Visual Servoing Platform version 3.5.0
vpFernClassifier.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 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
174class VISP_EXPORT vpFernClassifier : public vpBasicKeyPoint
175{
176protected:
178 cv::LDetector ldetector;
179
181 cv::FernClassifier fernClassifier;
182
184 cv::PatchGenerator gen;
185
187 bool hasLearn;
188
189 /* parameters for the key-points detector and the classifier */
191 int threshold;
193 int nbView;
195 int dist;
197 int nbClassfier;
199 int ClassifierSize;
201 int nbOctave;
203 int patchSize;
205 int radius;
207 int nbPoints;
208
209 /* parameters for the filter */
212 bool blurImage;
214 int radiusBlur;
216 int sigmaBlur;
217
220 unsigned int nbMinPoint;
221
223#if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
224 cv::Mat curImg;
225#else
226 IplImage *curImg;
227#endif
228
230 std::vector<cv::KeyPoint> objKeypoints;
232 cv::Rect modelROI_Ref;
234 cv::Rect modelROI;
236 std::vector<cv::KeyPoint> modelPoints;
238 std::vector<cv::KeyPoint> imgKeypoints;
240 std::vector<cv::Point2f> refPt, curPt;
241
242public:
243 vpFernClassifier();
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, const vpImagePoint &_iP,
250 unsigned int _height, unsigned int _width);
251 virtual unsigned int buildReference(const vpImage<unsigned char> &I, const vpRect &rectangle);
252
253 /* matching */
254 virtual unsigned int matchPoint(const vpImage<unsigned char> &I);
255 virtual unsigned int matchPoint(const vpImage<unsigned char> &_I, const vpImagePoint &_iP, unsigned int _height,
256 unsigned int _width);
257 virtual unsigned int matchPoint(const vpImage<unsigned char> &I, const vpRect &rectangle);
258
259 /* display */
260 virtual void display(const vpImage<unsigned char> &Iref, const vpImage<unsigned char> &Icurrent,
261 unsigned int size = 3);
262 virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size = 3,
263 const vpColor &color = vpColor::green);
264
265 /* io methods */
266 void load(const std::string &_dataFile, const std::string & /*_objectName*/);
267 void record(const std::string &_objectName, const std::string &_dataFile);
268
269 /* accessors */
276 inline void setBlurSetting(const bool _blur) { blurImage = _blur; }
277 inline void setBlurSettings(const bool _blur, int _sigma, int _size);
278
286 inline bool getBlurSetting() { return blurImage; }
287
293 inline int getBlurSigma() { return this->sigmaBlur; }
294
300 inline int getBlurSize() { return this->radiusBlur; }
301
307 const std::vector<cv::Point2f> &getRefPt() const { return refPt; }
308
314 const std::vector<cv::Point2f> &getCurPt() const { return curPt; }
315
319 cv::Rect getModelROI() const { return modelROI; }
320
321protected:
322 void setImage(const vpImage<unsigned char> &I);
323 void train();
324 virtual void init();
325};
326
327#endif /* opencv ver > 2.0.0 */
328
329#endif
class that defines what is a Keypoint. This class provides all the basic elements to implement classe...
virtual unsigned int buildReference(const vpImage< unsigned char > &I)=0
virtual unsigned int matchPoint(const vpImage< unsigned char > &I)=0
virtual void display(const vpImage< unsigned char > &Iref, const vpImage< unsigned char > &Icurrent, unsigned int size=3)=0
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:158
static const vpColor green
Definition: vpColor.h:220
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
Defines a rectangle in the plane.
Definition: vpRect.h:80