#ifndef __UTIL__ #define __UTIL__ #include #include #include #include #include #include // Get Output Layers Name std::vector getOutputsNames( const cv::dnn::Net& net ) { static std::vector names; if( names.empty() ){ std::vector out_layers = net.getUnconnectedOutLayers(); std::vector layers_names = net.getLayerNames(); names.resize( out_layers.size() ); for( size_t i = 0; i < out_layers.size(); ++i ){ names[i] = layers_names[out_layers[i] - 1]; } } return names; } // Get Output Layer Type std::string getOutputLayerType( cv::dnn::Net& net ) { const std::vector out_layers = net.getUnconnectedOutLayers(); const std::string output_layer_type = net.getLayer( out_layers[0] )->type; return output_layer_type; } // Read Class Name List std::vector readClassNameList( const std::string list_path ) { std::vector classes; std::ifstream ifs( list_path ); if( !ifs.is_open() ){ return classes; } std::string class_name = ""; while( std::getline( ifs, class_name ) ){ classes.push_back( class_name ); } return classes; } // Get Class Color Table for Visualize std::vector getClassColors( const int32_t number_of_colors ) { cv::RNG random; std::vector colors; for( int32_t i = 0; i < number_of_colors; i++ ){ cv::Scalar color( random.uniform( 0, 255 ), random.uniform( 0, 255 ), random.uniform( 0, 255 ) ); colors.push_back( color ); } return colors; } #endif // __UTIL__