Visual Servoing Platform  version 3.5.1 under development (2023-05-12)

#include <visp3/detection/vpDetectorDNN.h>

+ Inheritance diagram for vpDetectorDNN:

Public Member Functions

 vpDetectorDNN ()
 
virtual ~vpDetectorDNN ()
 
virtual bool detect (const vpImage< unsigned char > &I)
 
virtual bool detect (const vpImage< vpRGBa > &I, std::vector< vpRect > &boundingBoxes)
 
std::vector< vpRectgetDetectionBBs (bool afterNMS=true) const
 
std::vector< int > getDetectionClassIds (bool afterNMS=true) const
 
std::vector< float > getDetectionConfidence (bool afterNMS=true) const
 
void readNet (const std::string &model, const std::string &config="", const std::string &framework="")
 
void setConfidenceThreshold (float confThreshold)
 
void setInputSize (int width, int height)
 
void setMean (double meanR, double meanG, double meanB)
 
void setNMSThreshold (float nmsThreshold)
 
void setPreferableBackend (int backendId)
 
void setPreferableTarget (int targetId)
 
void setScaleFactor (double scaleFactor)
 
void setSwapRB (bool swapRB)
 
Inherited functionalities from vpDetectorBase
vpRect getBBox (size_t i) const
 
vpImagePoint getCog (size_t i) const
 
std::vector< std::string > & getMessage ()
 
std::string & getMessage (size_t i)
 
size_t getNbObjects () const
 
std::vector< std::vector< vpImagePoint > > & getPolygon ()
 
std::vector< vpImagePoint > & getPolygon (size_t i)
 
void setTimeout (unsigned long timeout_ms)
 

Protected Attributes

std::vector< std::vector< vpImagePoint > > m_polygon
 
std::vector< std::string > m_message
 
size_t m_nb_objects
 
unsigned long m_timeout_ms
 

Detailed Description

This class is a wrapper over the OpenCV DNN module and specialized to handle object detection task.

Example is provided in tutorial-dnn-object-detection-live.cpp

Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 52 of file vpDetectorDNN.h.

Constructor & Destructor Documentation

◆ vpDetectorDNN()

vpDetectorDNN::vpDetectorDNN ( )

Definition at line 41 of file vpDetectorDNN.cpp.

◆ ~vpDetectorDNN()

vpDetectorDNN::~vpDetectorDNN ( )
virtual

Definition at line 48 of file vpDetectorDNN.cpp.

Member Function Documentation

◆ detect() [1/2]

bool vpDetectorDNN::detect ( const vpImage< unsigned char > &  I)
virtual

Object detection using OpenCV DNN module.

Warning
Classical object detection network uses as input 3-channels. Grayscale image is converted to color image.
Parameters
I: Input image.
Returns
false if there is no detection.

Implements vpDetectorBase.

Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 58 of file vpDetectorDNN.cpp.

References vpImageConvert::convert().

◆ detect() [2/2]

bool vpDetectorDNN::detect ( const vpImage< vpRGBa > &  I,
std::vector< vpRect > &  boundingBoxes 
)
virtual

Object detection using OpenCV DNN module.

Parameters
I: Input image.
boundingBoxes: Vector of detection bounding boxes.
Returns
false if there is no detection.

Definition at line 73 of file vpDetectorDNN.cpp.

References vpImageConvert::convert(), vpDetectorBase::m_message, vpDetectorBase::m_nb_objects, and vpDetectorBase::m_polygon.

◆ getBBox()

vpRect vpDetectorBase::getBBox ( size_t  i) const
inherited

◆ getCog()

vpImagePoint vpDetectorBase::getCog ( size_t  i) const
inherited

Return the center of gravity location of the ith object.

Examples
mbot-apriltag-2D-half-vs.cpp, mbot-apriltag-ibvs.cpp, and tutorial-flir-ptu-ibvs.cpp.

Definition at line 79 of file vpDetectorBase.cpp.

References vpDetectorBase::m_polygon.

◆ getDetectionBBs()

std::vector< vpRect > vpDetectorDNN::getDetectionBBs ( bool  afterNMS = true) const

Get raw detection bounding boxes.

Parameters
afterNMSIf true, return detection bounding boxes after NMS

Definition at line 123 of file vpDetectorDNN.cpp.

◆ getDetectionClassIds()

std::vector< int > vpDetectorDNN::getDetectionClassIds ( bool  afterNMS = true) const

Get detection class ids.

Parameters
afterNMSIf true, returns class ids after NMS
Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 148 of file vpDetectorDNN.cpp.

◆ getDetectionConfidence()

std::vector< float > vpDetectorDNN::getDetectionConfidence ( bool  afterNMS = true) const

Get detection confidences.

Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 165 of file vpDetectorDNN.cpp.

◆ getMessage() [1/2]

std::vector<std::string>& vpDetectorBase::getMessage ( )
inlineinherited

Returns the contained message of the ith object if there is one.

Examples
testAprilTag.cpp, tutorial-apriltag-detector.cpp, tutorial-barcode-detector-live.cpp, and tutorial-barcode-detector.cpp.

Definition at line 106 of file vpDetectorBase.h.

◆ getMessage() [2/2]

std::string & vpDetectorBase::getMessage ( size_t  i)
inherited

Returns the contained message of the ith object if there is one.

Definition at line 67 of file vpDetectorBase.cpp.

References vpException::badValue, vpDetectorBase::m_message, and vpDetectorBase::m_polygon.

◆ getNbObjects()

◆ getPolygon() [1/2]

◆ getPolygon() [2/2]

std::vector< vpImagePoint > & vpDetectorBase::getPolygon ( size_t  i)
inherited

Returns ith object container box as a vector of points.

Definition at line 55 of file vpDetectorBase.cpp.

References vpException::badValue, and vpDetectorBase::m_polygon.

◆ readNet()

void vpDetectorDNN::readNet ( const std::string &  model,
const std::string &  config = "",
const std::string &  framework = "" 
)

Read a network, see OpenCV readNet documentation for more information.

Parameters
modelPath to a binary file of model containing trained weights. The following file extensions are expected for models from different frameworks:
configPath to a text file of model containing network configuration. It could be a file with the following extensions:
frameworkOptional name of an origin framework of the model. Automatically detected if it is not set.
Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 347 of file vpDetectorDNN.cpp.

◆ setConfidenceThreshold()

void vpDetectorDNN::setConfidenceThreshold ( float  confThreshold)

Set confidence threshold to filter the detections.

Parameters
confThresholdConfidence threshold between [0, 1]
Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 362 of file vpDetectorDNN.cpp.

◆ setInputSize()

void vpDetectorDNN::setInputSize ( int  width,
int  height 
)

Set dimension to resize the image to the input blob.

Parameters
widthIf <= 0, blob width is set to image width
heightIf <= 0, blob height is set to image height
Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 370 of file vpDetectorDNN.cpp.

◆ setMean()

void vpDetectorDNN::setMean ( double  meanR,
double  meanG,
double  meanB 
)

Set mean subtraction values.

Parameters
meanRMean value for R-channel
meanGMean value for G-channel
meanBMean value for R-channel
Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 383 of file vpDetectorDNN.cpp.

◆ setNMSThreshold()

void vpDetectorDNN::setNMSThreshold ( float  nmsThreshold)

Set Non-Maximum Suppression threshold, used to filter multiple detections at approximatively the same location.

Parameters
nmsThresholdNon-Maximum Suppression threshold between [0, 1]
Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 391 of file vpDetectorDNN.cpp.

◆ setPreferableBackend()

void vpDetectorDNN::setPreferableBackend ( int  backendId)

Set preferable backend for inference computation. See OpenCV setPreferableBackend documentation for more information.

Parameters
backendIdBackend identifier

Definition at line 399 of file vpDetectorDNN.cpp.

◆ setPreferableTarget()

void vpDetectorDNN::setPreferableTarget ( int  targetId)

Set preferable target for inference computation. See OpenCV setPreferableTarget documentation for more information.

Parameters
targetIdTarget identifier

Definition at line 407 of file vpDetectorDNN.cpp.

◆ setScaleFactor()

void vpDetectorDNN::setScaleFactor ( double  scaleFactor)

Set scale factor to normalize the range of pixel values.

Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 412 of file vpDetectorDNN.cpp.

◆ setSwapRB()

void vpDetectorDNN::setSwapRB ( 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).

Examples
tutorial-dnn-object-detection-live.cpp.

Definition at line 419 of file vpDetectorDNN.cpp.

◆ setTimeout()

void vpDetectorBase::setTimeout ( unsigned long  timeout_ms)
inlineinherited

Set detector timeout in milli-seconds. When set to 0, there is no timeout.

Definition at line 129 of file vpDetectorBase.h.

Referenced by vpDetectorDataMatrixCode::vpDetectorDataMatrixCode().

Member Data Documentation

◆ m_message

std::vector<std::string> vpDetectorBase::m_message
protectedinherited

◆ m_nb_objects

size_t vpDetectorBase::m_nb_objects
protectedinherited

Number of detected objects.

Definition at line 69 of file vpDetectorBase.h.

Referenced by vpDetectorAprilTag::detect(), vpDetectorDataMatrixCode::detect(), vpDetectorQRCode::detect(), and detect().

◆ m_polygon

std::vector<std::vector<vpImagePoint> > vpDetectorBase::m_polygon
protectedinherited

◆ m_timeout_ms

unsigned long vpDetectorBase::m_timeout_ms
protectedinherited

Detection timeout.

Definition at line 70 of file vpDetectorBase.h.

Referenced by vpDetectorDataMatrixCode::detect().