Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpDetectorDNN Class Reference

#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 45 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 55 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 69 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, servoBebop2.cpp, servoFlirPtuIBVS.cpp, servoFrankaPBVS.cpp, and tutorial-flir-ptu-ibvs.cpp.

Definition at line 79 of file vpDetectorBase.cpp.

References vpDetectorBase::m_polygon.

Referenced by VispDetector::detectAprilTag:px:py:.

◆ 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 118 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 142 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 158 of file vpDetectorDNN.cpp.

◆ getMessage() [1/2]

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

◆ 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]

std::vector<std::vector<vpImagePoint> >& vpDetectorBase::getPolygon ( )
inlineinherited

◆ 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 301 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 315 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 325 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 337 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 347 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 357 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 367 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 374 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 383 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

◆ 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().