Visual Servoing Platform  version 3.6.0 under development (2023-10-01)
vpDetectorDNNOpenCV.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * DNN object detection using OpenCV DNN module.
33  *
34 *****************************************************************************/
35 #ifndef _vpDetectorDNN_h_
36 #define _vpDetectorDNN_h_
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
41 #include <map>
42 #include <string>
43 #include <vector>
44 
45 #include <opencv2/dnn.hpp>
46 
47 #include <visp3/core/vpColor.h>
48 #include <visp3/core/vpDisplay.h>
49 #include <visp3/core/vpImage.h>
50 #include <visp3/core/vpRect.h>
51 
52 #include <optional>
53 #ifdef VISP_HAVE_NLOHMANN_JSON
54 #include <nlohmann/json.hpp>
55 using json = nlohmann::json;
56 #endif
57 
80 class VISP_EXPORT vpDetectorDNNOpenCV
81 {
82 public:
88  typedef enum DNNResultsParsingType
89  {
90  USER_SPECIFIED = 0,
91  FASTER_RCNN = 1,
92  SSD_MOBILENET = 2,
93  RESNET_10 = 3,
94  YOLO_V3 = 4,
95  YOLO_V4 = 5,
96  YOLO_V5 = 6,
97  YOLO_V7 = 7,
98  YOLO_V8 = 8,
99  COUNT = 9
100  } DNNResultsParsingType;
101 
102  typedef struct DetectionCandidates
103  {
104  std::vector< float > m_confidences;
105  std::vector< cv::Rect > m_boxes;
106  std::vector< int > m_classIds;
107  } DetectionCandidates;
108 
114  typedef class DetectedFeatures2D
115  {
116  protected:
118  double m_score;
119  unsigned int m_cls;
120  std::optional<std::string> m_classname;
121  public:
133  inline explicit DetectedFeatures2D(double u_min, double u_max
134  , double v_min, double v_max
135  , unsigned int cls, double score
136  , const std::optional<std::string> &classname
137  )
138  : m_bbox(vpImagePoint(v_min, u_min), vpImagePoint(v_max, u_max))
139  , m_score(score)
140  , m_cls(cls)
141  {
142  if (classname) {
143  m_classname = classname;
144  }
145  else {
146  m_classname = std::nullopt;
147  }
148  };
149 
153  inline vpRect getBoundingBox() const { return m_bbox; }
157  inline double getConfidenceScore() const { return m_score; }
161  inline unsigned int getClassId() const { return m_cls; }
165  inline std::optional<std::string> getClassName() const { return m_classname; }
166 
167  template < typename Type >
168  void display(const vpImage< Type > &img, const vpColor &color = vpColor::blue, unsigned int thickness = 1) const;
169 
171  } DetectedFeatures2D;
172 
177  typedef class NetConfig
178  {
179  private:
180  float m_confThreshold;
181  float m_nmsThreshold;
182  std::vector<std::string> m_classNames;
183  cv::Size m_inputSize;
184  double m_filterSizeRatio;
186  cv::Scalar m_mean;
187  double m_scaleFactor;
188  bool m_swapRB; /*<! If true, swap R and B for mean subtraction, e.g. when a model has been trained on BGR image format.*/
189  DNNResultsParsingType m_parsingMethodType;
190  std::string m_modelFilename;
191  std::string m_modelConfigFilename; /*<! Path towards the model additional configuration file, e.g. pbtxt file.*/
192  std::string m_framework;
194 #ifdef VISP_HAVE_NLOHMANN_JSON
202  inline friend void from_json(const json &j, NetConfig &config)
203  {
204  config.m_confThreshold = j.value("confidenceThreshold", config.m_confThreshold);
205  if (config.m_confThreshold <= 0) {
206  throw vpException(vpException::badValue, "Confidence threshold should be > 0");
207  }
208 
209  config.m_nmsThreshold = j.value("nmsThreshold", config.m_nmsThreshold);
210  if (config.m_nmsThreshold <= 0) {
211  throw vpException(vpException::badValue, "Confidence threshold should be > 0");
212  }
213 
214  config.m_filterSizeRatio = j.value("filterSizeRatio", config.m_filterSizeRatio);
215 
216  config.m_classNames = j.value("classNames", config.m_classNames);
217 
218  std::pair<unsigned int, unsigned int> resolution = j.value("resolution", std::pair<unsigned int, unsigned int>(config.m_inputSize.width, config.m_inputSize.height));
219  config.m_inputSize.width = resolution.first;
220  config.m_inputSize.height = resolution.second;
221 
222  std::vector<double> v_mean = j.value("mean", std::vector<double>({ config.m_mean[0], config.m_mean[1], config.m_mean[2] }));
223  if (v_mean.size() != 3) {
224  throw(vpException(vpException::dimensionError, "Mean should have size = 3"));
225  }
226  config.m_mean = cv::Scalar(v_mean[0], v_mean[1], v_mean[2]);
227 
228  config.m_scaleFactor = j.value("scale", config.m_scaleFactor);
229  config.m_swapRB = j.value("swapRB", config.m_swapRB);
230  config.m_parsingMethodType = dnnResultsParsingTypeFromString(j.value("parsingType", dnnResultsParsingTypeToString(config.m_parsingMethodType)));
231  config.m_modelFilename = j.value("modelFile", config.m_modelFilename);
232  config.m_modelConfigFilename = j.value("configurationFile", config.m_modelConfigFilename);
233  config.m_framework = j.value("framework", config.m_framework);
234  }
235 
242  inline friend void to_json(json &j, const NetConfig &config)
243  {
244  std::pair<unsigned int, unsigned int> resolution = { config.m_inputSize.width, config.m_inputSize.height };
245  std::vector<double> v_mean = { config.m_mean[0], config.m_mean[1], config.m_mean[2] };
246  j = json {
247  {"confidenceThreshold", config.m_confThreshold } ,
248  {"nmsThreshold" , config.m_nmsThreshold } ,
249  {"filterSizeRatio" , config.m_filterSizeRatio} ,
250  {"classNames" , config.m_classNames } ,
251  {"resolution" , resolution } ,
252  {"mean" , v_mean } ,
253  {"scale" , config.m_scaleFactor } ,
254  {"swapRB" , config.m_swapRB } ,
255  {"parsingType" , dnnResultsParsingTypeToString(config.m_parsingMethodType) },
256  {"modelFile" , config.m_modelFilename } ,
257  {"configurationFile" , config.m_modelConfigFilename } ,
258  {"framework" , config.m_framework }
259  };
260  }
261 #endif
262 
263  public:
286  inline static std::vector<std::string> parseClassNamesFile(const std::string &filename)
287  {
288  std::vector<std::string> classNames;
289  std::ifstream ifs(filename);
290  std::string line;
291  while (getline(ifs, line)) {
292  if (line.find("[") == std::string::npos) {
293  classNames.push_back(line);
294  }
295  else {
296  std::string lineWithoutBracket;
297  if (line.find("[") != std::string::npos) {
298  lineWithoutBracket = line.substr(line.find("[") + 1, line.size() - 2); // Remove opening and closing brackets
299  }
300 
301  while (!lineWithoutBracket.empty()) {
302  std::string className;
303  auto start_pos = lineWithoutBracket.find("\"");
304  auto end_pos = lineWithoutBracket.find("\"", start_pos + 1);
305  className = lineWithoutBracket.substr(start_pos + 1, end_pos - (start_pos + 1));
306  if (!className.empty()) {
307  classNames.push_back(className);
308  lineWithoutBracket = lineWithoutBracket.substr(end_pos + 1);
309  }
310  }
311  }
312  }
313  return classNames;
314  }
315 
319  inline NetConfig()
320  : m_confThreshold(0.5f)
321  , m_nmsThreshold(0.4f)
322  , m_classNames()
323  , m_inputSize(300, 300)
324  , m_filterSizeRatio(0.)
325  , m_mean(127.5, 127.5, 127.5)
326  , m_scaleFactor(2.0 / 255.0)
327  , m_swapRB(true)
328  , m_parsingMethodType(vpDetectorDNNOpenCV::USER_SPECIFIED)
329  , m_modelFilename()
330  , m_modelConfigFilename()
331  , m_framework()
332  {
333 
334  }
335 
336  inline NetConfig(const NetConfig &config)
337  : m_confThreshold(config.m_confThreshold)
338  , m_nmsThreshold(config.m_nmsThreshold)
339  , m_classNames(config.m_classNames)
340  , m_inputSize(config.m_inputSize.width, config.m_inputSize.height)
341  , m_filterSizeRatio(config.m_filterSizeRatio)
342  , m_mean(cv::Scalar(config.m_mean[0], config.m_mean[1], config.m_mean[2]))
343  , m_scaleFactor(config.m_scaleFactor)
344  , m_swapRB(config.m_swapRB)
345  , m_parsingMethodType(config.m_parsingMethodType)
346  , m_modelFilename(config.m_modelFilename)
347  , m_modelConfigFilename(config.m_modelConfigFilename)
348  , m_framework(config.m_framework)
349  {
350 
351  }
352 
370  inline NetConfig(float confThresh, const float &nmsThresh, const std::vector<std::string> &classNames, const cv::Size &dnnInputSize, const double &filterSizeRatio = 0.
371  , const cv::Scalar &mean = cv::Scalar(127.5, 127.5, 127.5), const double &scaleFactor = 2. / 255., const bool &swapRB = true
372  , const DNNResultsParsingType &parsingType = vpDetectorDNNOpenCV::USER_SPECIFIED, const std::string &modelFilename = "", const std::string &configFilename = "", const std::string &framework = "")
373  : m_confThreshold(confThresh)
374  , m_nmsThreshold(nmsThresh)
375  , m_classNames(classNames)
376  , m_inputSize(dnnInputSize)
377  , m_filterSizeRatio(filterSizeRatio)
378  , m_mean(mean)
379  , m_scaleFactor(scaleFactor)
380  , m_swapRB(swapRB)
381  , m_parsingMethodType(parsingType)
382  , m_modelFilename(modelFilename)
383  , m_modelConfigFilename(configFilename)
384  , m_framework(framework)
385  { }
386 
404  inline NetConfig(const float &confThresh, const float &nmsThresh, const std::string &classNamesFile, const cv::Size &dnnInputSize, const double &filterSizeRatio = 0.
405  , const cv::Scalar &mean = cv::Scalar(127.5, 127.5, 127.5), const double &scaleFactor = 2. / 255., const bool &swapRB = true
406  , const DNNResultsParsingType &parsingType = vpDetectorDNNOpenCV::USER_SPECIFIED, const std::string &modelFilename = "", const std::string &configFilename = "", const std::string &framework = "")
407  : m_confThreshold(confThresh)
408  , m_nmsThreshold(nmsThresh)
409  , m_inputSize(dnnInputSize)
410  , m_filterSizeRatio(filterSizeRatio)
411  , m_mean(mean)
412  , m_scaleFactor(scaleFactor)
413  , m_swapRB(swapRB)
414  , m_parsingMethodType(parsingType)
415  , m_modelFilename(modelFilename)
416  , m_modelConfigFilename(configFilename)
417  , m_framework(framework)
418  {
419  m_classNames = parseClassNamesFile(classNamesFile);
420  }
421 
422  inline std::string toString() const
423  {
424  std::string text;
425  text += "Model : " + m_modelFilename + "\n";
426  text += "Type : " + vpDetectorDNNOpenCV::dnnResultsParsingTypeToString(m_parsingMethodType) + "\n";
427  text += "Config (optional): " + (m_modelConfigFilename.empty() ? "\"None\"" : m_modelConfigFilename) + "\n";
428  text += "Framework (optional): " + (m_framework.empty() ? "\"None\"" : m_framework) + "\n";
429  text += "Width x Height : " + std::to_string(m_inputSize.width) + " x " + std::to_string(m_inputSize.height) + "\n";
430  text += "Mean RGB : " + std::to_string(m_mean[0]) + " " + std::to_string(m_mean[1]) + " " + std::to_string(m_mean[2]) + "\n";
431  text += "Scale : " + std::to_string(m_scaleFactor) + "\n";
432  text += "Swap RB? : " + (m_swapRB ? std::string("true") : std::string("false")) + "\n";
433  text += "Confidence threshold : " + std::to_string(m_confThreshold) + "\n";
434  text += "NMS threshold : " + std::to_string(m_nmsThreshold) + "\n";
435  text += "Filter threshold : " +
436  (m_filterSizeRatio > std::numeric_limits<double>::epsilon() ? std::to_string(m_filterSizeRatio)
437  : "disabled") + "\n";
438  return text;
439  }
440 
441  inline friend std::ostream &operator<<(std::ostream &os, const NetConfig &config)
442  {
443  os << config.toString();
444  return os;
445  }
446 
447  NetConfig &operator=(const NetConfig &config)
448  {
449  m_confThreshold = config.m_confThreshold;
450  m_nmsThreshold = config.m_nmsThreshold;
451  m_classNames = config.m_classNames;
452  m_inputSize = cv::Size(config.m_inputSize.width, config.m_inputSize.height);
453  m_filterSizeRatio = config.m_filterSizeRatio;
454  m_mean = cv::Scalar(config.m_mean[0], config.m_mean[1], config.m_mean[2]);
455  m_scaleFactor = config.m_scaleFactor;
456  m_swapRB = config.m_swapRB;
457  m_parsingMethodType = config.m_parsingMethodType;
458  m_modelFilename = config.m_modelFilename;
459  m_modelConfigFilename = config.m_modelConfigFilename;
460  m_framework = config.m_framework;
461  return *this;
462  }
463 
465  } NetConfig;
466 
467  static std::string getAvailableDnnResultsParsingTypes();
468  static std::string dnnResultsParsingTypeToString(const DNNResultsParsingType &type);
469  static DNNResultsParsingType dnnResultsParsingTypeFromString(const std::string &name);
470  static std::vector<std::string> parseClassNamesFile(const std::string &filename);
472  vpDetectorDNNOpenCV(const NetConfig &config, const DNNResultsParsingType &typeParsingMethod, void (*parsingMethod)(DetectionCandidates &, std::vector<cv::Mat> &, const NetConfig &) = postProcess_unimplemented);
473 #ifdef VISP_HAVE_NLOHMANN_JSON
474  vpDetectorDNNOpenCV(const std::string &jsonPath, void (*parsingMethod)(DetectionCandidates &, std::vector<cv::Mat> &, const NetConfig &) = postProcess_unimplemented);
475  void initFromJSON(const std::string &jsonPath);
476  void saveConfigurationInJSON(const std::string &jsonPath) const;
477 #endif
478  virtual ~vpDetectorDNNOpenCV();
479 
480  virtual bool detect(const vpImage<unsigned char> &I, std::vector<DetectedFeatures2D> &output);
481  virtual bool detect(const vpImage<unsigned char> &I, std::map< std::string, std::vector<DetectedFeatures2D>> &output);
482  virtual bool detect(const vpImage<unsigned char> &I, std::vector< std::pair<std::string, std::vector<DetectedFeatures2D>>> &output);
483  virtual bool detect(const vpImage<vpRGBa> &I, std::vector<DetectedFeatures2D> &output);
484  virtual bool detect(const vpImage<vpRGBa> &I, std::map< std::string, std::vector<DetectedFeatures2D>> &output);
485  virtual bool detect(const vpImage<vpRGBa> &I, std::vector< std::pair<std::string, std::vector<DetectedFeatures2D>>> &output);
486  virtual bool detect(const cv::Mat &I, std::vector<DetectedFeatures2D> &output);
487  virtual bool detect(const cv::Mat &I, std::map< std::string, std::vector<DetectedFeatures2D>> &output);
488  virtual bool detect(const cv::Mat &I, std::vector< std::pair<std::string, std::vector<DetectedFeatures2D>>> &output);
489 
490  void readNet(const std::string &model, const std::string &config = "", const std::string &framework = "");
491 
492  void setNetConfig(const NetConfig &config);
493  void setConfidenceThreshold(const float &confThreshold);
494  void setNMSThreshold(const float &nmsThreshold);
495  void setDetectionFilterSizeRatio(const double &sizeRatio);
496  void setInputSize(const int &width, const int &height);
497  void setMean(const double &meanR, const double &meanG, const double &meanB);
498  void setPreferableBackend(const int &backendId);
499  void setPreferableTarget(const int &targetId);
500  void setScaleFactor(const double &scaleFactor);
501  void setSwapRB(const bool &swapRB);
502  void setParsingMethod(const DNNResultsParsingType &typeParsingMethod, void (*parsingMethod)(DetectionCandidates &, std::vector<cv::Mat> &, const NetConfig &) = postProcess_unimplemented);
503  inline const NetConfig &getNetConfig() const
504  {
505  return m_netConfig;
506  }
507 
508 #ifdef VISP_HAVE_NLOHMANN_JSON
516  inline friend void from_json(const json &j, vpDetectorDNNOpenCV &network)
517  {
518  network.m_netConfig = j.value("networkSettings", network.m_netConfig);
519  }
520 
527  inline friend void to_json(json &j, const vpDetectorDNNOpenCV &network)
528  {
529  j = json {
530  {"networkSettings", network.m_netConfig}
531  };
532  }
533 #endif
534 
535  inline friend std::ostream &operator<<(std::ostream &os, const vpDetectorDNNOpenCV &network)
536  {
537  os << network.m_netConfig;
538  return os;
539  }
540 
541 protected:
542 #if (VISP_HAVE_OPENCV_VERSION == 0x030403)
543  std::vector<cv::String> getOutputsNames();
544 #endif
545  std::vector<DetectedFeatures2D>
546  filterDetectionSingleClassInput(const std::vector<DetectedFeatures2D> &detected_features, const double minRatioOfAreaOk);
547 
548  std::vector<DetectedFeatures2D>
549  filterDetectionMultiClassInput(const std::vector<DetectedFeatures2D> &detected_features, const double minRatioOfAreaOk);
550 
551  std::map<std::string, std::vector<vpDetectorDNNOpenCV::DetectedFeatures2D>>
552  filterDetectionMultiClassInput(const std::map< std::string, std::vector<vpDetectorDNNOpenCV::DetectedFeatures2D>> &detected_features, const double minRatioOfAreaOk);
553 
554  void postProcess(DetectionCandidates &proposals);
555 
556  void postProcess_YoloV3_V4(DetectionCandidates &proposals, std::vector<cv::Mat> &dnnRes, const NetConfig &netConfig);
557 
558  void postProcess_YoloV5_V7(DetectionCandidates &proposals, std::vector<cv::Mat> &dnnRes, const NetConfig &netConfig);
559 
560  void postProcess_YoloV8(DetectionCandidates &proposals, std::vector<cv::Mat> &dnnRes, const NetConfig &netConfig);
561 
562  void postProcess_FasterRCNN(DetectionCandidates &proposals, std::vector<cv::Mat> &dnnRes, const NetConfig &netConfig);
563 
564 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
565  void postProcess_SSD_MobileNet(DetectionCandidates &proposals, std::vector<cv::Mat> &dnnRes, const NetConfig &netConfig);
566 #endif
567 
568  void postProcess_ResNet_10(DetectionCandidates &proposals, std::vector<cv::Mat> &dnnRes, const NetConfig &netConfig);
569 
570  static void postProcess_unimplemented(DetectionCandidates &proposals, std::vector<cv::Mat> &dnnRes, const NetConfig &netConfig);
571 
575  cv::Mat m_blob;
579  cv::Mat m_img;
581  std::vector<int> m_indices;
583  cv::dnn::Net m_net;
587  std::vector<cv::String> m_outNames;
589  std::vector<cv::Mat> m_dnnRes;
591  void (*m_parsingMethod)(DetectionCandidates &, std::vector<cv::Mat> &, const NetConfig &);
592 };
593 
601 template < typename Type >
602 inline void
603 vpDetectorDNNOpenCV::DetectedFeatures2D::display(const vpImage< Type > &img, const vpColor &color, unsigned int thickness) const
604 {
605  vpDisplay::displayRectangle(img, m_bbox, color, false, thickness);
606 
607  std::stringstream ss;
608  if (m_classname) {
609  ss << *m_classname;
610  }
611  else {
612  ss << m_cls;
613  }
614  ss << "(" << std::setprecision(4) << m_score * 100. << "%)";
615  vpDisplay::displayText(img, m_bbox.getTopRight(), ss.str(), color);
616 }
617 #endif
618 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
static const vpColor blue
Definition: vpColor.h:217
Structure containing the bounding box, expressed in pixels, confidence and class information about an...
void display(const vpImage< Type > &img, const vpColor &color=vpColor::blue, unsigned int thickness=1) const
DetectedFeatures2D(double u_min, double u_max, double v_min, double v_max, unsigned int cls, double score, const std::optional< std::string > &classname)
Construct a new Detected Features 2 D object.
std::optional< std::string > getClassName() const
std::optional< std::string > m_classname
Structure containing some information required for the configuration of a vpDetectorDNNOpenCV object.
NetConfig(const NetConfig &config)
friend void from_json(const json &j, NetConfig &config)
Read the network configuration from JSON. All values are optional and if an argument is not present,...
NetConfig()
Default constructor of the structure vpDetectorDNNOpenCV::NetConfig , required for JSON serialization...
friend std::ostream & operator<<(std::ostream &os, const NetConfig &config)
NetConfig(float confThresh, const float &nmsThresh, const std::vector< std::string > &classNames, const cv::Size &dnnInputSize, const double &filterSizeRatio=0., const cv::Scalar &mean=cv::Scalar(127.5, 127.5, 127.5), const double &scaleFactor=2./255., const bool &swapRB=true, const DNNResultsParsingType &parsingType=vpDetectorDNNOpenCV::USER_SPECIFIED, const std::string &modelFilename="", const std::string &configFilename="", const std::string &framework="")
Construct a new Net Config object.
NetConfig & operator=(const NetConfig &config)
static std::vector< std::string > parseClassNamesFile(const std::string &filename)
Parse the file containing the list of classes the DNN can detect. These classes can be written either...
friend void to_json(json &j, const NetConfig &config)
Parse a vpDetectorDNNOpenCV::NetConfig into JSON format.
NetConfig(const float &confThresh, const float &nmsThresh, const std::string &classNamesFile, const cv::Size &dnnInputSize, const double &filterSizeRatio=0., const cv::Scalar &mean=cv::Scalar(127.5, 127.5, 127.5), const double &scaleFactor=2./255., const bool &swapRB=true, const DNNResultsParsingType &parsingType=vpDetectorDNNOpenCV::USER_SPECIFIED, const std::string &modelFilename="", const std::string &configFilename="", const std::string &framework="")
Construct a new Net Config object.
json namespace shortcut
cv::Mat m_blob
Buffer for the blob in input net.
friend std::ostream & operator<<(std::ostream &os, const vpDetectorDNNOpenCV &network)
DNNResultsParsingType
Enumeration listing the types of DNN for which the vpDetectorDNNOpenCV furnishes the methods permitti...
friend void from_json(const json &j, vpDetectorDNNOpenCV &network)
Read the network configuration from JSON. All values are optional and if an argument is not present,...
std::vector< cv::String > m_outNames
Names of layers with unconnected outputs.
const NetConfig & getNetConfig() const
cv::Mat m_img
Buffer for the input image.
std::vector< int > m_indices
Indices for NMS.
NetConfig m_netConfig
Configuration of the DNN.
std::vector< cv::Mat > m_dnnRes
Contains all output blobs for each layer specified in m_outNames.
cv::dnn::Net m_net
DNN network.
bool m_applySizeFilterAfterNMS
If true, filter the detections removing the ones for which the bbox does not respect area(bbox) € [me...
friend void to_json(json &j, const vpDetectorDNNOpenCV &network)
Parse the network configuration into JSON format.
static std::string dnnResultsParsingTypeToString(const DNNResultsParsingType &type)
vpImage< vpRGBa > m_I_color
Buffer for gray to RGBa image conversion.
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Definition: vpException.h:59
@ badValue
Used to indicate that a value is not in the allowed range.
Definition: vpException.h:85
@ dimensionError
Bad dimension.
Definition: vpException.h:83
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
Definition of the vpImage class member functions.
Definition: vpImage.h:69
Defines a rectangle in the plane.
Definition: vpRect.h:76
vpImagePoint getTopRight() const
Definition: vpRect.h:209