ViSP  2.10.0
vpFernClassifier.h
1 /****************************************************************************
2  *
3  * $Id: vpFernClassifier.h 5203 2015-01-24 09:33: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) && (VISP_HAVE_OPENCV_VERSION < 0x030000) // Require opencv >= 2.0.0 and < 3.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 
178 class VISP_EXPORT vpFernClassifier: public vpBasicKeyPoint
179 {
180 protected:
182  cv::LDetector ldetector;
183 
185  cv::FernClassifier fernClassifier;
186 
188  cv::PatchGenerator gen;
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 #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 
245 public:
247  vpFernClassifier(const std::string& _dataFile, const std::string& _objectName);
248  virtual ~vpFernClassifier();
249 
250  /* build reference */
251  virtual unsigned int buildReference(const vpImage<unsigned char> &I);
252  virtual unsigned int buildReference(const vpImage<unsigned char> &I,
253  const vpImagePoint &iP,
254  const unsigned int height, const unsigned int width);
255  virtual unsigned int buildReference(const vpImage<unsigned char> &I,
256  const vpRect& rectangle);
257 
258  /* matching */
259  virtual unsigned int matchPoint(const vpImage<unsigned char> &I);
260  virtual unsigned int matchPoint(const vpImage<unsigned char> &I,
261  const vpImagePoint &iP,
262  const unsigned int height, const unsigned int width);
263  virtual unsigned int matchPoint(const vpImage<unsigned char> &I,
264  const vpRect& rectangle);
265 
266  /* display */
267  virtual void display(const vpImage<unsigned char> &Iref,
268  const vpImage<unsigned char> &Icurrent, unsigned int size=3);
269  virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size=3,
270  const vpColor &color=vpColor::green);
271 
272  /* io methods */
273  void load(const std::string& _dataFile, const std::string& /*_objectName*/);
274  void record(const std::string& _objectName, const std::string& _dataFile);
275 
276 
277 
278  /* accessors */
285  inline void setBlurSetting(const bool _blur){ blurImage = _blur;}
286  inline void setBlurSettings(const bool _blur, int _sigma, int _size);
287 
295  inline bool getBlurSetting(){ return blurImage;}
296 
302  inline int getBlurSigma() { return this->sigmaBlur;}
303 
309  inline int getBlurSize() { return this->radiusBlur;}
310 
316  const std::vector<cv::Point2f>& getRefPt() const {return refPt;}
317 
323  const std::vector<cv::Point2f>& getCurPt() const {return curPt;}
324 
328  cv::Rect getModelROI() const { return modelROI;}
329 
330 protected:
331  void setImage(const vpImage<unsigned char>& I);
332  void train();
333  virtual void init();
334 };
335 
336 #endif /* opencv ver > 2.0.0 */
337 
338 #endif
339 
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.
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:93
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...