![]() |
Visual Servoing Platform version 3.7.0
|
#include <vpDetectorDNNOpenCV.h>
Classes | |
| struct | DetectionCandidates |
| class | DetectedFeatures2D |
| struct | NetConfig |
Public Types | |
| enum | DNNResultsParsingType { USER_SPECIFIED = 0 , FASTER_RCNN = 1 , SSD_MOBILENET = 2 , RESNET_10 = 3 , YOLO_V3 = 4 , YOLO_V4 = 5 , YOLO_V5 = 6 , YOLO_V7 = 7 , YOLO_V8 = 8 , YOLO_V11 = 9 , YOLO_V12 = 10 , COUNT = 11 } |
| typedef enum vpDetectorDNNOpenCV::DNNResultsParsingType | DNNResultsParsingType |
| typedef struct vpDetectorDNNOpenCV::DetectionCandidates | DetectionCandidates |
| typedef class vpDetectorDNNOpenCV::DetectedFeatures2D | DetectedFeatures2D |
| typedef class vpDetectorDNNOpenCV::NetConfig | NetConfig |
Public Member Functions | |
| vpDetectorDNNOpenCV () | |
| vpDetectorDNNOpenCV (const NetConfig &config, const DNNResultsParsingType &typeParsingMethod, void(*parsingMethod)(DetectionCandidates &, std::vector< cv::Mat > &, const NetConfig &)=postProcess_unimplemented) | |
| vpDetectorDNNOpenCV (const std::string &jsonPath, void(*parsingMethod)(DetectionCandidates &, std::vector< cv::Mat > &, const NetConfig &)=postProcess_unimplemented) | |
| void | initFromJSON (const std::string &jsonPath) |
| void | saveConfigurationInJSON (const std::string &jsonPath) const |
| virtual | ~vpDetectorDNNOpenCV () |
| virtual bool | detect (const vpImage< unsigned char > &I, std::vector< DetectedFeatures2D > &output) |
| virtual bool | detect (const vpImage< unsigned char > &I, std::map< std::string, std::vector< DetectedFeatures2D > > &output) |
| virtual bool | detect (const vpImage< unsigned char > &I, std::vector< std::pair< std::string, std::vector< DetectedFeatures2D > > > &output) |
| virtual bool | detect (const vpImage< vpRGBa > &I, std::vector< DetectedFeatures2D > &output) |
| virtual bool | detect (const vpImage< vpRGBa > &I, std::map< std::string, std::vector< DetectedFeatures2D > > &output) |
| virtual bool | detect (const vpImage< vpRGBa > &I, std::vector< std::pair< std::string, std::vector< DetectedFeatures2D > > > &output) |
| virtual bool | detect (const cv::Mat &I, std::vector< DetectedFeatures2D > &output) |
| virtual bool | detect (const cv::Mat &I, std::map< std::string, std::vector< DetectedFeatures2D > > &output) |
| virtual bool | detect (const cv::Mat &I, std::vector< std::pair< std::string, std::vector< DetectedFeatures2D > > > &output) |
| void | readNet (const std::string &model, const std::string &config="", const std::string &framework="") |
| void | setNetConfig (const NetConfig &config) |
| void | setConfidenceThreshold (const float &confThreshold) |
| void | setNMSThreshold (const float &nmsThreshold) |
| void | setDetectionFilterSizeRatio (const double &sizeRatio) |
| void | setInputSize (const int &width, const int &height) |
| void | setMean (const double &meanR, const double &meanG, const double &meanB) |
| void | setPreferableBackend (const int &backendId) |
| void | setPreferableTarget (const int &targetId) |
| void | setScaleFactor (const double &scaleFactor) |
| void | setSwapRB (const bool &swapRB) |
| void | setParsingMethod (const DNNResultsParsingType &typeParsingMethod, void(*parsingMethod)(DetectionCandidates &, std::vector< cv::Mat > &, const NetConfig &)=postProcess_unimplemented) |
| const NetConfig & | getNetConfig () const |
Static Public Member Functions | |
| static std::string | getAvailableDnnResultsParsingTypes () |
| static std::string | dnnResultsParsingTypeToString (const DNNResultsParsingType &type) |
| static DNNResultsParsingType | dnnResultsParsingTypeFromString (const std::string &name) |
| static std::vector< std::string > | parseClassNamesFile (const std::string &filename) |
Protected Member Functions | |
| std::vector< cv::String > | getOutputsNames () |
| std::vector< DetectedFeatures2D > | filterDetectionSingleClassInput (const std::vector< DetectedFeatures2D > &detected_features, const double minRatioOfAreaOk) |
| std::vector< DetectedFeatures2D > | filterDetectionMultiClassInput (const std::vector< DetectedFeatures2D > &detected_features, const double minRatioOfAreaOk) |
| std::map< std::string, std::vector< vpDetectorDNNOpenCV::DetectedFeatures2D > > | filterDetectionMultiClassInput (const std::map< std::string, std::vector< vpDetectorDNNOpenCV::DetectedFeatures2D > > &detected_features, const double minRatioOfAreaOk) |
| void | postProcess (DetectionCandidates &proposals) |
| void | postProcess_YoloV3_V4 (DetectionCandidates &proposals, std::vector< cv::Mat > &dnnRes, const NetConfig &netConfig) |
| void | postProcess_YoloV5_V7 (DetectionCandidates &proposals, std::vector< cv::Mat > &dnnRes, const NetConfig &netConfig) |
| void | postProcess_YoloV8_V11_V12 (DetectionCandidates &proposals, std::vector< cv::Mat > &dnnRes, const NetConfig &netConfig) |
| void | postProcess_FasterRCNN (DetectionCandidates &proposals, std::vector< cv::Mat > &dnnRes, const NetConfig &netConfig) |
| void | postProcess_SSD_MobileNet (DetectionCandidates &proposals, std::vector< cv::Mat > &dnnRes, const NetConfig &netConfig) |
| void | postProcess_ResNet_10 (DetectionCandidates &proposals, std::vector< cv::Mat > &dnnRes, const NetConfig &netConfig) |
Static Protected Member Functions | |
| static void | postProcess_unimplemented (DetectionCandidates &proposals, std::vector< cv::Mat > &dnnRes, const NetConfig &netConfig) |
Protected Attributes | |
| bool | m_applySizeFilterAfterNMS |
| cv::Mat | m_blob |
| vpImage< vpRGBa > | m_I_color |
| cv::Mat | m_img |
| std::vector< int > | m_indices |
| cv::dnn::Net | m_net |
| NetConfig | m_netConfig |
| std::vector< cv::String > | m_outNames |
| std::vector< cv::Mat > | m_dnnRes |
| void(* | m_parsingMethod )(DetectionCandidates &, std::vector< cv::Mat > &, const NetConfig &) |
Friends | |
| void | from_json (const nlohmann::json &j, vpDetectorDNNOpenCV &network) |
| void | to_json (nlohmann::json &j, const vpDetectorDNNOpenCV &network) |
| std::ostream & | operator<< (std::ostream &os, const vpDetectorDNNOpenCV &network) |
This class is a wrapper over the OpenCV DNN module and specialized to handle object detection task.
This class supports the following networks dedicated to object detection:
This class can be initialized from a JSON file if ViSP has been compiled with NLOHMANN JSON (see JSON for modern C++ to see how to do it). Examples of such JSON files can be found in the tutorial folder.
Tutorials
If you want a detailed explanation on how to use this class, you may have a look at:
Definition at line 91 of file vpDetectorDNNOpenCV.h.
| typedef class vpDetectorDNNOpenCV::DetectedFeatures2D vpDetectorDNNOpenCV::DetectedFeatures2D |
| typedef struct vpDetectorDNNOpenCV::DetectionCandidates vpDetectorDNNOpenCV::DetectionCandidates |
| typedef class vpDetectorDNNOpenCV::NetConfig vpDetectorDNNOpenCV::NetConfig |
Enumeration listing the types of DNN for which the vpDetectorDNNOpenCV furnishes the methods permitting to parse the raw detection data into vpDetectorDNNOpenCV::DetectedFeatures2D .
| Enumerator | |
|---|---|
| USER_SPECIFIED | The user will give a pointer towards the parsing method to use to parse the raw data resulting from the detection step. |
| FASTER_RCNN | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a Faster-RCNN DNN. See vpDetectorDNNOpenCV::postProcess_FasterRCNN for more information. |
| SSD_MOBILENET | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a SSD MobileNet DNN. See vpDetectorDNNOpenCV::postProcess_SSD_MobileNet for more information. |
| RESNET_10 | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a ResNet 10 DNN. See vpDetectorDNNOpenCV::postProcess_ResNet_10 for more information. |
| YOLO_V3 | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a YoloV3 DNN. See vpDetectorDNNOpenCV::postProcess_YoloV3_V4 for more information. |
| YOLO_V4 | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a YoloV4 DNN. See vpDetectorDNNOpenCV::postProcess_YoloV3_V4 for more information. |
| YOLO_V5 | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a YoloV5 DNN. See vpDetectorDNNOpenCV::postProcess_YoloV5_V7 for more information. |
| YOLO_V7 | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a YoloV7 DNN. See vpDetectorDNNOpenCV::postProcess_YoloV5_V7 for more information. |
| YOLO_V8 | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a YoloV8 DNN. See vpDetectorDNNOpenCV::postProcess_YoloV8_V11_V12 for more information. |
| YOLO_V11 | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a YoloV11 DNN. See vpDetectorDNNOpenCV::postProcess_YoloV8_V11_V12 for more information. |
| YOLO_V12 | The vpDetectorDNNOpenCV object will use the parsing method corresponding to a YoloV12 DNN. See vpDetectorDNNOpenCV::postProcess_YoloV8_V11_V12 for more information. |
| COUNT | The number of parsing method that come along with the vpDetectorDNNOpenCV class. |
Definition at line 99 of file vpDetectorDNNOpenCV.h.
| vpDetectorDNNOpenCV::vpDetectorDNNOpenCV | ( | ) |
Definition at line 153 of file vpDetectorDNNOpenCV.cpp.
References m_applySizeFilterAfterNMS, m_blob, m_dnnRes, m_I_color, m_img, m_net, m_netConfig, m_outNames, m_parsingMethod, postProcess_unimplemented(), setDetectionFilterSizeRatio(), and vpDetectorDNNOpenCV().
Referenced by from_json, operator<<, to_json, and vpDetectorDNNOpenCV().
| vpDetectorDNNOpenCV::vpDetectorDNNOpenCV | ( | const NetConfig & | config, |
| const DNNResultsParsingType & | typeParsingMethod, | ||
| void(* | parsingMethod )(DetectionCandidates &, std::vector< cv::Mat > &, const NetConfig &) = postProcess_unimplemented ) |
Construct a new vpDetectorDNNOpenCV object and, if the model file has been given to the config object, read the net by calling vpDetectorDNNOpenCV::readNet.
| config | The network configuration. |
| typeParsingMethod | The type of parsing method that must be used to parse the raw results of the DNN detection step. |
| parsingMethod | If typeParsingMethod is set to vpDetectorDNNOpenCV::DNNResultsParsingType::USER_SPECIFIED, the parsing method that must be used to parse the raw results of the DNN detection step. |
Definition at line 168 of file vpDetectorDNNOpenCV.cpp.
References m_applySizeFilterAfterNMS, m_blob, m_dnnRes, m_I_color, m_img, m_net, m_netConfig, m_outNames, readNet(), setDetectionFilterSizeRatio(), and setParsingMethod().
| vpDetectorDNNOpenCV::vpDetectorDNNOpenCV | ( | const std::string & | jsonPath, |
| void(* | parsingMethod )(DetectionCandidates &, std::vector< cv::Mat > &, const NetConfig &) = postProcess_unimplemented ) |
Construct a new vpDetectorDNNOpenCV object from a JSON file and a potential parsing method.
| jsonPath | The JSON file permitting to initialize the detector. |
| parsingMethod | If the user chose to use a user-specified parsing method, the parsing method that must be used to parse the raw results of the DNN detection step. |
Definition at line 189 of file vpDetectorDNNOpenCV.cpp.
References initFromJSON(), m_applySizeFilterAfterNMS, m_blob, m_dnnRes, m_I_color, m_img, m_net, m_netConfig, m_outNames, setDetectionFilterSizeRatio(), and setParsingMethod().
|
virtual |
Destroy the vpDetectorDNNOpenCV object.
Definition at line 245 of file vpDetectorDNNOpenCV.cpp.
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : Map where the name of the class is used as key and whose value is a vector of detected 2D features that belong to the class. |
Definition at line 402 of file vpDetectorDNNOpenCV.cpp.
References filterDetectionMultiClassInput(), m_applySizeFilterAfterNMS, m_blob, vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_classIds, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, m_dnnRes, m_img, m_indices, m_net, m_netConfig, m_outNames, and postProcess().
Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : Vector of detections, whichever class they belong to. |
Definition at line 349 of file vpDetectorDNNOpenCV.cpp.
References filterDetectionMultiClassInput(), m_applySizeFilterAfterNMS, m_blob, vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_classIds, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, m_dnnRes, m_img, m_indices, m_net, m_netConfig, m_outNames, and postProcess().
Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : Vector of pairs <name_of_the_class, vector_of_detections>. |
Definition at line 458 of file vpDetectorDNNOpenCV.cpp.
References detect().
Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : Map where the name of the class is used as key and whose value is a vector of detected 2D features that belong to the class. |
Definition at line 273 of file vpDetectorDNNOpenCV.cpp.
References vpImageConvert::convert(), detect(), and m_I_color.
Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : Vector of detections, whichever class they belong to. |
Definition at line 256 of file vpDetectorDNNOpenCV.cpp.
References vpImageConvert::convert(), detect(), and m_I_color.
Referenced by detect(), detect(), detect(), detect(), detect(), detect(), detect(), and visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : Vector of pairs <name_of_the_class, vector_of_detections>. |
Definition at line 289 of file vpDetectorDNNOpenCV.cpp.
References vpImageConvert::convert(), detect(), and m_I_color.
Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : Map where the name of the class is used as key and whose value is a vector of detected 2D features that belong to the class. |
Definition at line 321 of file vpDetectorDNNOpenCV.cpp.
References vpImageConvert::convert(), detect(), and m_img.
Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : Vector of detections, whichever class they belong to. |
Definition at line 305 of file vpDetectorDNNOpenCV.cpp.
References vpImageConvert::convert(), detect(), and m_img.
Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
virtual |
Object detection using OpenCV DNN module.
| [in] | I | : Input image. |
| [out] | output | : vector of pairs <name_of_the_class, vector_of_detections> |
Definition at line 335 of file vpDetectorDNNOpenCV.cpp.
References vpImageConvert::convert(), detect(), and m_img.
Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().
|
static |
Cast a name of class of parsing method into a vpDetectorDNNOpenCV::DNNResultsParsingType. The naming convention is the following:
| [in] | name | : the name of the type of parsing method to apply. |
Definition at line 123 of file vpDetectorDNNOpenCV.cpp.
References COUNT, dnnResultsParsingTypeToString(), and vpIoTools::toLowerCase().
Referenced by vpDetectorDNNOpenCV::NetConfig::from_json.
|
static |
Cast a vpDetectorDNNOpenCV::DNNResultsParsingType into its name, in std::string format. The naming convention is the following:
| [in] | type | : The type of parsing method to apply to interpret the DNN inference raw results. |
Definition at line 71 of file vpDetectorDNNOpenCV.cpp.
References COUNT, FASTER_RCNN, RESNET_10, SSD_MOBILENET, USER_SPECIFIED, YOLO_V11, YOLO_V12, YOLO_V3, YOLO_V4, YOLO_V5, YOLO_V7, and YOLO_V8.
Referenced by dnnResultsParsingTypeFromString(), vpDetectorDNNOpenCV::NetConfig::from_json, getAvailableDnnResultsParsingTypes(), setParsingMethod(), vpDetectorDNNOpenCV::NetConfig::to_json, and vpDetectorDNNOpenCV::NetConfig::toString().
|
protected |
Return a new map <class, vector_corresponding_detections> where the area of each detection belonging to one class is in the range [average_area(class) x minRatioOfAreaOk ; average_area(class) / minRatioOfAreaOk ] .
| detected_features | The original detected features, that can contains several classes. |
| minRatioOfAreaOk | The minimum ratio of area a feature bounding box must reach to be kept in the resulting list of features. Value between 0 and 1.0. |
Definition at line 678 of file vpDetectorDNNOpenCV.cpp.
References filterDetectionSingleClassInput().
|
protected |
Return a new vector, ordered by vpDetectorDNNOpenCV::DetectedFeatures2D::m_cls , where the area of each detection belonging to one class is in the range [average_area(class) x minRatioOfAreaOk ; average_area(class) / minRatioOfAreaOk ] .
| [in] | detected_features | : The original list of detected features, that can contains several classes. |
| [in] | minRatioOfAreaOk | : The minimum ratio of area a feature bounding box must reach to be kept in the resulting list of features. Value between 0 and 1.0. |
Definition at line 586 of file vpDetectorDNNOpenCV.cpp.
References vpException::badValue, vpRect::getArea(), vpDetectorDNNOpenCV::DetectedFeatures2D::getBoundingBox(), and vpDetectorDNNOpenCV::DetectedFeatures2D::getClassId().
|
protected |
Return a new vector of detected features whose area is greater or equal to the average area x minRatioOfAreaOk. This method assumes that detected_features contains detections of a single class.
| [in] | detected_features | : The original list of detected features, belonging to the same class. |
| [in] | minRatioOfAreaOk | : The minimum ratio of area a feature bounding box must reach to be kept in the resulting list of features. Value between 0 and 1.0. |
Definition at line 550 of file vpDetectorDNNOpenCV.cpp.
Referenced by filterDetectionMultiClassInput().
|
static |
Get the list of the parsing methods / types of DNNs supported by the vpDetectorDNNOpenCV class.
Definition at line 52 of file vpDetectorDNNOpenCV.cpp.
References COUNT, and dnnResultsParsingTypeToString().
|
inline |
Definition at line 516 of file vpDetectorDNNOpenCV.h.
References m_netConfig.
|
protected |
Get the names of the output layers of the DNN.
Definition at line 474 of file vpDetectorDNNOpenCV.cpp.
References m_net.
Referenced by readNet().
| void vpDetectorDNNOpenCV::initFromJSON | ( | const std::string & | jsonPath | ) |
Initialize detector from a json config file.
| [in] | jsonPath | : Json config file path. |
Definition at line 203 of file vpDetectorDNNOpenCV.cpp.
References vpException::ioError, m_netConfig, and readNet().
Referenced by vpDetectorDNNOpenCV().
|
static |
Parse the designated file that contains the list of the classes the network can detect. The class names must either be indicated in an array of string in YAML format, or one name by row (without quotes) as described in NetConfig::parseClassNamesFile().
| filename | The path towards the file. |
Definition at line 148 of file vpDetectorDNNOpenCV.cpp.
|
protected |
Post-process the raw results of the DNN. Call the post-process method corresponding to the vpDetectorDNNOpenCV::DNNResultsParsingType that will extract the data stored as a matrix. Then, perform Non-Maximum Suppression to remove overlapping detections.
| [in,out] | proposals | : Input/output that will contains all the detection candidates. |
Definition at line 496 of file vpDetectorDNNOpenCV.cpp.
References vpException::badValue, FASTER_RCNN, vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, m_dnnRes, m_indices, m_netConfig, m_parsingMethod, postProcess_FasterRCNN(), postProcess_ResNet_10(), postProcess_SSD_MobileNet(), postProcess_YoloV3_V4(), postProcess_YoloV5_V7(), postProcess_YoloV8_V11_V12(), RESNET_10, SSD_MOBILENET, USER_SPECIFIED, YOLO_V11, YOLO_V12, YOLO_V3, YOLO_V4, YOLO_V5, YOLO_V7, and YOLO_V8.
|
protected |
Post-process the raw results of a Faster-RCNN-type DNN. Extract the data stored as a matrix. The network produces output blob with a shape 1x1xNx7 where N is a number of detections and an every detection is a vector of values [batchId, classId, confidence, left, top, right, bottom]
| proposals | : input/output that will contains all the detection candidates. |
| dnnRes | : raw results of the vpDetectorDNNOpenCV::detect step. |
| netConfig | : the configuration of the network, to know for instance the DNN input size. |
Definition at line 891 of file vpDetectorDNNOpenCV.cpp.
References vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_classIds, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, and m_img.
Referenced by postProcess().
|
protected |
Post-process the raw results of a ResNet-10-type DNN. Extract the data stored as a matrix. The network produces output blob with a shape 1x1xNx7 where N is a number of detections and an every detection is a vector of values [batchId, classId, confidence, left, top, right, bottom]
| proposals | : input/output that will contains all the detection candidates. |
| dnnRes | : raw results of the vpDetectorDNNOpenCV::detect step. |
| netConfig | : the configuration of the network, to know for instance the DNN input size. |
Definition at line 994 of file vpDetectorDNNOpenCV.cpp.
References vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_classIds, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, and m_img.
Referenced by postProcess().
|
protected |
Post-process the raw results of a SSD-MobileNet-type DNN. Extract the data stored as a matrix. The network produces 2 outputs blob:
| proposals | : input/output that will contains all the detection candidates. |
| dnnRes | : raw results of the vpDetectorDNNOpenCV::detect step. |
| netConfig | : the configuration of the network, to know for instance the DNN input size. |
Definition at line 933 of file vpDetectorDNNOpenCV.cpp.
References vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_classIds, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, m_img, and m_outNames.
Referenced by postProcess().
|
staticprotected |
Method throwing a vpException::functionNotImplementedError . It is called if the user set the vpDetectorDNNOpenCV::NetConfig::m_parsingMethodType to USER_DEFINED but didn't set the parsing method.
| proposals | : input/output that will contains all the detection candidates. |
| dnnRes | : raw results of the vpDetectorDNNOpenCV::detect step. |
| netConfig | : the configuration of the network, to know for instance the DNN input size. |
Definition at line 1027 of file vpDetectorDNNOpenCV.cpp.
References vpException::functionNotImplementedError.
Referenced by vpDetectorDNNOpenCV().
|
protected |
Post-process the raw results of a Yolov3-type or YoloV4-type DNN. Extract the data stored as a matrix. They are stored as follow: [batchsize][1:nb_proposals][1:5+nb_classes] Where a detection proposal consists of: [center_x; center_y; width; height; objectness; score_class_0; ...; score_last_class] where center_x € [0; 1] and center_y € [0; 1] which correspond to the ratio of the position of the center of the bbox with regard to the total width/height of the image.
| proposals | : input/output that will contains all the detection candidates. |
| dnnRes | : raw results of the vpDetectorDNNOpenCV::detect step. |
| netConfig | : the configuration of the network, to know for instance the DNN input size. |
cx,cy,w,h,box_score,class_score
cx
cy
w
h
Definition at line 700 of file vpDetectorDNNOpenCV.cpp.
References vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_classIds, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, and m_img.
Referenced by postProcess().
|
protected |
Post-process the raw results of a YoloV5-type or a YoloV7-type DNN. Extract the data stored as a matrix. They are stored as follow: [batchsize][1:num_proposals][1:5+nb_classes] Where a detection proposal consists of: [center_x; center_y; width; height; objectness; score_class_0; ...; score_last_class]
| proposals | : input/output that will contains all the detection candidates. |
| dnnRes | : raw results of the vpDetectorDNNOpenCV::detect step. |
| netConfig | : the configuration of the network, to know for instance the DNN input size. |
cx,cy,w,h,box_score,class_score
cx
cy
w
h
Definition at line 763 of file vpDetectorDNNOpenCV.cpp.
References vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_classIds, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, and m_img.
Referenced by postProcess().
|
protected |
Post-process the raw results of a YoloV8-type DNN. Extract the data stored as a matrix. They are stored as follow: [batchsize][1:5+nb_classes][1:8400] Where 8400 is the number of detection proposals and a detection proposal consists of: [center_x; center_y; width; height; score_class_0; ...; score_last_class]^T
| proposals | : input/output that will contains all the detection candidates. |
| dnnRes | : raw results of the vpDetectorDNNOpenCV::detect step. |
| netConfig | : the configuration of the network, to know for instance the DNN input size. |
cx,cy,w,h,box_score,class_score
cx
cy
w
h
Definition at line 828 of file vpDetectorDNNOpenCV.cpp.
References vpDetectorDNNOpenCV::DetectionCandidates::m_boxes, vpDetectorDNNOpenCV::DetectionCandidates::m_classIds, vpDetectorDNNOpenCV::DetectionCandidates::m_confidences, and m_img.
Referenced by postProcess().
| void vpDetectorDNNOpenCV::readNet | ( | const std::string & | model, |
| const std::string & | config = "", | ||
| const std::string & | framework = "" ) |
Read a network, see OpenCV readNet documentation for more information.
| model | Path to a binary file of model containing trained weights. The following file extensions are expected for models from different frameworks:
|
| config | Path to a text file of model containing network configuration. It could be a file with the following extensions:
|
| framework | Optional name of an origin framework of the model. Automatically detected if it is not set. |
Definition at line 1054 of file vpDetectorDNNOpenCV.cpp.
References getOutputsNames(), m_net, m_netConfig, and m_outNames.
Referenced by initFromJSON(), setNetConfig(), and vpDetectorDNNOpenCV().
| void vpDetectorDNNOpenCV::saveConfigurationInJSON | ( | const std::string & | jsonPath | ) | const |
Save the network configuration in a JSON file.
| jsonPath | Path towards the output JSON file . |
Definition at line 233 of file vpDetectorDNNOpenCV.cpp.
| void vpDetectorDNNOpenCV::setConfidenceThreshold | ( | const float & | confThreshold | ) |
Set confidence threshold to filter the detections.
| confThreshold | Confidence threshold between [0, 1] |
Definition at line 1088 of file vpDetectorDNNOpenCV.cpp.
References m_netConfig.
| void vpDetectorDNNOpenCV::setDetectionFilterSizeRatio | ( | const double & | sizeRatio | ) |
Set the size ratio used in the filterDetection method. If <= 0., filterDetection is not used. The detections of class c for which the bbox area does not belong to [mean_class_c(Area) * sizeRatio ; mean_class_c(Area) / sizeRatio ] are removed from the list of detections.
| sizeRatio | the size ratio used in the filterDetection method. If <= 0., filterDetection is not used. |
Definition at line 1105 of file vpDetectorDNNOpenCV.cpp.
References m_applySizeFilterAfterNMS, and m_netConfig.
Referenced by setNetConfig(), vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
| void vpDetectorDNNOpenCV::setInputSize | ( | const int & | width, |
| const int & | height ) |
Set dimension to resize the image to the input blob.
| width | If <= 0, blob width is set to image width |
| height | If <= 0, blob height is set to image height |
Definition at line 1122 of file vpDetectorDNNOpenCV.cpp.
References m_netConfig.
| void vpDetectorDNNOpenCV::setMean | ( | const double & | meanR, |
| const double & | meanG, | ||
| const double & | meanB ) |
Set mean subtraction values.
| meanR | Mean value for R-channel |
| meanG | Mean value for G-channel |
| meanB | Mean value for R-channel |
Definition at line 1135 of file vpDetectorDNNOpenCV.cpp.
References m_netConfig.
| void vpDetectorDNNOpenCV::setNetConfig | ( | const NetConfig & | config | ) |
Configure the DNN (thresholds, input size, ...). If the DNN weights file is known, initialize the m_net by reading the weights.
| config | : The desired configuration of the network. |
Definition at line 1073 of file vpDetectorDNNOpenCV.cpp.
References m_netConfig, readNet(), setDetectionFilterSizeRatio(), and setParsingMethod().
| void vpDetectorDNNOpenCV::setNMSThreshold | ( | const float & | nmsThreshold | ) |
Set Non-Maximum Suppression threshold, used to filter multiple detections at approximatively the same location.
| nmsThreshold | Non-Maximum Suppression threshold between [0, 1] |
Definition at line 1096 of file vpDetectorDNNOpenCV.cpp.
References m_netConfig.
| void vpDetectorDNNOpenCV::setParsingMethod | ( | const DNNResultsParsingType & | typeParsingMethod, |
| void(* | parsingMethod )(DetectionCandidates &, std::vector< cv::Mat > &, const NetConfig &) = postProcess_unimplemented ) |
Set the type of parsing method that must be used to interpret the raw results of the DNN detection.
| typeParsingMethod | : The type of parsing method that must be used to interpret the raw results of the DNN detection. |
| parsingMethod | : If typeParsingMethod is equal to vpDetectorDNNOpenCV::USER_DEFINED , a function permitting to interpret the cv::Mat resulting from the DNN inference. |
Definition at line 1178 of file vpDetectorDNNOpenCV.cpp.
References dnnResultsParsingTypeToString(), m_netConfig, m_parsingMethod, SSD_MOBILENET, YOLO_V11, YOLO_V12, YOLO_V7, and YOLO_V8.
Referenced by setNetConfig(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
| void vpDetectorDNNOpenCV::setPreferableBackend | ( | const int & | backendId | ) |
Set preferable backend for inference computation. See OpenCV setPreferableBackend documentation for more information.
| backendId | Backend identifier |
Definition at line 1143 of file vpDetectorDNNOpenCV.cpp.
References m_net.
| void vpDetectorDNNOpenCV::setPreferableTarget | ( | const int & | targetId | ) |
Set preferable target for inference computation. See OpenCV setPreferableTarget documentation for more information.
| targetId | Target identifier |
Definition at line 1151 of file vpDetectorDNNOpenCV.cpp.
References m_net.
| void vpDetectorDNNOpenCV::setScaleFactor | ( | const double & | scaleFactor | ) |
Set scale factor to normalize the range of pixel values.
Definition at line 1156 of file vpDetectorDNNOpenCV.cpp.
References m_netConfig, YOLO_V11, YOLO_V12, YOLO_V7, and YOLO_V8.
| void vpDetectorDNNOpenCV::setSwapRB | ( | const bool & | swapRB | ) |
If true, swap R and B channel for mean subtraction. For instance when the network has been trained on RGB image format (OpenCV uses BGR convention).
Definition at line 1169 of file vpDetectorDNNOpenCV.cpp.
References m_netConfig.
|
friend |
Read the network configuration from JSON. All values are optional and if an argument is not present, the default value defined in the constructor is kept.
| j | The JSON object, resulting from the parsing of a JSON file. |
| network | The network, that will be initialized from the JSON data. |
Definition at line 529 of file vpDetectorDNNOpenCV.h.
References m_netConfig, and vpDetectorDNNOpenCV().
|
friend |
Definition at line 548 of file vpDetectorDNNOpenCV.h.
References m_netConfig, and vpDetectorDNNOpenCV().
|
friend |
Parse the network configuration into JSON format.
| j | The JSON parser. |
| network | The network we want to parse the configuration. |
Definition at line 540 of file vpDetectorDNNOpenCV.h.
References m_netConfig, and vpDetectorDNNOpenCV().
|
protected |
If true, filter the detections removing the ones for which the bbox does not respect area(bbox) € [mean_class(area) * ratio; mean_class(area) / ratio].
Definition at line 586 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), setDetectionFilterSizeRatio(), vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
|
protected |
Buffer for the blob in input net.
Definition at line 588 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
|
protected |
Contains all output blobs for each layer specified in m_outNames.
Definition at line 602 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), postProcess(), vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
Buffer for gray to RGBa image conversion.
Definition at line 590 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), detect(), vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
|
protected |
Buffer for the input image.
Definition at line 592 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), detect(), detect(), detect(), postProcess_FasterRCNN(), postProcess_ResNet_10(), postProcess_SSD_MobileNet(), postProcess_YoloV3_V4(), postProcess_YoloV5_V7(), postProcess_YoloV8_V11_V12(), vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
|
protected |
Indices for NMS.
Definition at line 594 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), and postProcess().
|
protected |
DNN network.
Definition at line 596 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), getOutputsNames(), readNet(), setPreferableBackend(), setPreferableTarget(), vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
|
protected |
Configuration of the DNN.
Definition at line 598 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), from_json, getNetConfig(), initFromJSON(), operator<<, postProcess(), readNet(), setConfidenceThreshold(), setDetectionFilterSizeRatio(), setInputSize(), setMean(), setNetConfig(), setNMSThreshold(), setParsingMethod(), setScaleFactor(), setSwapRB(), to_json, vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
|
protected |
Names of layers with unconnected outputs.
Definition at line 600 of file vpDetectorDNNOpenCV.h.
Referenced by detect(), detect(), postProcess_SSD_MobileNet(), readNet(), vpDetectorDNNOpenCV(), vpDetectorDNNOpenCV(), and vpDetectorDNNOpenCV().
|
protected |
Pointer towards the parsing method, used if m_parsingMethodType is equal to m_parsingMethodType::USER_SPECIFIED.
Definition at line 604 of file vpDetectorDNNOpenCV.h.
Referenced by postProcess(), setParsingMethod(), and vpDetectorDNNOpenCV().