Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpPlanarObjectDetector.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  * Planar surface detection tool.
32  *
33  * Authors:
34  * Romain Tallonneau
35  *
36  *****************************************************************************/
37 
38 #ifndef VPPLANAROBJECTDETECTOR_H_
39 #define VPPLANAROBJECTDETECTOR_H_
40 
41 #include <visp3/core/vpConfig.h>
42 
43 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) && (VISP_HAVE_OPENCV_VERSION < 0x030000) // Require opencv >= 2.0.0 and < 3.0.0
44 
45 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
46 # include <opencv2/imgproc/imgproc.hpp>
47 # include <opencv2/features2d/features2d.hpp>
48 # include <opencv2/calib3d/calib3d.hpp>
49 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020000) // Require opencv >= 2.0.0
50 # include <cv.h>
51 # include <cvaux.hpp>
52 #endif
53 
54 #include <visp3/core/vpImagePoint.h>
55 #include <visp3/core/vpImage.h>
56 #include <visp3/core/vpRect.h>
57 #include <visp3/core/vpImagePoint.h>
58 #include <visp3/core/vpPoint.h>
59 #include <visp3/core/vpHomogeneousMatrix.h>
60 #include <visp3/core/vpCameraParameters.h>
61 #include <visp3/vision/vpHomography.h>
62 #include <visp3/vision/vpFernClassifier.h>
63 
142 class VISP_EXPORT vpPlanarObjectDetector{
143 protected:
146 
150  cv::Mat H;
151 
153  std::vector<cv::Point2f> dst_corners;
154 
156  bool isCorrect;
157 
159  std::vector<cv::Point2f> ref_corners;
160 
162  cv::Rect modelROI;
163 
165  std::vector<vpImagePoint> currentImagePoints;
167  std::vector<vpImagePoint> refImagePoints;
168 
170  unsigned int minNbMatching;
171 
172 public:
173 
174  // constructors and destructors
176  vpPlanarObjectDetector(const std::string& dataFile, const std::string& objectName);
177  virtual ~vpPlanarObjectDetector();
178 
179  // main functions
180  // creation of reference
181  unsigned int buildReference(const vpImage<unsigned char> &I);
182  unsigned int buildReference(const vpImage<unsigned char> &I,
183  const vpImagePoint &iP,
184  unsigned int height, unsigned int width);
185  unsigned int buildReference(const vpImage<unsigned char> &I,
186  const vpRect rectangle);
187 
188  // matching
189  bool matchPoint(const vpImage<unsigned char> &I);
190  bool matchPoint(const vpImage<unsigned char> &I,
191  const vpImagePoint &iP, const unsigned int height, const unsigned int width);
192  bool matchPoint(const vpImage<unsigned char> &I, const vpRect rectangle);
193  // database management
194  void recordDetector(const std::string& objectName, const std::string& dataFile);
195  void load(const std::string& dataFilename, const std::string& objName);
196 
197 
198  // display
199  void display(vpImage<unsigned char> &I, bool displayKpts = false);
200  void display(vpImage<unsigned char> &Iref,
201  vpImage<unsigned char> &Icurrent, bool displayKpts = false);
202 
209  std::vector<vpImagePoint> getDetectedCorners() const;
210 
216  vpFernClassifier& getFernClassifier() {return this->fern;}
217 
224  inline void getHomography(vpHomography& _H) const { _H = this->homography;}
225 
231  inline unsigned int getNbRefPoints() {return (unsigned int)currentImagePoints.size() ;}
232 
241  void getReferencePoint(const unsigned int _i, vpImagePoint& _imPoint);
242 
250  void getMatchedPoints(const unsigned int _index, vpImagePoint& _referencePoint, vpImagePoint& _currentPoint);
251 
258  void setMinNbPointValidation(const unsigned int _min){ this->minNbMatching = _min;}
259 
260 
267  unsigned int getMinNbPointValidation() const { return this->minNbMatching;}
268 
269 protected:
270 
271  virtual void init();
272  void computeRoi(vpImagePoint* ip, const unsigned int nbpt);
273  void initialiseRefCorners(const cv::Rect& _modelROI);
274 };
275 
276 #endif
277 
278 #endif /* VPPLANAROBJECTDETECTOR_H_ */
279 
280 
281 
282 
283 
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)
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:179
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:88
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...