46 #include <visp3/vision/vpPose.h>
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpException.h>
49 #include <visp3/vision/vpPoseException.h>
50 #include <visp3/core/vpMeterPixelConversion.h>
51 #include <visp3/core/vpCameraParameters.h>
52 #include <visp3/core/vpDisplay.h>
53 #include <visp3/core/vpMath.h>
58 #define DEBUG_LEVEL1 0
66 std::cout <<
"begin vpPose::Init() " << std::endl ;
78 computeCovariance =
false;
80 ransacMaxTrials = 1000;
81 ransacThreshold = 0.0001;
82 ransacNbInlierConsensus = 4;
86 std::cout <<
"end vpPose::Init() " << std::endl ;
93 : npt(0), listP(), residual(0), lambda(0.25), vvsIterMax(200), c3d(),
94 computeCovariance(false), covarianceMatrix(),
95 ransacNbInlierConsensus(4), ransacMaxTrials(1000), ransacInliers(), ransacInlierIndex(), ransacThreshold(0.0001),
96 distanceToPlaneForCoplanarityTest(0.001)
99 std::cout <<
"begin vpPose::vpPose() " << std::endl ;
105 std::cout <<
"end vpPose::vpPose() " << std::endl ;
116 std::cout <<
"begin vpPose::~vpPose() " << std::endl ;
122 std::cout <<
"end vpPose::~vpPose() " << std::endl ;
132 std::cout <<
"begin vpPose::ClearPoint() " << std::endl ;
139 std::cout <<
"end vpPose::ClearPoint() " << std::endl ;
155 std::cout <<
"begin vpPose::AddPoint(Dot) " << std::endl ;
158 listP.push_back(newP);
162 std::cout <<
"end vpPose::AddPoint(Dot) " << std::endl ;
188 coplanar_plane_type = 0;
193 "Not enough points ")) ;
196 if (
npt ==3)
return true ;
198 double x1=0,x2=0,x3=0,y1=0,y2=0,y3=0,z1=0,z2=0,z3=0 ;
200 std::list<vpPoint>::const_iterator it =
listP.begin();
205 bool degenerate =
true;
206 bool not_on_origin =
true;
207 std::list<vpPoint>::const_iterator it_tmp;
209 std::list<vpPoint>::const_iterator it_i, it_j, it_k;
210 for (it_i=
listP.begin(); it_i !=
listP.end(); ++it_i) {
211 if (degenerate ==
false) {
217 if ((std::fabs(P1.
get_oX()) <= std::numeric_limits<double>::epsilon())
218 && (std::fabs(P1.
get_oY()) <= std::numeric_limits<double>::epsilon())
219 && (std::fabs(P1.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
220 not_on_origin =
false;
223 not_on_origin =
true;
226 it_tmp = it_i; it_tmp ++;
227 for (it_j=it_tmp; it_j !=
listP.end(); ++it_j) {
228 if (degenerate ==
false) {
233 if ((std::fabs(P2.
get_oX()) <= std::numeric_limits<double>::epsilon())
234 && (std::fabs(P2.
get_oY()) <= std::numeric_limits<double>::epsilon())
235 && (std::fabs(P2.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
236 not_on_origin =
false;
239 not_on_origin =
true;
242 it_tmp = it_j; it_tmp ++;
243 for (it_k=it_tmp; it_k !=
listP.end(); ++it_k) {
245 if ((std::fabs(P3.
get_oX()) <= std::numeric_limits<double>::epsilon())
246 && (std::fabs(P3.
get_oY()) <= std::numeric_limits<double>::epsilon())
247 && (std::fabs(P3.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
248 not_on_origin =
false;
251 not_on_origin =
true;
267 a_b[0] = x1-x2; a_b[1] = y1-y2; a_b[2] = z1-z2;
268 b_c[0] = x2-x3; b_c[1] = y2-y3; b_c[2] = z2-z3;
271 if (cross_prod.
sumSquare() <= std::numeric_limits<double>::epsilon())
276 if (degenerate ==
false)
285 coplanar_plane_type = 4;
289 double a = y1*z2 - y1*z3 - y2*z1 + y2*z3 + y3*z1 - y3*z2 ;
290 double b = -x1*z2 + x1*z3 + x2*z1 - x2*z3 - x3*z1 + x3*z2 ;
291 double c = x1*y2 - x1*y3 - x2*y1 + x2*y3 + x3*y1 - x3*y2 ;
292 double d = -x1*y2*z3 + x1*y3*z2 +x2*y1*z3 - x2*y3*z1 - x3*y1*z2 + x3*y2*z1 ;
295 if (std::fabs(b) <= std::numeric_limits<double>::epsilon()
296 && std::fabs(c) <= std::numeric_limits<double>::epsilon() ) {
297 coplanar_plane_type = 1;
298 }
else if (std::fabs(a) <= std::numeric_limits<double>::epsilon()
299 && std::fabs(c) <= std::numeric_limits<double>::epsilon() ) {
300 coplanar_plane_type = 2;
301 }
else if (std::fabs(a) <= std::numeric_limits<double>::epsilon()
302 && std::fabs(b) <= std::numeric_limits<double>::epsilon() ) {
303 coplanar_plane_type = 3;
310 for(it=
listP.begin(); it !=
listP.end(); ++it)
342 double residual_ = 0 ;
344 for(std::list<vpPoint>::const_iterator it=
listP.begin(); it !=
listP.end(); ++it)
347 double x = P.
get_x() ;
348 double y = P.
get_y() ;
385 std::cout <<
"begin vpPose::ComputePose()" << std::endl ;
392 "No enough point ")) ;
404 vpERROR_TRACE(
"Dementhon method cannot be used in that case ") ;
408 "Not enough points ")) ;
412 int coplanar_plane_type = 0;
413 bool plan =
coplanar(coplanar_plane_type) ;
447 int coplanar_plane_type;
448 bool plan =
coplanar(coplanar_plane_type) ;
450 if (plan ==
true && coplanar_plane_type > 0)
453 if (coplanar_plane_type == 4)
455 vpERROR_TRACE(
"Lagrange method cannot be used in that case ") ;
458 "Points are collinear ")) ;
462 vpERROR_TRACE(
"Lagrange method cannot be used in that case ") ;
466 "Not enough points ")) ;
481 vpERROR_TRACE(
"Lagrange method cannot be used in that case ") ;
485 "Not enough points ")) ;
501 vpERROR_TRACE(
"Ransac method cannot be used in that case ") ;
505 "Not enough points ")) ;
560 std::cout <<
"end vpPose::ComputePose()" << std::endl ;
573 for(std::list<vpPoint>::const_iterator it=
listP.begin(); it !=
listP.end(); ++it)
577 std::cout <<
"3D oP " << P.
oP.
t() ;
578 std::cout <<
"3D cP " << P.
cP.
t() ;
579 std::cout <<
"2D " << P.
p.
t() ;
617 for(std::list<vpPoint>::const_iterator it=
listP.begin(); it !=
listP.end(); ++it)
640 for(std::list<vpPoint>::const_iterator it=
listP.begin(); it !=
listP.end(); ++it)
678 std::vector<double> rectx(4) ;
679 std::vector<double> recty(4) ;
688 std::vector<double> irectx(4) ;
689 std::vector<double> irecty(4) ;
690 irectx[0]=(p1.
get_x()) ;
691 irecty[0]=(p1.
get_y()) ;
692 irectx[1]=(p2.
get_x()) ;
693 irecty[1]=(p2.
get_y()) ;
694 irectx[2]=(p3.
get_x()) ;
695 irecty[2]=(p3.
get_y()) ;
696 irectx[3]=(p4.
get_x()) ;
697 irecty[3]=(p4.
get_y()) ;
705 for (
unsigned int i=0 ; i < 3 ; i++)
706 for(
unsigned int j=0 ; j < 3 ; j++)
707 H[i][j] = hom[i][j] ;
Implementation of a matrix and operations on matrices.
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
Implementation of an homogeneous matrix and operations on such kind of matrices.
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
Implementation of an homography and operations on homographies.
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
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
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.
unsigned int npt
number of point used in pose computation
double get_oX() const
Get the point X coordinate in the object frame.
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, vpImagePoint offset=vpImagePoint(0, 0))
void setWorldCoordinates(const double oX, const double oY, const double oZ)
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)
Implementation of column vector and the associated operations.
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)
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 clearPoint()
suppress all the point in the array of point