ViSP  2.9.0
vpFernClassifier.h
1 /****************************************************************************
2  *
3  * $Id: vpFernClassifier.h 4664 2014-02-16 16:17:54Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 
177 class VISP_EXPORT vpFernClassifier: public vpBasicKeyPoint
178 {
179 protected:
181  cv::LDetector ldetector;
182 
184  cv::FernClassifier fernClassifier;
185 
187  cv::PatchGenerator gen;
188 
189 
191  bool hasLearn;
192 
193  /* parameters for the key-points detector and the classifier */
197  int nbView;
199  int dist;
205  int nbOctave;
209  int radius;
211  int nbPoints;
212 
213  /* parameters for the filter */
215  bool blurImage;
220 
222  unsigned int nbMinPoint;
223 
225  IplImage* curIplImg;
226 
228  std::vector<cv::KeyPoint> objKeypoints;
230  cv::Rect modelROI_Ref;
232  cv::Rect modelROI;
234  std::vector<cv::KeyPoint> modelPoints;
236  std::vector<cv::KeyPoint> imgKeypoints;
238  std::vector<cv::Point2f> refPt, curPt;
239 
240 
241 public:
243  vpFernClassifier(const std::string& _dataFile, const std::string& _objectName);
244  virtual ~vpFernClassifier();
245 
246  /* build reference */
247  virtual unsigned int buildReference(const vpImage<unsigned char> &I);
248  virtual unsigned int buildReference(const vpImage<unsigned char> &I,
249  const vpImagePoint &iP,
250  const unsigned int height, const unsigned int width);
251  virtual unsigned int buildReference(const vpImage<unsigned char> &I,
252  const vpRect& rectangle);
253 
254  /* matching */
255  virtual unsigned int matchPoint(const vpImage<unsigned char> &I);
256  virtual unsigned int matchPoint(const vpImage<unsigned char> &I,
257  const vpImagePoint &iP,
258  const unsigned int height, const unsigned int width);
259  virtual unsigned int matchPoint(const vpImage<unsigned char> &I,
260  const vpRect& rectangle);
261 
262  /* display */
263  virtual void display(const vpImage<unsigned char> &Iref,
264  const vpImage<unsigned char> &Icurrent, unsigned int size=3);
265  virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size=3,
266  const vpColor &color=vpColor::green);
267 
268  /* io methods */
269  void load(const std::string& _dataFile, const std::string& /*_objectName*/);
270  void record(const std::string& _objectName, const std::string& _dataFile);
271 
272 
273 
274  /* accessors */
281  inline void setBlurSetting(const bool _blur){ blurImage = _blur;}
282  inline void setBlurSettings(const bool _blur, int _sigma, int _size);
283 
291  inline bool getBlurSetting(){ return blurImage;}
292 
298  inline int getBlurSigma() { return this->sigmaBlur;}
299 
305  inline int getBlurSize() { return this->radiusBlur;}
306 
312  const std::vector<cv::Point2f>& getRefPt() const {return refPt;}
313 
319  const std::vector<cv::Point2f>& getCurPt() const {return curPt;}
320 
324  cv::Rect getModelROI() const { return modelROI;}
325 
326 protected:
327  void setImage(const vpImage<unsigned char>& _I);
328  void train();
329  virtual void init();
330 };
331 
332 #endif /* opencv ver > 2.0.0 */
333 
334 #endif
335 
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:85
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...