ViSP  2.8.0
vpMbtKltPolygon.h
1 /****************************************************************************
2  *
3  * $Id: vpMbtKltPolygon.h 4339 2013-07-23 15:24:42Z ayol $
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  * Description:
34  * Generic model polygon, containing points of interest.
35  *
36  * Authors:
37  * Romain Tallonneau
38  * Aurelien Yol
39  *
40  *****************************************************************************/
41 
42 #ifndef vpMbtKltPolygon_h
43 #define vpMbtKltPolygon_h
44 
45 #include <visp/vpConfig.h>
46 
47 #ifdef VISP_HAVE_OPENCV
48 
49 #include <visp/vpMbtPolygon.h>
50 #include <visp/vpKltOpencv.h>
51 #include <visp/vpPlane.h>
52 #include <visp/vpDisplay.h>
53 #include <visp/vpGEMM.h>
54 #include <visp/vpHomography.h>
55 #include <visp/vpPlot.h>
56 
66 class VISP_EXPORT vpMbtKltPolygon: public vpMbtPolygon
67 {
68 private:
70  vpMatrix H;
72  vpColVector N;
74  vpColVector N_cur;
76  double invd0;
78  vpColVector cRc0_0n;
80  std::map<int, vpImagePoint> initPoints;
82  std::map<int, vpImagePoint> curPoints;
84  std::map<int, int> curPointsInd;
86  unsigned int nbPointsCur;
88  unsigned int nbPointsInit;
90  unsigned int minNbPoint;
92  bool enoughPoints;
94  double dt;
96  double d0;
99 
100 private:
101 
102  double compute_1_over_Z(const double x, const double y);
103  void computeP_mu_t(const double x_in, const double y_in, double& x_out, double& y_out, const vpMatrix& cHc0);
104  bool isTrackedFeature(const int id);
105 
106 public:
107  vpMbtKltPolygon();
108  virtual ~vpMbtKltPolygon();
109 
110  unsigned int computeNbDetectedCurrent(const vpKltOpencv& _tracker);
111  void computeHomography(const vpHomogeneousMatrix& _cTc0, vpHomography& cHc0);
112  void computeInteractionMatrixAndResidu(vpColVector& _R, vpMatrix& _J);
113 
114  void displayPrimitive(const vpImage<unsigned char>& _I);
115  void displayPrimitive(const vpImage<vpRGBa>& _I);
116 
122  inline vpCameraParameters& getCameraParameters(){ return cam; }
123 
124  inline vpColVector getCurrentNormal() const {return N_cur; }
125 
126  inline std::map<int, vpImagePoint>& getCurrentPoints() {return curPoints; }
127 
128  inline std::map<int, int>& getCurrentPointsInd() {return curPointsInd; }
129 
135  inline unsigned int getInitialNumberPoint() const { return nbPointsInit;}
136 
145  inline unsigned int getNbPointsCur() const {return nbPointsCur;}
146 
147  inline bool hasEnoughPoints() const {return enoughPoints;}
148 
149  void init(const vpKltOpencv& _tracker);
150 
151  void removeOutliers(const vpColVector& weight, const double &threshold_outlier);
152 
158  virtual inline void setCameraParameters(const vpCameraParameters& _cam){ cam = _cam; }
159 
160  void updateMask(IplImage* _mask, unsigned int _nb = 255, unsigned int _shiftBorder = 0);
161 
162 //###################
163 // Static Functions
164 //###################
165 private:
166  static bool isInside(const std::vector<vpImagePoint>& roi, const double i, const double j);
167  static bool intersect(const vpImagePoint& p1, const vpImagePoint& p2, const double i, const double j, const double i_test, const double j_test);
168 };
169 
170 #endif
171 
172 #endif // VISP_HAVE_OPENCV
Implementation of a polygon of the model containing points of interest. It is used by the model-based...
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
unsigned int getInitialNumberPoint() const
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
unsigned int getNbPointsCur() const
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:173
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:67
Generic class defining intrinsic camera parameters.
vpColVector getCurrentNormal() const
virtual void setCameraParameters(const vpCameraParameters &_cam)
vpCameraParameters & getCameraParameters()
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
Definition: vpKltOpencv.h:103
std::map< int, int > & getCurrentPointsInd()
std::map< int, vpImagePoint > & getCurrentPoints()
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
bool hasEnoughPoints() const