50 #include <visp/vpPose.h>
51 #include <visp/vpDebug.h>
52 #include <visp/vpException.h>
53 #include <visp/vpPoseException.h>
54 #include <visp/vpMeterPixelConversion.h>
55 #include <visp/vpCameraParameters.h>
56 #include <visp/vpDisplay.h>
57 #include <visp/vpMath.h>
62 #define DEBUG_LEVEL1 0
70 std::cout <<
"begin vpPose::Init() " << std::endl ;
82 computeCovariance =
false;
84 ransacMaxTrials = 1000;
85 ransacThreshold = 0.0001;
86 ransacNbInlierConsensus = 4;
90 std::cout <<
"end vpPose::Init() " << std::endl ;
97 : npt(0), listP(), residual(0), lambda(0.25), vvsIterMax(200), c3d(),
98 computeCovariance(false), covarianceMatrix(),
99 ransacNbInlierConsensus(4), ransacMaxTrials(1000), ransacInliers(), ransacThreshold(0.0001),
100 distanceToPlaneForCoplanarityTest(0.001)
103 std::cout <<
"begin vpPose::vpPose() " << std::endl ;
109 std::cout <<
"end vpPose::vpPose() " << std::endl ;
120 std::cout <<
"begin vpPose::~vpPose() " << std::endl ;
126 std::cout <<
"end vpPose::~vpPose() " << std::endl ;
136 std::cout <<
"begin vpPose::ClearPoint() " << std::endl ;
143 std::cout <<
"end vpPose::ClearPoint() " << std::endl ;
159 std::cout <<
"begin vpPose::AddPoint(Dot) " << std::endl ;
162 listP.push_back(newP);
166 std::cout <<
"end vpPose::AddPoint(Dot) " << std::endl ;
192 coplanar_plane_type = 0;
197 "Not enough points ")) ;
200 if (
npt ==3)
return true ;
202 double x1=0,x2=0,x3=0,y1=0,y2=0,y3=0,z1=0,z2=0,z3=0 ;
204 std::list<vpPoint>::const_iterator it =
listP.begin();
209 bool degenerate =
true;
210 bool not_on_origin =
true;
211 std::list<vpPoint>::const_iterator it_tmp;
213 std::list<vpPoint>::const_iterator it_i, it_j, it_k;
214 for (it_i=
listP.begin(); it_i !=
listP.end(); ++it_i) {
215 if (degenerate ==
false) {
221 if ((std::fabs(P1.
get_oX()) <= std::numeric_limits<double>::epsilon())
222 && (std::fabs(P1.
get_oY()) <= std::numeric_limits<double>::epsilon())
223 && (std::fabs(P1.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
224 not_on_origin =
false;
227 not_on_origin =
true;
230 it_tmp = it_i; it_tmp ++;
231 for (it_j=it_tmp; it_j !=
listP.end(); ++it_j) {
232 if (degenerate ==
false) {
237 if ((std::fabs(P2.
get_oX()) <= std::numeric_limits<double>::epsilon())
238 && (std::fabs(P2.
get_oY()) <= std::numeric_limits<double>::epsilon())
239 && (std::fabs(P2.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
240 not_on_origin =
false;
243 not_on_origin =
true;
246 it_tmp = it_j; it_tmp ++;
247 for (it_k=it_tmp; it_k !=
listP.end(); ++it_k) {
249 if ((std::fabs(P3.
get_oX()) <= std::numeric_limits<double>::epsilon())
250 && (std::fabs(P3.
get_oY()) <= std::numeric_limits<double>::epsilon())
251 && (std::fabs(P3.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
252 not_on_origin =
false;
255 not_on_origin =
true;
271 a_b[0] = x1-x2; a_b[1] = y1-y2; a_b[2] = z1-z2;
272 b_c[0] = x2-x3; b_c[1] = y2-y3; b_c[2] = z2-z3;
275 if (cross_prod.
sumSquare() <= std::numeric_limits<double>::epsilon())
280 if (degenerate ==
false)
289 coplanar_plane_type = 4;
293 double a = y1*z2 - y1*z3 - y2*z1 + y2*z3 + y3*z1 - y3*z2 ;
294 double b = -x1*z2 + x1*z3 + x2*z1 - x2*z3 - x3*z1 + x3*z2 ;
295 double c = x1*y2 - x1*y3 - x2*y1 + x2*y3 + x3*y1 - x3*y2 ;
296 double d = -x1*y2*z3 + x1*y3*z2 +x2*y1*z3 - x2*y3*z1 - x3*y1*z2 + x3*y2*z1 ;
299 if (std::fabs(b) <= std::numeric_limits<double>::epsilon()
300 && std::fabs(c) <= std::numeric_limits<double>::epsilon() ) {
301 coplanar_plane_type = 1;
302 }
else if (std::fabs(a) <= std::numeric_limits<double>::epsilon()
303 && std::fabs(c) <= std::numeric_limits<double>::epsilon() ) {
304 coplanar_plane_type = 2;
305 }
else if (std::fabs(a) <= std::numeric_limits<double>::epsilon()
306 && std::fabs(b) <= std::numeric_limits<double>::epsilon() ) {
307 coplanar_plane_type = 3;
314 for(it=
listP.begin(); it !=
listP.end(); ++it)
346 double residual_ = 0 ;
348 for(std::list<vpPoint>::const_iterator it=
listP.begin(); it !=
listP.end(); ++it)
351 double x = P.
get_x() ;
352 double y = P.
get_y() ;
389 std::cout <<
"begin vpPose::ComputePose()" << std::endl ;
396 "No enough point ")) ;
408 vpERROR_TRACE(
"Dementhon method cannot be used in that case ") ;
412 "Not enough points ")) ;
416 int coplanar_plane_type = 0;
417 bool plan =
coplanar(coplanar_plane_type) ;
451 int coplanar_plane_type;
452 bool plan =
coplanar(coplanar_plane_type) ;
454 if (plan ==
true && coplanar_plane_type > 0)
457 if (coplanar_plane_type == 4)
459 vpERROR_TRACE(
"Lagrange method cannot be used in that case ") ;
462 "Points are collinear ")) ;
466 vpERROR_TRACE(
"Lagrange method cannot be used in that case ") ;
470 "Not enough points ")) ;
485 vpERROR_TRACE(
"Lagrange method cannot be used in that case ") ;
489 "Not enough points ")) ;
505 vpERROR_TRACE(
"Ransac method cannot be used in that case ") ;
509 "Not enough points ")) ;
564 std::cout <<
"end vpPose::ComputePose()" << std::endl ;
577 for(std::list<vpPoint>::const_iterator it=
listP.begin(); it !=
listP.end(); ++it)
581 std::cout <<
"3D oP " << P.
oP.
t() ;
582 std::cout <<
"3D cP " << P.
cP.
t() ;
583 std::cout <<
"2D " << P.
p.
t() ;
621 for(std::list<vpPoint>::const_iterator it=
listP.begin(); it !=
listP.end(); ++it)
644 for(std::list<vpPoint>::const_iterator it=
listP.begin(); it !=
listP.end(); ++it)
682 std::vector<double> rectx(4) ;
683 std::vector<double> recty(4) ;
692 std::vector<double> irectx(4) ;
693 std::vector<double> irecty(4) ;
694 irectx[0]=(p1.
get_x()) ;
695 irecty[0]=(p1.
get_y()) ;
696 irectx[1]=(p2.
get_x()) ;
697 irecty[1]=(p2.
get_y()) ;
698 irectx[2]=(p3.
get_x()) ;
699 irecty[2]=(p3.
get_y()) ;
700 irectx[3]=(p4.
get_x()) ;
701 irecty[3]=(p4.
get_y()) ;
709 for (
unsigned int i=0 ; i < 3 ; i++)
710 for(
unsigned int j=0 ; j < 3 ; j++)
711 H[i][j] = hom[i][j] ;
Definition of the vpMatrix class.
virtual ~vpPose()
destructor
double residual
compute the residual in meter
void poseLagrangePlan(vpHomogeneousMatrix &cMo, const int coplanar_plane_type=0)
compute the pose using Lagrange approach (planar object)
bool coplanar(int &coplanar_plane_type)
test the coplanarity of the points
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void poseLagrangeNonPlan(vpHomogeneousMatrix &cMo)
compute the pose using Lagrange approach (non planar object)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
void init()
basic initialisation (called by the constructors)
Class to define colors available for display functionnalities.
void displayModel(vpImage< unsigned char > &I, vpCameraParameters &cam, vpColor col=vpColor::none)
double get_oY() const
Get the point Y coordinate in the object frame.
void track(const vpHomogeneousMatrix &cMo)
double get_y() const
Get the point y coordinate in the image plane.
std::list< vpPoint > listP
array of point (use here class vpPoint)
void poseVirtualVS(vpHomogeneousMatrix &cMo)
compute the pose using virtual visual servoing approach
Class that defines what is a point.
bool poseRansac(vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
compute the pose using the Ransac approach
static void HLM(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, bool isplanar, vpHomography &aHb)
double lambda
parameters use for the virtual visual servoing approach
This class aims to compute the homography wrt.two images.
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
void setIdentity(const double &val=1.0)
static double poseFromRectangle(vpPoint &p1, vpPoint &p2, vpPoint &p3, vpPoint &p4, double lx, vpCameraParameters &cam, vpHomogeneousMatrix &cMo)
Carries out the camera pose the image of a rectangle and the intrinsec parameters, the length on x axis is known but the proprtion of the rectangle are unknown.
static double sqr(double x)
bool computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
compute the pose for a given method
vpRowVector t() const
Transpose of a vector.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
Class used for pose computation from N points (pose from point only).
Generic class defining intrinsic camera parameters.
double distanceToPlaneForCoplanarityTest
vpColVector getCol(const unsigned int j) const
double get_oZ() const
Get the point Z coordinate in the object frame.
void poseLowe(vpHomogeneousMatrix &cMo)
Compute the pose using the Lowe non linear approach it consider the minimization of a residual using ...
double get_x() const
Get the point x coordinate in the image plane.
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1)
unsigned int npt
number of point used in pose computation
double get_oX() const
Get the point X coordinate in the object frame.
void poseDementhonPlan(vpHomogeneousMatrix &cMo)
compute the pose using Dementhon approach (planar object)
Error that can be emited by the vpPose class and its derivates.
void poseDementhonNonPlan(vpHomogeneousMatrix &cMo)
compute the pose using Dementhon approach (non planar object)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void setDistanceToPlaneForCoplanarityTest(double d)
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
Compute the cross product of two vectors C = a x b.
void addPoint(const vpPoint &P)
Add a new point in this array.
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the residual expressed in meter for the pose matrix 'cMo'.
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
void clearPoint()
suppress all the point in the array of point