Visual Servoing Platform  version 3.0.0
vpFernClassifier.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Class that implements the Fern classifier and the YAPE detector thanks
32  * to the OpenCV library.
33  *
34  * Authors:
35  * Romain Tallonneau
36  *
37  *****************************************************************************/
38 
39 #ifndef vpFernClassifier_H
40 #define vpFernClassifier_H
41 
42 #include <visp3/core/vpConfig.h>
43 
44 #include <string>
45 
46 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) && (VISP_HAVE_OPENCV_VERSION < 0x030000) // Require opencv >= 2.0.0 and < 3.0.0
47 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
48 # include <opencv2/imgproc/imgproc.hpp>
49 # include <opencv2/features2d/features2d.hpp>
50 # include <opencv2/legacy/legacy.hpp>
51 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020000) // Require opencv >= 2.0.0
52 # include <cv.h>
53 # include <cvaux.hpp>
54 #endif
55 
56 #include <visp3/vision/vpBasicKeyPoint.h>
57 
175 class VISP_EXPORT vpFernClassifier: public vpBasicKeyPoint
176 {
177 protected:
179  cv::LDetector ldetector;
180 
182  cv::FernClassifier fernClassifier;
183 
185  cv::PatchGenerator gen;
186 
188  bool hasLearn;
189 
190  /* parameters for the key-points detector and the classifier */
194  int nbView;
196  int dist;
202  int nbOctave;
206  int radius;
208  int nbPoints;
209 
210  /* parameters for the filter */
212  bool blurImage;
217 
219  unsigned int nbMinPoint;
220 
222 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
223  cv::Mat curImg;
224 #else
225  IplImage* curImg;
226 #endif
227 
229  std::vector<cv::KeyPoint> objKeypoints;
231  cv::Rect modelROI_Ref;
233  cv::Rect modelROI;
235  std::vector<cv::KeyPoint> modelPoints;
237  std::vector<cv::KeyPoint> imgKeypoints;
239  std::vector<cv::Point2f> refPt, curPt;
240 
241 
242 public:
244  vpFernClassifier(const std::string& _dataFile, const std::string& _objectName);
245  virtual ~vpFernClassifier();
246 
247  /* build reference */
248  virtual unsigned int buildReference(const vpImage<unsigned char> &I);
249  virtual unsigned int buildReference(const vpImage<unsigned char> &I,
250  const vpImagePoint &iP,
251  const unsigned int height, const unsigned int width);
252  virtual unsigned int buildReference(const vpImage<unsigned char> &I,
253  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,
258  const vpImagePoint &iP,
259  const unsigned int height, const unsigned int width);
260  virtual unsigned int matchPoint(const vpImage<unsigned char> &I,
261  const vpRect& rectangle);
262 
263  /* display */
264  virtual void display(const vpImage<unsigned char> &Iref,
265  const vpImage<unsigned char> &Icurrent, unsigned int size=3);
266  virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size=3,
267  const vpColor &color=vpColor::green);
268 
269  /* io methods */
270  void load(const std::string& _dataFile, const std::string& /*_objectName*/);
271  void record(const std::string& _objectName, const std::string& _dataFile);
272 
273 
274 
275  /* accessors */
282  inline void setBlurSetting(const bool _blur){ blurImage = _blur;}
283  inline void setBlurSettings(const bool _blur, int _sigma, int _size);
284 
292  inline bool getBlurSetting(){ return blurImage;}
293 
299  inline int getBlurSigma() { return this->sigmaBlur;}
300 
306  inline int getBlurSize() { return this->radiusBlur;}
307 
313  const std::vector<cv::Point2f>& getRefPt() const {return refPt;}
314 
320  const std::vector<cv::Point2f>& getCurPt() const {return curPt;}
321 
325  cv::Rect getModelROI() const { return modelROI;}
326 
327 protected:
328  void setImage(const vpImage<unsigned char>& I);
329  void train();
330  virtual void init();
331 };
332 
333 #endif /* opencv ver > 2.0.0 */
334 
335 #endif
336 
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:121
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:166
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:81
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
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...