ViSP  2.8.0
vpFernClassifier.h
1 /****************************************************************************
2  *
3  * $Id: vpFernClassifier.h 4201 2013-04-08 08:20:47Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.GPL at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Class that implements the Fern classifier and the YAPE detector thanks
36  * to the OpenCV library.
37  *
38  * Authors:
39  * Romain Tallonneau
40  *
41  *****************************************************************************/
42 
43 #ifndef vpFernClassifier_H
44 #define vpFernClassifier_H
45 
46 #include <visp/vpConfig.h>
47 
48 #include <string>
49 
50 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) // Require opencv >= 2.0.0
51 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
52 # include <opencv2/imgproc/imgproc.hpp>
53 # include <opencv2/features2d/features2d.hpp>
54 # include <opencv2/legacy/legacy.hpp>
55 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020000) // Require opencv >= 2.0.0
56 # include <cv.h>
57 # include <cvaux.hpp>
58 #endif
59 
60 #include <visp/vpBasicKeyPoint.h>
61 
182 class VISP_EXPORT vpFernClassifier: public vpBasicKeyPoint
183 {
184 protected:
186  cv::LDetector ldetector;
187 
189  cv::FernClassifier fernClassifier;
190 
192  cv::PatchGenerator gen;
193 
194 
196  bool hasLearn;
197 
198  /* parameters for the key-points detector and the classifier */
202  int nbView;
204  int dist;
210  int nbOctave;
214  int radius;
216  int nbPoints;
217 
218  /* parameters for the filter */
220  bool blurImage;
225 
227  unsigned int nbMinPoint;
228 
230  IplImage* curIplImg;
231 
233  std::vector<cv::KeyPoint> objKeypoints;
235  cv::Rect modelROI_Ref;
237  cv::Rect modelROI;
239  std::vector<cv::KeyPoint> modelPoints;
241  std::vector<cv::KeyPoint> imgKeypoints;
243  std::vector<cv::Point2f> refPt, curPt;
244 
245 
246 public:
248  vpFernClassifier(const std::string& _dataFile, const std::string& _objectName);
249  virtual ~vpFernClassifier();
250 
251  /* build reference */
252  virtual unsigned int buildReference(const vpImage<unsigned char> &I);
253  virtual unsigned int buildReference(const vpImage<unsigned char> &I,
254  const vpImagePoint &iP,
255  const unsigned int height, const unsigned int width);
256  virtual unsigned int buildReference(const vpImage<unsigned char> &I,
257  const vpRect& rectangle);
258 
259  /* matching */
260  virtual unsigned int matchPoint(const vpImage<unsigned char> &I);
261  virtual unsigned int matchPoint(const vpImage<unsigned char> &I,
262  const vpImagePoint &iP,
263  const unsigned int height, const unsigned int width);
264  virtual unsigned int matchPoint(const vpImage<unsigned char> &I,
265  const vpRect& rectangle);
266 
267  /* display */
268  virtual void display(const vpImage<unsigned char> &Iref,
269  const vpImage<unsigned char> &Icurrent, unsigned int size=3);
270  virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size=3,
271  const vpColor &color=vpColor::green);
272 
273  /* io methods */
274  void load(const std::string& _dataFile, const std::string& /*_objectName*/);
275  void record(const std::string& _objectName, const std::string& _dataFile);
276 
277 
278 
279  /* accessors */
286  inline void setBlurSetting(const bool _blur){ blurImage = _blur;}
287  inline void setBlurSettings(const bool _blur, int _sigma, int _size);
288 
296  inline bool getBlurSetting(){ return blurImage;}
297 
303  inline int getBlurSigma() { return this->sigmaBlur;}
304 
310  inline int getBlurSize() { return this->radiusBlur;}
311 
317  const std::vector<cv::Point2f>& getRefPt() const {return refPt;}
318 
324  const std::vector<cv::Point2f>& getCurPt() const {return curPt;}
325 
329  cv::Rect getModelROI() const { return modelROI;}
330 
331 protected:
332  void setImage(const vpImage<unsigned char>& _I);
333  void train();
334  virtual void init();
335 };
336 
337 #endif /* opencv ver > 2.0.0 */
338 
339 #endif
340 
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 blurImage
Flag to specify whether the reference image have to be blurred or not in order to improve the recogni...
bool hasLearn
Flag to indicate whether the classifier has been trained or not.
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
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
Number of minimum point below which the homography is not estimated (must be at least four) ...
cv::LDetector ldetector
The points of interest detector.
const std::vector< cv::Point2f > & getRefPt() const
static const vpColor green
Definition: vpColor.h:170
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 > & getCurPt() 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::Rect getModelROI() const
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:82
int radiusBlur
Radius of the kernel used to blur the image.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
IplImage * curIplImg
The current image in the OpenCV format.
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...