ViSP  2.6.2
vpPose.h
1 /****************************************************************************
2  *
3  * $Id: vpPose.h 3809 2012-06-25 20:26:56Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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 
80 class VISP_EXPORT vpPose
81 {
82 public:
83  typedef enum
84  {
87  LOWE ,
93  LAGRANGE_VIRTUAL_VS
94  } vpPoseMethodType;
95 
96  unsigned int npt ;
97  std::list<vpPoint> listP ;
98 
99  double residual ;
100 
101 protected :
102  double lambda ;
103 
104 private:
105  int vvsIterMax ;
106  vpPoint *c3d ;
109  bool computeCovariance;
111  vpMatrix covarianceMatrix;
112 
113  int ransacNbInlierConsensus;
114  int ransacMaxTrials;
115  std::vector<vpPoint> ransacInliers;
116  double ransacThreshold;
117 
118 protected:
119  double computeResidualDementhon(vpHomogeneousMatrix &cMo) ;
120 
121  // method used in poseDementhonPlan()
122  int calculArbreDementhon(vpMatrix &b, vpColVector &U, vpHomogeneousMatrix &cMo) ;
123 
124 public:
126  vpPose() ;
128  virtual ~vpPose() ;
130  void addPoint(const vpPoint& P) ;
132  void clearPoint() ;
133 
135  void computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo) ;
138  double computeResidual(vpHomogeneousMatrix &cMo) ;
140  double computeResidual() ;
142  bool coplanar() ;
143  void displayModel(vpImage<unsigned char> &I,
144  vpCameraParameters &cam,
145  vpColor col=vpColor::none) ;
146  void displayModel(vpImage<vpRGBa> &I,
147  vpCameraParameters &cam,
148  vpColor col=vpColor::none) ;
150  void init() ;
152  void poseDementhonPlan(vpHomogeneousMatrix &cMo) ;
154  void poseDementhonNonPlan(vpHomogeneousMatrix &cMo) ;
156  void poseLagrangePlan(vpHomogeneousMatrix &cMo) ;
158  void poseLagrangeNonPlan(vpHomogeneousMatrix &cMo) ;
161  void poseLowe(vpHomogeneousMatrix & cMo) ;
163  void poseRansac(vpHomogeneousMatrix & cMo) ;
165  void poseVirtualVSrobust(vpHomogeneousMatrix & cMo) ;
167  void poseVirtualVS(vpHomogeneousMatrix & cMo) ;
168  void printPoint() ;
169  void setDistanceToPlaneForCoplanarityTest(double d) ;
170  void setLambda(double a) { lambda = a ; }
171  void setVvsIterMax(int nb) { vvsIterMax = nb ; }
172 
173  void setRansacNbInliersToReachConsensus(const int &nbC){ ransacNbInlierConsensus = nbC; }
174  void setRansacThreshold(const double &t){ ransacThreshold = t; }
175  void setRansacMaxTrials(const int &rM){ ransacMaxTrials = rM; }
176  int getRansacNbInliers(){ return ransacInliers.size(); }
177  std::vector<vpPoint> getRansacInliers(){ return ransacInliers; }
178 
184  void setCovarianceComputation(const bool& flag) { computeCovariance = flag; }
185 
194  if(!computeCovariance)
195  vpTRACE("Warning : The covariance matrix has not been computed. See setCovarianceComputation() to do it.");
196 
197  return covarianceMatrix;
198  }
199 
200  static void display(vpImage<unsigned char> &I, vpHomogeneousMatrix &cMo,
201  vpCameraParameters &cam, double size,
202  vpColor col=vpColor::none) ;
203  static void display(vpImage<vpRGBa> &I, vpHomogeneousMatrix &cMo,
204  vpCameraParameters &cam, double size,
205  vpColor col=vpColor::none) ;
206  static double poseFromRectangle(vpPoint &p1,vpPoint &p2,
207  vpPoint &p3,vpPoint &p4,
208  double lx, vpCameraParameters & cam,
209  vpHomogeneousMatrix & cMo) ;
210 
211  static void findMatch(std::vector<vpPoint> &p2D,
212  std::vector<vpPoint> &p3D,
213  const int &numberOfInlierToReachAConsensus,
214  const double &threshold,
215  unsigned int &ninliers,
216  std::vector<vpPoint> &listInliers,
217  vpHomogeneousMatrix &cMo,
218  const int &maxNbTrials = 10000);
219 
220 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
221 private:
225  static void initRansac(const unsigned int n,
226  const double *x, const double *y,
227  const unsigned int m,
228  const double *X, const double *Y, const double *Z,
229  vpColVector &data) ;
230 
231 public:
232  static void computeTransformation(vpColVector &x, unsigned int *ind, vpColVector &M) ;
233 
234  static double computeResidual(vpColVector &x, vpColVector &M, vpColVector &d) ;
235 
236  static bool degenerateConfiguration(vpColVector &x, unsigned int *ind) ;
237 
238  static void ransac(const unsigned int n,
239  const double *x, const double *y,
240  const unsigned int m,
241  const double *X, const double *Y, const double *Z,
242  const int numberOfInlierToReachAConsensus,
243  const double threshold,
244  unsigned int &ninliers,
245  vpColVector &xi, vpColVector &yi,
246  vpColVector &Xi, vpColVector &Yi, vpColVector &Zi,
247  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
248 
249  vp_deprecated static void ransac(const unsigned int n,
250  const vpPoint *p,
251  const unsigned int m,
252  const vpPoint *P,
253  const int numberOfInlierToReachAConsensus,
254  const double threshold,
255  unsigned int &ninliers,
256  std::list<vpPoint> &Pi,
257  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
258 
259  vp_deprecated static void ransac(std::list<vpPoint> &p,
260  std::list<vpPoint> &P,
261  const int numberOfInlierToReachAConsensus,
262  const double threshold,
263  unsigned int &ninliers,
264  std::list<vpPoint> &lPi,
265  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
266 #endif
267 } ;
268 
269 
270 #endif
271 
272 
273 /*
274  * Local variables:
275  * c-basic-offset: 2
276  * End:
277  */
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
double residual
compute the residual in meter
Definition: vpPose.h:99
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpTRACE
Definition: vpDebug.h:401
Class to define colors available for display functionnalities.
Definition: vpColor.h:123
static const vpColor none
Definition: vpColor.h:177
void setRansacThreshold(const double &t)
Definition: vpPose.h:174
std::list< vpPoint > listP
array of point (use here class vpPoint)
Definition: vpPose.h:97
Class that defines what is a point.
Definition: vpPoint.h:65
double lambda
parameters use for the virtual visual servoing approach
Definition: vpPose.h:102
std::vector< vpPoint > getRansacInliers()
Definition: vpPose.h:177
int getRansacNbInliers()
Definition: vpPose.h:176
Class used for pose computation from N points (pose from point only).
Definition: vpPose.h:80
Generic class defining intrinsic camera parameters.
void setRansacNbInliersToReachConsensus(const int &nbC)
Definition: vpPose.h:173
double distanceToPlaneForCoplanarityTest
Definition: vpPose.h:149
vpMatrix getCovarianceMatrix() const
Definition: vpPose.h:193
void setVvsIterMax(int nb)
Definition: vpPose.h:171
unsigned int npt
number of point used in pose computation
Definition: vpPose.h:96
void setRansacMaxTrials(const int &rM)
Definition: vpPose.h:175
void setLambda(double a)
Definition: vpPose.h:170
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:83
void setCovarianceComputation(const bool &flag)
Definition: vpPose.h:184