ViSP  2.7.0
vpPose.h
1 /****************************************************************************
2  *
3  * $Id: vpPose.h 4056 2013-01-05 13:04:42Z 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  * 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  unsigned int ransacNbInlierConsensus;
114  int ransacMaxTrials;
115  std::vector<vpPoint> ransacInliers;
116  double ransacThreshold;
117 
118 protected:
119  double computeResidualDementhon(const 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(const vpHomogeneousMatrix &cMo) const ;
140  bool coplanar(int &coplanar_plane_type) ;
141  void displayModel(vpImage<unsigned char> &I,
142  vpCameraParameters &cam,
143  vpColor col=vpColor::none) ;
144  void displayModel(vpImage<vpRGBa> &I,
145  vpCameraParameters &cam,
146  vpColor col=vpColor::none) ;
148  void init() ;
150  void poseDementhonPlan(vpHomogeneousMatrix &cMo) ;
152  void poseDementhonNonPlan(vpHomogeneousMatrix &cMo) ;
154  void poseLagrangePlan(vpHomogeneousMatrix &cMo, const int coplanar_plane_type=0) ;
156  void poseLagrangeNonPlan(vpHomogeneousMatrix &cMo) ;
159  void poseLowe(vpHomogeneousMatrix & cMo) ;
161  void poseRansac(vpHomogeneousMatrix & cMo) ;
163  void poseVirtualVSrobust(vpHomogeneousMatrix & cMo) ;
165  void poseVirtualVS(vpHomogeneousMatrix & cMo) ;
166  void printPoint() ;
167  void setDistanceToPlaneForCoplanarityTest(double d) ;
168  void setLambda(double a) { lambda = a ; }
169  void setVvsIterMax(int nb) { vvsIterMax = nb ; }
170 
171  void setRansacNbInliersToReachConsensus(const unsigned int &nbC){ ransacNbInlierConsensus = nbC; }
172  void setRansacThreshold(const double &t){ ransacThreshold = t; }
173  void setRansacMaxTrials(const int &rM){ ransacMaxTrials = rM; }
174  unsigned int getRansacNbInliers(){ return ransacInliers.size(); }
175  std::vector<vpPoint> getRansacInliers(){ return ransacInliers; }
176 
182  void setCovarianceComputation(const bool& flag) { computeCovariance = flag; }
183 
192  if(!computeCovariance)
193  vpTRACE("Warning : The covariance matrix has not been computed. See setCovarianceComputation() to do it.");
194 
195  return covarianceMatrix;
196  }
197 
198  static void display(vpImage<unsigned char> &I, vpHomogeneousMatrix &cMo,
199  vpCameraParameters &cam, double size,
200  vpColor col=vpColor::none) ;
201  static void display(vpImage<vpRGBa> &I, vpHomogeneousMatrix &cMo,
202  vpCameraParameters &cam, double size,
203  vpColor col=vpColor::none) ;
204  static double poseFromRectangle(vpPoint &p1,vpPoint &p2,
205  vpPoint &p3,vpPoint &p4,
206  double lx, vpCameraParameters & cam,
207  vpHomogeneousMatrix & cMo) ;
208 
209  static void findMatch(std::vector<vpPoint> &p2D,
210  std::vector<vpPoint> &p3D,
211  const unsigned int &numberOfInlierToReachAConsensus,
212  const double &threshold,
213  unsigned int &ninliers,
214  std::vector<vpPoint> &listInliers,
215  vpHomogeneousMatrix &cMo,
216  const int &maxNbTrials = 10000);
217 
218 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
219 private:
223  static void initRansac(const unsigned int n,
224  const double *x, const double *y,
225  const unsigned int m,
226  const double *X, const double *Y, const double *Z,
227  vpColVector &data) ;
228 
229 public:
230  static void computeTransformation(vpColVector &x, unsigned int *ind, vpColVector &M) ;
231 
232  static double computeResidual(const vpColVector &x, const vpColVector &M, vpColVector &d) ;
233 
234  static bool degenerateConfiguration(vpColVector &x, unsigned int *ind) ;
235 
236  static void ransac(const unsigned int n,
237  const double *x, const double *y,
238  const unsigned int m,
239  const double *X, const double *Y, const double *Z,
240  const int numberOfInlierToReachAConsensus,
241  const double threshold,
242  unsigned int &ninliers,
243  vpColVector &xi, vpColVector &yi,
244  vpColVector &Xi, vpColVector &Yi, vpColVector &Zi,
245  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
246 
247  vp_deprecated static void ransac(const unsigned int n,
248  const vpPoint *p,
249  const unsigned int m,
250  const vpPoint *P,
251  const int numberOfInlierToReachAConsensus,
252  const double threshold,
253  unsigned int &ninliers,
254  std::list<vpPoint> &Pi,
255  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
256 
257  vp_deprecated static void ransac(std::list<vpPoint> &p,
258  std::list<vpPoint> &P,
259  const int numberOfInlierToReachAConsensus,
260  const double threshold,
261  unsigned int &ninliers,
262  std::list<vpPoint> &lPi,
263  vpHomogeneousMatrix &cMo, const int maxNbTrials = 10000) ;
264 #endif
265 } ;
266 
267 
268 #endif
269 
270 
271 /*
272  * Local variables:
273  * c-basic-offset: 2
274  * End:
275  */
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:172
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:175
Class used for pose computation from N points (pose from point only).
Definition: vpPose.h:80
Generic class defining intrinsic camera parameters.
double distanceToPlaneForCoplanarityTest
Definition: vpPose.h:147
vpMatrix getCovarianceMatrix() const
Definition: vpPose.h:191
void setVvsIterMax(int nb)
Definition: vpPose.h:169
unsigned int npt
number of point used in pose computation
Definition: vpPose.h:96
void setRansacMaxTrials(const int &rM)
Definition: vpPose.h:173
void setRansacNbInliersToReachConsensus(const unsigned int &nbC)
Definition: vpPose.h:171
void setLambda(double a)
Definition: vpPose.h:168
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
unsigned int getRansacNbInliers()
Definition: vpPose.h:174
vpPoseMethodType
Definition: vpPose.h:83
void setCovarianceComputation(const bool &flag)
Definition: vpPose.h:182