ViSP  2.10.0
vpPlanarObjectDetector.h
1 /****************************************************************************
2  *
3  * $Id: vpPlanarObjectDetector.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.txt 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  * Planar surface detection tool.
36  *
37  * Authors:
38  * Romain Tallonneau
39  *
40  *****************************************************************************/
41 
42 #ifndef VPPLANAROBJECTDETECTOR_H_
43 #define VPPLANAROBJECTDETECTOR_H_
44 
45 #include <visp/vpConfig.h>
46 
47 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) && (VISP_HAVE_OPENCV_VERSION < 0x030000) // Require opencv >= 2.0.0 and < 3.0.0
48 
49 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
50 # include <opencv2/imgproc/imgproc.hpp>
51 # include <opencv2/features2d/features2d.hpp>
52 # include <opencv2/calib3d/calib3d.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 <visp/vpImagePoint.h>
59 #include <visp/vpImage.h>
60 #include <visp/vpRect.h>
61 #include <visp/vpImagePoint.h>
62 #include <visp/vpPoint.h>
63 #include <visp/vpHomogeneousMatrix.h>
64 #include <visp/vpCameraParameters.h>
65 #include <visp/vpHomography.h>
66 #include <visp/vpFernClassifier.h>
67 
145 class VISP_EXPORT vpPlanarObjectDetector{
146 protected:
149 
153  cv::Mat H;
154 
156  std::vector<cv::Point2f> dst_corners;
157 
159  bool isCorrect;
160 
162  std::vector<cv::Point2f> ref_corners;
163 
165  cv::Rect modelROI;
166 
168  std::vector<vpImagePoint> currentImagePoints;
170  std::vector<vpImagePoint> refImagePoints;
171 
173  unsigned int minNbMatching;
174 
175 public:
176 
177  // constructors and destructors
179  vpPlanarObjectDetector(const std::string& dataFile, const std::string& objectName);
180  virtual ~vpPlanarObjectDetector();
181 
182  // main functions
183  // creation of reference
184  unsigned int buildReference(const vpImage<unsigned char> &I);
185  unsigned int buildReference(const vpImage<unsigned char> &I,
186  const vpImagePoint &iP,
187  unsigned int height, unsigned int width);
188  unsigned int buildReference(const vpImage<unsigned char> &I,
189  const vpRect rectangle);
190 
191  // matching
192  bool matchPoint(const vpImage<unsigned char> &I);
193  bool matchPoint(const vpImage<unsigned char> &I,
194  const vpImagePoint &iP, const unsigned int height, const unsigned int width);
195  bool matchPoint(const vpImage<unsigned char> &I, const vpRect rectangle);
196  // database management
197  void recordDetector(const std::string& objectName, const std::string& dataFile);
198  void load(const std::string& dataFilename, const std::string& objName);
199 
200 
201  // display
202  void display(vpImage<unsigned char> &I, bool displayKpts = false);
203  void display(vpImage<unsigned char> &Iref,
204  vpImage<unsigned char> &Icurrent, bool displayKpts = false);
205 
212  std::vector<vpImagePoint> getDetectedCorners() const;
213 
219  vpFernClassifier& getFernClassifier() {return this->fern;}
220 
227  inline void getHomography(vpHomography& _H) const { _H = this->homography;}
228 
234  inline unsigned int getNbRefPoints() {return (unsigned int)currentImagePoints.size() ;}
235 
244  void getReferencePoint(const unsigned int _i, vpImagePoint& _imPoint);
245 
253  void getMatchedPoints(const unsigned int _index, vpImagePoint& _referencePoint, vpImagePoint& _currentPoint);
254 
261  void setMinNbPointValidation(const unsigned int _min){ this->minNbMatching = _min;}
262 
263 
270  unsigned int getMinNbPointValidation() const { return this->minNbMatching;}
271 
272 protected:
273 
274  virtual void init();
275  void computeRoi(vpImagePoint* ip, const unsigned int nbpt);
276  void initialiseRefCorners(const cv::Rect& _modelROI);
277 };
278 
279 #endif
280 
281 #endif /* VPPLANAROBJECTDETECTOR_H_ */
282 
283 
284 
285 
286 
vpFernClassifier & getFernClassifier()
void getHomography(vpHomography &_H) const
std::vector< cv::Point2f > ref_corners
The corners in the reference image.
cv::Rect modelROI
The ROI for the reference image.
cv::Mat H
Computed homography in the OpenCV format.
void setMinNbPointValidation(const unsigned int _min)
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:178
std::vector< cv::Point2f > dst_corners
The estimated new coordinates of the corners (reprojected using the homography).
vpFernClassifier fern
Fern Classifier used to match the points between a reference image and the current image...
std::vector< vpImagePoint > currentImagePoints
Vector of the image point in the current image that match after the deletion of the outliers with the...
vpHomography homography
Computed homography in the ViSP format.
unsigned int getMinNbPointValidation() const
bool isCorrect
Flag to indicate wether the last computed homography is correct or not.
unsigned int minNbMatching
Minimal number of point to after the ransac needed to suppose that the homography has been correctly ...
Defines a rectangle in the plane.
Definition: vpRect.h:85
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
Class used to detect a planar surface.
std::vector< vpImagePoint > refImagePoints
Vector of the image point in the reference image that match after the deletion of the outliers with t...
Class that implements the Fern classifier and the YAPE detector thanks to the OpenCV library...