DetectorDNNOpenCV¶
- class DetectorDNNOpenCV(self)¶
Bases:
pybind11_object
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:
Faster-RCNN, see usage to detect objects belonging to the COCO dataset using dnn_supported_faster_rcnn network
SSD MobileNet, see usage to detect objects belonging to the COCO dataset using dnn_supported_mobilenet_ssd network
ResNet 10, see usage for dnn_usecase_face_detection
Yolo v3, see usage to detect objects belonging to the COCO dataset using dnn_supported_yolov3 network
Yolo v4, see usage to detect objects belonging to the COCO dataset using dnn_supported_yolov4 network
Yolo v5, see usage to detect objects belonging to the COCO dataset using dnn_supported_yolov5 network
Yolo v7, see usage to detect objects belonging to the COCO dataset using dnn_supported_yolov7 network
Yolo v8, see usage to detect objects belonging to the COCO dataset using dnn_supported_yolov8 network
This class can be initialized from a JSON file if ViSP has been compiled with NLOHMANN JSON (see soft_tool_json to see how to do it). Examples of such JSON files can be found in the tutorial folder.
Note
See tutorial-detection-dnn
Methods
Overloaded function.
Cast a name of class of parsing method into a ** vpDetectorDNNOpenCV::DNNResultsParsingType ** .
Get the list of the parsing methods / types of DNNs supported by the ** vpDetectorDNNOpenCV ** class.
- param jsonPath:
Parse the designated file that contains the list of the classes the network can detect.
Read a network, see OpenCV readNet documentation for more information.
Save the network configuration in a JSON file.
Set confidence threshold to filter the detections.
Set the size ratio used in the filterDetection method.
Set dimension to resize the image to the input blob.
Set mean subtraction values.
Set Non-Maximum Suppression threshold, used to filter multiple detections at approximatively the same location.
Set preferable backend for inference computation.
Set preferable target for inference computation.
Set scale factor to normalize the range of pixel values.
If true, swap R and B channel for mean subtraction.
Inherited Methods
Operators
__doc__
__module__
__repr__
Attributes
COUNT
FASTER_RCNN
RESNET_10
SSD_MOBILENET
USER_SPECIFIED
YOLO_V11
YOLO_V3
YOLO_V4
YOLO_V5
YOLO_V7
YOLO_V8
__annotations__
- class DNNResultsParsingType(self, value: int)¶
Bases:
pybind11_object
Enumeration listing the types of DNN for which the ** vpDetectorDNNOpenCV ** furnishes the methods permitting to parse the raw detection data into ** vpDetectorDNNOpenCV::DetectedFeatures2D ** .
Values:
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 ** for more information.
COUNT: The number of parsing method that come along with the ** vpDetectorDNNOpenCV ** class.
- __init__(self)¶
- detect(*args, **kwargs)¶
Overloaded function.
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: visp._visp.core.ImageGray, output: list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]) -> tuple[bool, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]
Object detection using OpenCV DNN module.
- Parameters:
- I
Input image.
- output
Vector of detections, whichever class they belong to.
- Returns:
A tuple containing:
false if there is no detection, true otherwise.
output: Vector of detections, whichever class they belong to.
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: visp._visp.core.ImageGray, output: dict[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]) -> bool
- Parameters:
- I
Input image.
- 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.
- Returns:
false if there is no detection.
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: visp._visp.core.ImageGray, output: list[tuple[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]]) -> tuple[bool, list[tuple[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]]]
- Parameters:
- I
Input image.
- output
vector of pairs <name_of_the_class, vector_of_detections>
- Returns:
A tuple containing:
false if there is no detection.
output: vector of pairs <name_of_the_class, vector_of_detections>
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: visp._visp.core.ImageRGBa, output: list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]) -> tuple[bool, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]
Object detection using OpenCV DNN module.
- Parameters:
- I
Input image.
- output
Vector of detections, whichever class they belong to.
- Returns:
A tuple containing:
false if there is no detection, true otherwise.
output: Vector of detections, whichever class they belong to.
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: visp._visp.core.ImageRGBa, output: dict[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]) -> bool
Object detection using OpenCV DNN module.
- Parameters:
- I
Input image.
- 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.
- Returns:
false if there is no detection.
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: visp._visp.core.ImageRGBa, output: list[tuple[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]]) -> tuple[bool, list[tuple[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]]]
Object detection using OpenCV DNN module.
- Parameters:
- I
Input image.
- output
vector of pairs <name_of_the_class, vector_of_detections>
- Returns:
A tuple containing:
false if there is no detection, true otherwise.
output: vector of pairs <name_of_the_class, vector_of_detections>
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: cv::Mat, output: list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]) -> tuple[bool, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]
Object detection using OpenCV DNN module.
- Parameters:
- I
Input image.
- output
Vector of detections, whichever class they belong to.
- Returns:
A tuple containing:
false if there is no detection.
output: Vector of detections, whichever class they belong to.
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: cv::Mat, output: dict[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]) -> bool
Object detection using OpenCV DNN module.
- Parameters:
- I
Input image.
- 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.
- Returns:
false if there is no detection.
detect(self: visp._visp.detection.DetectorDNNOpenCV, I: cv::Mat, output: list[tuple[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]]) -> tuple[bool, list[tuple[str, list[visp._visp.detection.DetectorDNNOpenCV.DetectedFeatures2D]]]]
Object detection using OpenCV DNN module.
- Parameters:
- I
Input image.
- output
vector of pairs <name_of_the_class, vector_of_detections>
- Returns:
A tuple containing:
false if there is no detection.
output: vector of pairs <name_of_the_class, vector_of_detections>
- static dnnResultsParsingTypeFromString(name: str) visp._visp.detection.DetectorDNNOpenCV.DNNResultsParsingType ¶
Cast a name of class of parsing method into a ** vpDetectorDNNOpenCV::DNNResultsParsingType ** . The naming convention is the following:
only lowercases
- static dnnResultsParsingTypeToString(type: visp._visp.detection.DetectorDNNOpenCV.DNNResultsParsingType) str ¶
- static getAvailableDnnResultsParsingTypes() str ¶
Get the list of the parsing methods / types of DNNs supported by the ** vpDetectorDNNOpenCV ** class.
- Returns:
std::string The list of the supported parsing methods / types of DNNs.
- getNetConfig(self) visp._visp.detection.DetectorDNNOpenCV.NetConfig ¶
- static parseClassNamesFile(filename: str) list[str] ¶
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() .
Note
See NetConfig::parseClassNamesFile() .
- readNet(self: visp._visp.detection.DetectorDNNOpenCV, model: str, config: str =, framework: str =) None ¶
Read a network, see OpenCV readNet documentation for more information.
- Parameters:
- model
Path to a binary file of model containing trained weights. The following file extensions are expected for models from different frameworks:
*.caffemodel (Caffe, http://caffe.berkeleyvision.org/ )
*.pb (TensorFlow, https://www.tensorflow.org/ )
*.t7 | *.net (Torch, http://torch.ch/ )
*.weights (Darknet, https://pjreddie.com/darknet/ )
*.bin (DLDT, https://software.intel.com/openvino-toolkit )
*.onnx (ONNX, https://onnx.ai/ )
- config
Path to a text file of model containing network configuration. It could be a file with the following extensions:
*.prototxt (Caffe, http://caffe.berkeleyvision.org/ )
*.pbtxt (TensorFlow, https://www.tensorflow.org/ )
*.cfg (Darknet, https://pjreddie.com/darknet/ )
*.xml (DLDT, https://software.intel.com/openvino-toolkit )
- framework
Optional name of an origin framework of the model. Automatically detected if it is not set.
- setConfidenceThreshold(self, confThreshold: float) None ¶
Set confidence threshold to filter the detections.
- setDetectionFilterSizeRatio(self, sizeRatio: float) None ¶
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.
- setInputSize(self, width: int, height: int) None ¶
Set dimension to resize the image to the input blob.
- setNMSThreshold(self, nmsThreshold: float) None ¶
Set Non-Maximum Suppression threshold, used to filter multiple detections at approximatively the same location.
- setPreferableBackend(self, backendId: int) None ¶
Set preferable backend for inference computation. See OpenCV setPreferableBackend documentation for more information.
- setPreferableTarget(self, targetId: int) None ¶
Set preferable target for inference computation. See OpenCV setPreferableTarget documentation for more information.