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