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.;
75 if (c3d !=NULL)
delete [] c3d ;
82 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it)
102 for (
unsigned int i=0 ; i <
npt ; i++)
123 std::cout <<
"a" << std::endl <<a<<std::endl ;
124 std::cout <<
"ata" << std::endl <<ata<<std::endl ;
125 std::cout <<
"ata1" << std::endl <<ata1<<std::endl ;
126 std::cout<<
" ata*ata1" << std::endl << ata*ata1 ;
127 std::cout<<
" b" << std::endl << (a*ata1).t() ;
172 for (
unsigned int i=0;i<
npt;i++)
174 xprim[i]=(1+ eps[i])*c3d[i].get_x() - c3d[0].
get_x();
175 yprim[i]=(1+ eps[i])*c3d[i].get_y() - c3d[0].
get_y();
184 if (normI+normJ < 1e-10)
188 "division by zero ")) ;
192 Z0=2*f/(normI+normJ);
193 cpt=cpt+1; seuil=0.0;
194 for (
unsigned int i=0; i<
npt; i++)
196 double epsi_1 = eps[i] ;
198 seuil+=fabs(eps[i]-epsi_1);
204 "division by zero ")) ;
215 cMo[0][3]=c3d[0].
get_x()*2/(normI+normJ);
220 cMo[1][3]=c3d[0].
get_y()*2/(normI+normJ);
231 delete [] c3d ; c3d = NULL ;
236 #define EPS 0.0000001
237 #define EPS_DEM 0.001
240 calculRTheta(
double s,
double c,
double &r,
double &theta)
242 if ((fabs(c) > EPS_DEM) || (fabs(s) > EPS_DEM))
244 r = sqrt(sqrt(s*s+c*c));
245 theta = atan2(s,c)/2.0;
249 if (fabs(c) > fabs(s))
269 void calculSolutionDementhon(
double xi0,
double yi0,
275 std::cout <<
"begin (Dementhon.cc)CalculSolutionDementhon() " << std::endl;
278 double normI, normJ, normk, Z0;
291 Z0=2.0/(normI+normJ);
293 normk = sqrt(k.sumSquare()) ;
316 std::cout <<
"end (Dementhon.cc)CalculSolutionDementhon() " << std::endl;
327 std::cout <<
"begin vpPose::CalculArbreDementhon() " << std::endl;
334 double smin,smin_old, s1,s2;
338 unsigned int iter_max = 20;
343 for(i = 0; i <
npt; i++)
346 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];
347 if (z <= 0.0) erreur = -1;
358 for(i = 0; i <
npt; i++)
360 xi[k] = c3d[i].
get_x();
361 yi[k] = c3d[i].
get_y();
365 eps[0][k] = (cMo[2][0]*c3d[i].
get_oX() +
366 cMo[2][1]*c3d[i].
get_oY() +
367 cMo[2][2]*c3d[i].
get_oZ())/cMo[2][3];
382 while ((cpt<20) && (smin_old > 0.01) && (smin <= smin_old))
386 std::cout <<
"cpt " << cpt << std::endl ;
387 std::cout <<
"smin_old " << smin_old << std::endl ;
388 std::cout <<
"smin " << smin << std::endl ;
400 s = (1.0+eps[cpt][i])*xi[i] - xi[0];
401 I0[0] += b[0][i-1] * s;
402 I0[1] += b[1][i-1] * s;
403 I0[2] += b[2][i-1] * s;
404 s = (1.0+eps[cpt][i])*yi[i] - yi[0];
405 J0[0] += b[0][i-1] * s;
406 J0[1] += b[1][i-1] * s;
407 J0[2] += b[2][i-1] * s;
413 calculRTheta(s,c,r,theta);
423 std::cout <<
"I " << I.
t() ;
424 std::cout <<
"J " << J.
t() ;
428 calculSolutionDementhon(xi[0],yi[0],I,J,cMo1);
431 std::cout <<
"cMo1 "<< std::endl << cMo1 << std::endl ;
439 std::cout <<
"I " << I.
t() ;
440 std::cout <<
"J " << J.
t() ;
444 calculSolutionDementhon(xi[0],yi[0],I,J,cMo2);
447 std::cout <<
"cMo2 "<< std::endl << cMo2 << std::endl ;
455 for(i = 0; i <
npt; i++)
458 eps[cpt][k] = (cMo1[2][0]*c3d[i].
get_oX() + cMo1[2][1]*c3d[i].
get_oY()
459 + cMo1[2][2]*c3d[i].
get_oZ())/cMo1[2][3];
469 for(i = 0; i <
npt; i++)
472 eps[cpt][k] = (cMo2[2][0]*c3d[i].
get_oX() + cMo2[2][1]*c3d[i].
get_oY()
473 + cMo2[2][2]*c3d[i].
get_oZ())/cMo2[2][3];
483 std::cout <<
"Divergence " << std::endl ;
490 std::cout <<
"s1 = " << s1 << std::endl ;
491 std::cout <<
"s2 = " << s2 << std::endl ;
492 std::cout <<
"smin = " << smin << std::endl ;
493 std::cout <<
"smin_old = " << smin_old << std::endl ;
499 std::cout <<
"end vpPose::CalculArbreDementhon() return "<< erreur << std::endl;
517 std::cout <<
"begin CCalculPose::PoseDementhonPlan()" << std::endl ;
522 if (c3d !=NULL)
delete []c3d ;
529 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it)
551 for (i=1 ; i <
npt ; i++)
553 a[i-1][0]=c3d[i].
get_oX();
554 a[i-1][1]=c3d[i].
get_oY();
555 a[i-1][2]=c3d[i].
get_oZ();
576 std::cout <<
"a" << std::endl <<a<<std::endl ;
577 std::cout <<
"ata" << std::endl <<ata<<std::endl ;
586 unsigned int imin = 0;
592 unsigned int nc = sv.getRows() ;
593 for (i=0; i < nc ; i++)
594 if (sv[i] > s) s = sv[i];
599 if (sv[i] > s ) irank++;
602 for (i = 0; i < nc; i++)
603 if (sv[i] < svm) { imin = i; svm = sv[i]; }
607 std::cout <<
"rang: " << irank << std::endl ;;
608 std::cout <<
"imin = " << imin << std::endl ;
609 std::cout <<
"sv " << sv.t() << std::endl ;
613 for (i=0 ; i < ata.
getRows() ; i++)
614 for (j=0 ; j < ata.
getCols() ; j++)
617 for (k=0 ; k < nc ; k++)
619 ata1[i][j] += ((v[i][k]*ata[j][k])/sv[k]);
633 std::cout <<
"a" << std::endl <<a<<std::endl ;
634 std::cout <<
"ata" << std::endl <<ata_sav<<std::endl ;
635 std::cout <<
"ata1" << std::endl <<ata1<<std::endl ;
636 std::cout <<
"ata1*ata" << std::endl << ata1*ata_sav ;
637 std::cout <<
"b" << std::endl << b ;
638 std::cout <<
"U " << U.
t() << std::endl ;
645 for (i = 0; i <
npt; i++)
647 xi[i] = c3d[i].
get_x() ;
648 yi[i] = c3d[i].
get_y() ;
659 I0[0] += b[0][i-1] * (xi[i]-xi[0]);
660 I0[1] += b[1][i-1] * (xi[i]-xi[0]);
661 I0[2] += b[2][i-1] * (xi[i]-xi[0]);
663 J0[0] += b[0][i-1] * (yi[i]-yi[0]);
664 J0[1] += b[1][i-1] * (yi[i]-yi[0]);
665 J0[2] += b[2][i-1] * (yi[i]-yi[0]);
671 std::cout <<
"I0 "<<I0.
t() ;
672 std::cout <<
"J0 "<<J0.
t() ;
679 double r,theta,si,co ;
680 calculRTheta(s, c, r, theta);
689 calculSolutionDementhon(xi[0], yi[0], I, J, cMo1f);
699 calculSolutionDementhon(xi[0], yi[0], I, J, cMo2f);
703 if ((erreur1 == 0) && (erreur2 == -1)) cMo = cMo1f ;
704 if ((erreur1 == -1) && (erreur2 == 0)) cMo = cMo2f ;
705 if ((erreur1 == 0) && (erreur2 == 0))
710 if (s1<=s2) cMo = cMo1f ;
else cMo = cMo2f ;
717 delete [] c3d ; c3d = NULL ;
719 std::cout <<
"end CCalculPose::PoseDementhonPlan()" << std::endl ;
743 for (i =0 ; i <
npt ; i++)
746 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];
747 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];
748 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.
double residual
compute the residual in meter
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.
double get_y() const
Get the point y coordinate in the image plane.
double sumSquare() const
return sum of the Aij^2 (for all i, for all j)
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.
vpColVector column(const unsigned int j)
Column extraction.
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 Vector
double get_oZ() const
Get the point Z coordinate in the object frame.
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.
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)