Visual Servoing Platform  version 3.1.0
vpFernClassifier.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 */
195  int nbView;
197  int dist;
203  int nbOctave;
207  int radius;
209  int nbPoints;
210 
211  /* parameters for the filter */
214  bool blurImage;
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:
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...
std::vector< cv::KeyPoint > imgKeypoints
the vector containing the points in the current image.
bool hasLearn
Flag to indicate whether the classifier has been trained or not.
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
int nbClassfier
Number of classifier.
int nbView
Number of view to generate for the training.
cv::Rect modelROI_Ref
the ROI in the reference image.
cv::PatchGenerator gen
The patch generator (OpenCV format).
unsigned int nbMinPoint
cv::LDetector ldetector
The points of interest detector.
static const vpColor green
Definition: vpColor.h:183
int radius
Radius for the detector.
int nbPoints
Maximal number of points.
int patchSize
Size of the patch.
int sigmaBlur
Sigma of the kernel used to blur the image.
int nbOctave
Number of octave for the multi scale.
virtual unsigned int buildReference(const vpImage< unsigned char > &I)=0
const std::vector< cv::Point2f > & getRefPt() const
cv::Rect getModelROI() const
std::vector< cv::KeyPoint > objKeypoints
keypoints detected in the reference image.
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
int threshold
Threshold to accept or reject points (usually around 20)
cv::FernClassifier fernClassifier
The Fern classifier.
int dist
Minimal distance between two points.
std::vector< cv::Point2f > refPt
vector in the OpenCV format to be used by the detector.
Defines a rectangle in the plane.
Definition: vpRect.h:78
int radiusBlur
Radius of the kernel used to blur the image.
cv::Mat curImg
The current image in the OpenCV format.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
const std::vector< cv::Point2f > & getCurPt() const
std::vector< cv::KeyPoint > modelPoints
the vector containing the points in the model.
void setBlurSetting(const bool _blur)
int ClassifierSize
Size of the classifier.
cv::Rect modelROI
the ROI for the reference image.
Class that implements the Fern classifier and the YAPE detector thanks to the OpenCV library...