Visual Servoing Platform  version 3.6.1 under development (2023-10-19)
vpFernClassifier.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  * Class that implements the Fern classifier and the YAPE detector thanks
32  * to the OpenCV library.
33  */
34 
35 #ifndef vpFernClassifier_H
36 #define vpFernClassifier_H
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #include <string>
41 
42 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408) && \
43  (VISP_HAVE_OPENCV_VERSION < 0x030000) // Require opencv >= 2.4.8 and < 3.0.0
44 #include <opencv2/features2d/features2d.hpp>
45 #include <opencv2/imgproc/imgproc.hpp>
46 #include <opencv2/legacy/legacy.hpp>
47 
48 #include <visp3/vision/vpBasicKeyPoint.h>
49 
164 class VISP_EXPORT vpFernClassifier : public vpBasicKeyPoint
165 {
166 protected:
168  cv::LDetector ldetector;
169 
171  cv::FernClassifier fernClassifier;
172 
174  cv::PatchGenerator gen;
175 
177  bool hasLearn;
178 
179  /* parameters for the key-points detector and the classifier */
181  int threshold;
183  int nbView;
185  int dist;
187  int nbClassfier;
189  int ClassifierSize;
191  int nbOctave;
193  int patchSize;
195  int radius;
197  int nbPoints;
198 
199  /* parameters for the filter */
202  bool blurImage;
204  int radiusBlur;
206  int sigmaBlur;
207 
210  unsigned int nbMinPoint;
211 
213  cv::Mat curImg;
214 
216  std::vector<cv::KeyPoint> objKeypoints;
218  cv::Rect modelROI_Ref;
220  cv::Rect modelROI;
222  std::vector<cv::KeyPoint> modelPoints;
224  std::vector<cv::KeyPoint> imgKeypoints;
226  std::vector<cv::Point2f> refPt, curPt;
227 
228 public:
229  vpFernClassifier();
230  vpFernClassifier(const std::string &_dataFile, const std::string &_objectName);
231  virtual ~vpFernClassifier();
232 
233  /* build reference */
234  virtual unsigned int buildReference(const vpImage<unsigned char> &I);
235  virtual unsigned int buildReference(const vpImage<unsigned char> &_I, const vpImagePoint &_iP, unsigned int _height,
236  unsigned int _width);
237  virtual unsigned int buildReference(const vpImage<unsigned char> &I, const vpRect &rectangle);
238 
239  /* matching */
240  virtual unsigned int matchPoint(const vpImage<unsigned char> &I);
241  virtual unsigned int matchPoint(const vpImage<unsigned char> &_I, const vpImagePoint &_iP, unsigned int _height,
242  unsigned int _width);
243  virtual unsigned int matchPoint(const vpImage<unsigned char> &I, const vpRect &rectangle);
244 
245  /* display */
246  virtual void display(const vpImage<unsigned char> &Iref, const vpImage<unsigned char> &Icurrent,
247  unsigned int size = 3);
248  virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size = 3,
249  const vpColor &color = vpColor::green);
250 
251  /* io methods */
252  void load(const std::string &_dataFile, const std::string & /*_objectName*/);
253  void record(const std::string &_objectName, const std::string &_dataFile);
254 
255  /* accessors */
262  inline void setBlurSetting(const bool _blur) { blurImage = _blur; }
263  inline void setBlurSettings(const bool _blur, int _sigma, int _size);
264 
272  inline bool getBlurSetting() { return blurImage; }
273 
279  inline int getBlurSigma() { return this->sigmaBlur; }
280 
286  inline int getBlurSize() { return this->radiusBlur; }
287 
293  const std::vector<cv::Point2f> &getRefPt() const { return refPt; }
294 
300  const std::vector<cv::Point2f> &getCurPt() const { return curPt; }
301 
305  cv::Rect getModelROI() const { return modelROI; }
306 
307 protected:
308  void setImage(const vpImage<unsigned char> &I);
309  void train();
310  virtual void init();
311 };
312 
313 #endif /* opencv ver > 2.0.0 */
314 
315 #endif
class that defines what is a keypoint. This class provides all the basic elements to implement classe...
virtual unsigned int buildReference(const vpImage< unsigned char > &I)=0
virtual unsigned int matchPoint(const vpImage< unsigned char > &I)=0
virtual void display(const vpImage< unsigned char > &Iref, const vpImage< unsigned char > &Icurrent, unsigned int size=3)=0
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
static const vpColor green
Definition: vpColor.h:214
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
Defines a rectangle in the plane.
Definition: vpRect.h:76