Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpFernClassifier.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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  * Class that implements the Fern classifier and the YAPE detector thanks
33  * to the OpenCV library.
34  *
35  * Authors:
36  * Romain Tallonneau
37  *
38  *****************************************************************************/
39 
40 #ifndef vpFernClassifier_H
41 #define vpFernClassifier_H
42 
43 #include <visp3/core/vpConfig.h>
44 
45 #include <string>
46 
47 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) && \
48  (VISP_HAVE_OPENCV_VERSION < 0x030000) // Require opencv >= 2.0.0 and < 3.0.0
49 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
50 #include <opencv2/features2d/features2d.hpp>
51 #include <opencv2/imgproc/imgproc.hpp>
52 #include <opencv2/legacy/legacy.hpp>
53 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020000) // Require opencv >= 2.0.0
54 #include <cv.h>
55 #include <cvaux.hpp>
56 #endif
57 
58 #include <visp3/vision/vpBasicKeyPoint.h>
59 
176 class VISP_EXPORT vpFernClassifier : public vpBasicKeyPoint
177 {
178 protected:
180  cv::LDetector ldetector;
181 
183  cv::FernClassifier fernClassifier;
184 
186  cv::PatchGenerator gen;
187 
189  bool hasLearn;
190 
191  /* parameters for the key-points detector and the classifier */
193  int threshold;
195  int nbView;
197  int dist;
199  int nbClassfier;
201  int ClassifierSize;
203  int nbOctave;
205  int patchSize;
207  int radius;
209  int nbPoints;
210 
211  /* parameters for the filter */
214  bool blurImage;
216  int radiusBlur;
218  int sigmaBlur;
219 
222  unsigned int nbMinPoint;
223 
225 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
226  cv::Mat curImg;
227 #else
228  IplImage *curImg;
229 #endif
230 
232  std::vector<cv::KeyPoint> objKeypoints;
234  cv::Rect modelROI_Ref;
236  cv::Rect modelROI;
238  std::vector<cv::KeyPoint> modelPoints;
240  std::vector<cv::KeyPoint> imgKeypoints;
242  std::vector<cv::Point2f> refPt, curPt;
243 
244 public:
245  vpFernClassifier();
246  vpFernClassifier(const std::string &_dataFile, const std::string &_objectName);
247  virtual ~vpFernClassifier();
248 
249  /* build reference */
250  virtual unsigned int buildReference(const vpImage<unsigned char> &I);
251  virtual unsigned int buildReference(const vpImage<unsigned char> &I, const vpImagePoint &iP,
252  const unsigned int height, const unsigned int width);
253  virtual unsigned int buildReference(const vpImage<unsigned char> &I, const vpRect &rectangle);
254 
255  /* matching */
256  virtual unsigned int matchPoint(const vpImage<unsigned char> &I);
257  virtual unsigned int matchPoint(const vpImage<unsigned char> &I, const vpImagePoint &iP, const unsigned int height,
258  const unsigned int width);
259  virtual unsigned int matchPoint(const vpImage<unsigned char> &I, const vpRect &rectangle);
260 
261  /* display */
262  virtual void display(const vpImage<unsigned char> &Iref, const vpImage<unsigned char> &Icurrent,
263  unsigned int size = 3);
264  virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size = 3,
265  const vpColor &color = vpColor::green);
266 
267  /* io methods */
268  void load(const std::string &_dataFile, const std::string & /*_objectName*/);
269  void record(const std::string &_objectName, const std::string &_dataFile);
270 
271  /* accessors */
278  inline void setBlurSetting(const bool _blur) { blurImage = _blur; }
279  inline void setBlurSettings(const bool _blur, int _sigma, int _size);
280 
288  inline bool getBlurSetting() { return blurImage; }
289 
295  inline int getBlurSigma() { return this->sigmaBlur; }
296 
302  inline int getBlurSize() { return this->radiusBlur; }
303 
309  const std::vector<cv::Point2f> &getRefPt() const { return refPt; }
310 
316  const std::vector<cv::Point2f> &getCurPt() const { return curPt; }
317 
321  cv::Rect getModelROI() const { return modelROI; }
322 
323 protected:
324  void setImage(const vpImage<unsigned char> &I);
325  void train();
326  virtual void init();
327 };
328 
329 #endif /* opencv ver > 2.0.0 */
330 
331 #endif
class that defines what is a Keypoint. This class provides all the basic elements to implement classe...
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
static const vpColor green
Definition: vpColor.h:183
virtual unsigned int buildReference(const vpImage< unsigned char > &I)=0
virtual void display(const vpImage< unsigned char > &Iref, const vpImage< unsigned char > &Icurrent, unsigned int size=3)=0
virtual unsigned int matchPoint(const vpImage< unsigned char > &I)=0
Defines a rectangle in the plane.
Definition: vpRect.h:78
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88