ViSP  2.8.0
vpPlanarObjectDetector.h
1 /****************************************************************************
2  *
3  * $Id: vpPlanarObjectDetector.h 4303 2013-07-04 14:14:00Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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) // Require opencv >= 2.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 
143 class VISP_EXPORT vpPlanarObjectDetector{
144 protected:
147 
151  cv::Mat H;
152 
154  std::vector<cv::Point2f> dst_corners;
155 
157  bool isCorrect;
158 
160  std::vector<cv::Point2f> ref_corners;
161 
163  cv::Rect modelROI;
164 
166  std::vector<vpImagePoint> currentImagePoints;
168  std::vector<vpImagePoint> refImagePoints;
169 
171  unsigned int minNbMatching;
172 
173 public:
174 
175  // constructors and destructors
177  vpPlanarObjectDetector(const std::string& dataFile, const std::string& objectName);
178  virtual ~vpPlanarObjectDetector();
179 
180  // main functions
181  // creation of reference
182  unsigned int buildReference(const vpImage<unsigned char> &I);
183  unsigned int buildReference(const vpImage<unsigned char> &I,
184  const vpImagePoint &iP,
185  unsigned int height, unsigned int width);
186  unsigned int buildReference(const vpImage<unsigned char> &I,
187  const vpRect rectangle);
188 
189  // matching
190  bool matchPoint(const vpImage<unsigned char> &I);
191  bool matchPoint(const vpImage<unsigned char> &I,
192  const vpImagePoint &iP, const unsigned int height, const unsigned int width);
193  bool matchPoint(const vpImage<unsigned char> &I, const vpRect rectangle);
194  // database management
195  void recordDetector(const std::string& objectName, const std::string& dataFile);
196  void load(const std::string& dataFilename, const std::string& objName);
197 
198 
199  // display
200  void display(vpImage<unsigned char> &I, bool displayKpts = false);
201  void display(vpImage<unsigned char> &Iref,
202  vpImage<unsigned char> &Icurrent, bool displayKpts = false);
203 
210  std::vector<vpImagePoint> getDetectedCorners() const;
211 
217  vpFernClassifier& getFernClassifier() {return this->fern;}
218 
225  inline void getHomography(vpHomography& _H) const { _H = this->homography;}
226 
232  inline unsigned int getNbRefPoints() {return (unsigned int)currentImagePoints.size() ;}
233 
242  void getReferencePoint(const unsigned int _i, vpImagePoint& _imPoint);
243 
251  void getMatchedPoints(const unsigned int _index, vpImagePoint& _referencePoint, vpImagePoint& _currentPoint);
252 
259  void setMinNbPointValidation(const unsigned int _min){ this->minNbMatching = _min;}
260 
261 
268  unsigned int getMinNbPointValidation() const { return this->minNbMatching;}
269 
270 protected:
271 
272  virtual void init();
273  void computeRoi(vpImagePoint* ip, const unsigned int nbpt);
274  void initialiseRefCorners(const cv::Rect& _modelROI);
275 };
276 
277 #endif
278 
279 #endif /* VPPLANAROBJECTDETECTOR_H_ */
280 
281 
282 
283 
284 
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:173
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:82
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
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...