45 #include <visp/vpPose.h>
46 #include <visp/vpMath.h>
48 #define DEBUG_LEVEL1 0
49 #define DEBUG_LEVEL2 0
50 #define DEBUG_LEVEL3 0
68 double normI = 0., normJ = 0.;
77 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it)
88 for (
unsigned int i=0 ; i <
npt ; i++)
90 a[i][0]=c3d[i].get_oX();
91 a[i][1]=c3d[i].get_oY();
92 a[i][2]=c3d[i].get_oZ();
109 std::cout <<
"a" << std::endl <<a<<std::endl ;
110 std::cout <<
"ata" << std::endl <<ata<<std::endl ;
111 std::cout <<
"ata1" << std::endl <<ata1<<std::endl ;
112 std::cout<<
" ata*ata1" << std::endl << ata*ata1 ;
113 std::cout<<
" b" << std::endl << (a*ata1).t() ;
136 for (
unsigned int i=0;i<
npt;i++)
138 xprim[i]=(1+ eps[i])*c3d[i].get_x() - c3d[0].get_x();
139 yprim[i]=(1+ eps[i])*c3d[i].get_y() - c3d[0].get_y();
148 if (normI+normJ < 1e-10)
152 "Division by zero in Dementhon pose computation: normI+normJ = 0")) ;
156 Z0=2*f/(normI+normJ);
157 cpt=cpt+1; seuil=0.0;
158 for (
unsigned int i=0; i<
npt; i++)
160 double epsi_1 = eps[i] ;
161 eps[i]=(c3d[i].get_oX()*k[0]+c3d[i].get_oY()*k[1]+c3d[i].get_oZ()*k[2])/Z0;
162 seuil+=fabs(eps[i]-epsi_1);
168 "Division by zero in Dementhon pose computation: no points")) ;
179 cMo[0][3]=c3d[0].get_x()*2/(normI+normJ);
184 cMo[1][3]=c3d[0].get_y()*2/(normI+normJ);
198 #define EPS 0.0000001
199 #define EPS_DEM 0.001
202 calculRTheta(
double s,
double c,
double &r,
double &theta)
204 if ((fabs(c) > EPS_DEM) || (fabs(s) > EPS_DEM))
206 r = sqrt(sqrt(s*s+c*c));
207 theta = atan2(s,c)/2.0;
211 if (fabs(c) > fabs(s))
231 void calculSolutionDementhon(
double xi0,
double yi0,
237 std::cout <<
"begin (Dementhon.cc)CalculSolutionDementhon() " << std::endl;
240 double normI, normJ, normk, Z0;
253 Z0=2.0/(normI+normJ);
255 normk = sqrt(k.sumSquare()) ;
278 std::cout <<
"end (Dementhon.cc)CalculSolutionDementhon() " << std::endl;
289 std::cout <<
"begin vpPose::CalculArbreDementhon() " << std::endl;
296 double smin,smin_old, s1,s2;
300 unsigned int iter_max = 20;
305 for(i = 0; i <
npt; i++)
308 z = cMo[2][0]*c3d[i].get_oX()+cMo[2][1]*c3d[i].get_oY()+cMo[2][2]*c3d[i].get_oZ() + cMo[2][3];
309 if (z <= 0.0) erreur = -1;
320 for(i = 0; i <
npt; i++)
322 xi[k] = c3d[i].get_x();
323 yi[k] = c3d[i].get_y();
327 eps[0][k] = (cMo[2][0]*c3d[i].get_oX() +
328 cMo[2][1]*c3d[i].get_oY() +
329 cMo[2][2]*c3d[i].get_oZ())/cMo[2][3];
343 while ((cpt<20) && (smin_old > 0.01) && (smin <= smin_old))
347 std::cout <<
"cpt " << cpt << std::endl ;
348 std::cout <<
"smin_old " << smin_old << std::endl ;
349 std::cout <<
"smin " << smin << std::endl ;
361 s = (1.0+eps[cpt][i])*xi[i] - xi[0];
362 I0[0] += b[0][i-1] * s;
363 I0[1] += b[1][i-1] * s;
364 I0[2] += b[2][i-1] * s;
365 s = (1.0+eps[cpt][i])*yi[i] - yi[0];
366 J0[0] += b[0][i-1] * s;
367 J0[1] += b[1][i-1] * s;
368 J0[2] += b[2][i-1] * s;
374 calculRTheta(s,c,r,theta);
384 std::cout <<
"I " << I.
t() ;
385 std::cout <<
"J " << J.
t() ;
389 calculSolutionDementhon(xi[0],yi[0],I,J,cMo1);
392 std::cout <<
"cMo1 "<< std::endl << cMo1 << std::endl ;
400 std::cout <<
"I " << I.
t() ;
401 std::cout <<
"J " << J.
t() ;
405 calculSolutionDementhon(xi[0],yi[0],I,J,cMo2);
408 std::cout <<
"cMo2 "<< std::endl << cMo2 << std::endl ;
416 for(i = 0; i <
npt; i++)
419 eps[cpt][k] = (cMo1[2][0]*c3d[i].get_oX() + cMo1[2][1]*c3d[i].get_oY()
420 + cMo1[2][2]*c3d[i].get_oZ())/cMo1[2][3];
430 for(i = 0; i <
npt; i++)
433 eps[cpt][k] = (cMo2[2][0]*c3d[i].get_oX() + cMo2[2][1]*c3d[i].get_oY()
434 + cMo2[2][2]*c3d[i].get_oZ())/cMo2[2][3];
444 std::cout <<
"Divergence " << std::endl ;
451 std::cout <<
"s1 = " << s1 << std::endl ;
452 std::cout <<
"s2 = " << s2 << std::endl ;
453 std::cout <<
"smin = " << smin << std::endl ;
454 std::cout <<
"smin_old = " << smin_old << std::endl ;
460 std::cout <<
"end vpPose::CalculArbreDementhon() return "<< erreur << std::endl;
478 std::cout <<
"begin CCalculPose::PoseDementhonPlan()" << std::endl ;
487 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it)
508 for (i=1 ; i <
npt ; i++)
510 a[i-1][0]=c3d[i].get_oX();
511 a[i-1][1]=c3d[i].get_oY();
512 a[i-1][2]=c3d[i].get_oZ();
533 std::cout <<
"a" << std::endl <<a<<std::endl ;
534 std::cout <<
"ata" << std::endl <<ata<<std::endl ;
543 unsigned int imin = 0;
549 unsigned int nc = sv.getRows() ;
550 for (i=0; i < nc ; i++)
551 if (sv[i] > s) s = sv[i];
556 if (sv[i] > s ) irank++;
559 for (i = 0; i < nc; i++)
560 if (sv[i] < svm) { imin = i; svm = sv[i]; }
564 std::cout <<
"rang: " << irank << std::endl ;;
565 std::cout <<
"imin = " << imin << std::endl ;
566 std::cout <<
"sv " << sv.t() << std::endl ;
570 for (i=0 ; i < ata.
getRows() ; i++)
571 for (j=0 ; j < ata.
getCols() ; j++)
574 for (k=0 ; k < nc ; k++)
576 ata1[i][j] += ((v[i][k]*ata[j][k])/sv[k]);
590 std::cout <<
"a" << std::endl <<a<<std::endl ;
591 std::cout <<
"ata" << std::endl <<ata_sav<<std::endl ;
592 std::cout <<
"ata1" << std::endl <<ata1<<std::endl ;
593 std::cout <<
"ata1*ata" << std::endl << ata1*ata_sav ;
594 std::cout <<
"b" << std::endl << b ;
595 std::cout <<
"U " << U.
t() << std::endl ;
602 for (i = 0; i <
npt; i++)
604 xi[i] = c3d[i].get_x() ;
605 yi[i] = c3d[i].get_y() ;
616 I0[0] += b[0][i-1] * (xi[i]-xi[0]);
617 I0[1] += b[1][i-1] * (xi[i]-xi[0]);
618 I0[2] += b[2][i-1] * (xi[i]-xi[0]);
620 J0[0] += b[0][i-1] * (yi[i]-yi[0]);
621 J0[1] += b[1][i-1] * (yi[i]-yi[0]);
622 J0[2] += b[2][i-1] * (yi[i]-yi[0]);
628 std::cout <<
"I0 "<<I0.
t() ;
629 std::cout <<
"J0 "<<J0.
t() ;
636 double r,theta,si,co ;
637 calculRTheta(s, c, r, theta);
646 calculSolutionDementhon(xi[0], yi[0], I, J, cMo1f);
656 calculSolutionDementhon(xi[0], yi[0], I, J, cMo2f);
660 if ((erreur1 == 0) && (erreur2 == -1)) cMo = cMo1f ;
661 if ((erreur1 == -1) && (erreur2 == 0)) cMo = cMo2f ;
662 if ((erreur1 == 0) && (erreur2 == 0))
667 if (s1<=s2) cMo = cMo1f ;
else cMo = cMo2f ;
675 std::cout <<
"end CCalculPose::PoseDementhonPlan()" << std::endl ;
694 double residual_ = 0 ;
697 for (
unsigned int i =0 ; i <
npt ; i++)
700 double X = c3d[i].get_oX()*cMo[0][0]+c3d[i].get_oY()*cMo[0][1]+c3d[i].get_oZ()*cMo[0][2] + cMo[0][3];
701 double Y = c3d[i].get_oX()*cMo[1][0]+c3d[i].get_oY()*cMo[1][1]+c3d[i].get_oZ()*cMo[1][2] + cMo[1][3];
702 double Z = c3d[i].get_oX()*cMo[2][0]+c3d[i].get_oY()*cMo[2][1]+c3d[i].get_oZ()*cMo[2][2] + cMo[2][3];
int calculArbreDementhon(vpMatrix &b, vpColVector &U, vpHomogeneousMatrix &cMo)
Definition of the vpMatrix class.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
static vpColVector cross(const vpColVector &a, const vpColVector &b)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
double get_oY() const
Get the point Y coordinate in the object frame.
error that can be emited by ViSP classes.
std::list< vpPoint > listP
array of point (use here class vpPoint)
void set_oX(const double X)
Set the point X coordinate in the object frame.
Class that defines what is a point.
void set_oZ(const double Z)
Set the point Z coordinate in the object frame.
void svd(vpColVector &w, vpMatrix &v)
static double sqr(double x)
vpRowVector t() const
Transpose of a vector.
vpColVector getCol(const unsigned int j) const
double get_oZ() const
Get the point Z coordinate in the object frame.
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)
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...
unsigned int getCols() const
Return the number of columns of the matrix.
static double dotProd(const vpColVector &a, const vpColVector &b)
Dot Product.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
unsigned int getRows() const
Return the number of rows of the matrix.
vpColVector & normalize()
Normalise the vector.
double computeResidualDementhon(const vpHomogeneousMatrix &cMo)
Compute and return the residual expressed in meter for the pose matrix 'pose'.
void set_oY(const double Y)
Set the point Y coordinate in the object frame.
void resize(const unsigned int i, const bool flagNullify=true)