Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
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)
 

Protected Attributes

std::vector< std::vector< vpImagePoint > > m_polygon
 
std::vector< std::string > m_message
 
size_t m_nb_objects
 

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

Definition at line 41 of file vpDetectorDNN.cpp.

vpDetectorDNN::~vpDetectorDNN ( )
virtual

Definition at line 45 of file vpDetectorDNN.cpp.

Member Function Documentation

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

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.

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, and mbot-apriltag-ibvs.cpp.

Definition at line 74 of file vpDetectorBase.cpp.

References vpDetectorBase::m_polygon.

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.

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.

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.

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

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

Definition at line 62 of file vpDetectorBase.cpp.

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

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

Returns ith object container box as a vector of points.

Definition at line 50 of file vpDetectorBase.cpp.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

Member Data Documentation

std::vector<std::string> vpDetectorBase::m_message
protectedinherited
size_t vpDetectorBase::m_nb_objects
protectedinherited
std::vector<std::vector<vpImagePoint> > vpDetectorBase::m_polygon
protectedinherited