ViSP  2.10.0
vpPose.h
1 /****************************************************************************
2  *
3  * $Id: vpPose.h 5211 2015-01-26 17:44:35Z strinh $
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  * Pose computation.
36  *
37  * Authors:
38  * Eric Marchand
39  * Francois Chaumette
40  * Aurelien Yol
41  *
42  *****************************************************************************/
43 
52 #ifndef vpPOSE_HH
53 #define vpPOSE_HH
54 
55 #include <visp/vpHomogeneousMatrix.h>
56 #include <visp/vpHomography.h>
57 #include <visp/vpPoint.h>
58 #include <visp/vpRGBa.h>
59 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
60 # include <visp/vpList.h>
61 #endif
62 
63 #include <math.h>
64 #include <list>
65 #include <vector>
66 
78 class VISP_EXPORT vpPose
79 {
80 public:
81  typedef enum
82  {
85  LOWE ,
91  LAGRANGE_VIRTUAL_VS
92  } vpPoseMethodType;
93 
94  unsigned int npt ;
95  std::list<vpPoint> listP ;
96 
97  double residual ;
98 
99 protected :
100  double lambda ;
101 
102 private:
103  int vvsIterMax ;
104  std::vector<vpPoint> c3d ;
107  bool computeCovariance;
109  vpMatrix covarianceMatrix;
110 
111  unsigned int ransacNbInlierConsensus;
112  int ransacMaxTrials;
113  std::vector<vpPoint> ransacInliers;
114  double ransacThreshold;
115 
116 protected:
117  double computeResidualDementhon(const vpHomogeneousMatrix &cMo) ;
118 
119  // method used in poseDementhonPlan()
120  int calculArbreDementhon(vpMatrix &b, vpColVector &U, vpHomogeneousMatrix &cMo) ;
121 
122 public:
123  // constructor
124  vpPose() ;
126  virtual ~vpPose() ;
128  void addPoint(const vpPoint& P) ;
130  void clearPoint() ;
131 
133  bool computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo, bool (*func)(vpHomogeneousMatrix *)=NULL) ;
136  double computeResidual(const vpHomogeneousMatrix &cMo) const ;
138  bool coplanar(int &coplanar_plane_type) ;
139  void displayModel(vpImage<unsigned char> &I,
140  vpCameraParameters &cam,
141  vpColor col=vpColor::none) ;
142  void displayModel(vpImage<vpRGBa> &I,
143  vpCameraParameters &cam,
144  vpColor col=vpColor::none) ;
146  void init() ;
148  void poseDementhonPlan(vpHomogeneousMatrix &cMo) ;
150  void poseDementhonNonPlan(vpHomogeneousMatrix &cMo) ;
152  void poseLagrangePlan(vpHomogeneousMatrix &cMo, const int coplanar_plane_type=0) ;
154  void poseLagrangeNonPlan(vpHomogeneousMatrix &cMo) ;
157  void poseLowe(vpHomogeneousMatrix & cMo) ;
159  bool poseRansac(vpHomogeneousMatrix & cMo, bool (*func)(vpHomogeneousMatrix *)=NULL) ;
161  void poseVirtualVSrobust(vpHomogeneousMatrix & cMo) ;
163  void poseVirtualVS(vpHomogeneousMatrix & cMo) ;
164  void printPoint() ;
165  void setDistanceToPlaneForCoplanarityTest(double d) ;
166  void setLambda(double a) { lambda = a ; }
167  void setVvsIterMax(int nb) { vvsIterMax = nb ; }
168 
169  void setRansacNbInliersToReachConsensus(const unsigned int &nbC){ ransacNbInlierConsensus = nbC; }
170  void setRansacThreshold(const double &t) {
171  //Test whether or not t is > 0
172  if(t > 0) {
173  ransacThreshold = t;
174  } else {
175  throw vpException(vpException::badValue, "The Ransac threshold must be positive as we deal with distance.");
176  }
177  }
178  void setRansacMaxTrials(const int &rM){ ransacMaxTrials = rM; }
179  unsigned int getRansacNbInliers() const { return (unsigned int) ransacInliers.size(); }
180  std::vector<vpPoint> getRansacInliers() const{ return ransacInliers; }
181 
187  void setCovarianceComputation(const bool& flag) { computeCovariance = flag; }
188 
197  if(!computeCovariance)
198  vpTRACE("Warning : The covariance matrix has not been computed. See setCovarianceComputation() to do it.");
199 
200  return covarianceMatrix;
201  }
202 
203  static void display(vpImage<unsigned char> &I, vpHomogeneousMatrix &cMo,
204  vpCameraParameters &cam, double size,
205  vpColor col=vpColor::none) ;
206  static void display(vpImage<vpRGBa> &I, vpHomogeneousMatrix &cMo,
207  vpCameraParameters &cam, double size,
208  vpColor col=vpColor::none) ;
209  static double poseFromRectangle(vpPoint &p1,vpPoint &p2,
210  vpPoint &p3,vpPoint &p4,
211  double lx, vpCameraParameters & cam,
212  vpHomogeneousMatrix & cMo) ;
213 
214  static void findMatch(std::vector<vpPoint> &p2D,
215  std::vector<vpPoint> &p3D,
216  const unsigned int &numberOfInlierToReachAConsensus,
217  const double &threshold,
218  unsigned int &ninliers,
219  std::vector<vpPoint> &listInliers,
220  vpHomogeneousMatrix &cMo,
221  const int &maxNbTrials = 10000);
222 
223 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
224 private:
228  static void initRansac(const unsigned int n,
229  const double *x, const double *y,
230  const unsigned int m,
231  const double *X, const double *Y, const double *Z,
232  vpColVector &data) ;
233 
234 public:
235  static void computeTransformation(vpColVector &x, unsigned int *ind, vpColVector &M) ;
236 
237  static double computeResidual(const vpColVector &x, const vpColVector &M, vpColVector &d) ;
238 
239  static bool degenerateConfiguration(vpColVector &x, unsigned int *ind) ;
240 
241  static void ransac(const unsigned int n,
242  const double *x, const double *y,
243  const unsigned int m,
244  const double *X, const double *Y, const double *Z,
245  const int numberOfInlierToReachAConsensus,
246  const double threshold,
247  unsigned int &ninliers,
248  vpColVector &xi, vpColVector &yi,
249  vpColVector &Xi, vpColVector &Yi, vpColVector &Zi,
250  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
251 
252  vp_deprecated static void ransac(const unsigned int n,
253  const vpPoint *p,
254  const unsigned int m,
255  const vpPoint *P,
256  const int numberOfInlierToReachAConsensus,
257  const double threshold,
258  unsigned int &ninliers,
259  std::list<vpPoint> &Pi,
260  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
261 
262  vp_deprecated static void ransac(std::list<vpPoint> &p,
263  std::list<vpPoint> &P,
264  const int numberOfInlierToReachAConsensus,
265  const double threshold,
266  unsigned int &ninliers,
267  std::list<vpPoint> &lPi,
268  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
269 #endif
270 } ;
271 
272 
273 #endif
274 
275 
276 /*
277  * Local variables:
278  * c-basic-offset: 2
279  * End:
280  */
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
double residual
compute the residual in meter
Definition: vpPose.h:97
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpTRACE
Definition: vpDebug.h:418
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
static const vpColor none
Definition: vpColor.h:179
error that can be emited by ViSP classes.
Definition: vpException.h:76
void setRansacThreshold(const double &t)
Definition: vpPose.h:170
std::list< vpPoint > listP
array of point (use here class vpPoint)
Definition: vpPose.h:95
Class that defines what is a point.
Definition: vpPoint.h:65
double lambda
parameters use for the virtual visual servoing approach
Definition: vpPose.h:100
unsigned int getRansacNbInliers() const
Definition: vpPose.h:179
Class used for pose computation from N points (pose from point only).
Definition: vpPose.h:78
Generic class defining intrinsic camera parameters.
double distanceToPlaneForCoplanarityTest
Definition: vpPose.h:145
vpMatrix getCovarianceMatrix() const
Definition: vpPose.h:196
void setVvsIterMax(int nb)
Definition: vpPose.h:167
unsigned int npt
number of point used in pose computation
Definition: vpPose.h:94
void setRansacMaxTrials(const int &rM)
Definition: vpPose.h:178
void setRansacNbInliersToReachConsensus(const unsigned int &nbC)
Definition: vpPose.h:169
void setLambda(double a)
Definition: vpPose.h:166
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
vpPoseMethodType
Definition: vpPose.h:81
std::vector< vpPoint > getRansacInliers() const
Definition: vpPose.h:180
void setCovarianceComputation(const bool &flag)
Definition: vpPose.h:187