44 #include <visp/vpRobust.h>
45 #include <visp/vpHomogeneousMatrix.h>
46 #include <visp/vpHomography.h>
47 #include <visp/vpMath.h>
48 #include <visp/vpMatrix.h>
49 #include <visp/vpPoint.h>
50 #include <visp/vpPlane.h>
52 #include <visp/vpExponentialMap.h>
55 const double vpHomography::threshold_rotation = 1e-7;
56 const double vpHomography::threshold_displacement = 1e-18;
63 double sinu,cosi,mcosi,u[3], s;
67 s = sqrt(dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2]);
71 for (i=0;i<3;i++) u[i] = dx[i]/s;
75 rd[0][0] = cosi + mcosi*u[0]*u[0];
76 rd[0][1] = -sinu*u[2] + mcosi*u[0]*u[1];
77 rd[0][2] = sinu*u[1] + mcosi*u[0]*u[2];
78 rd[1][0] = sinu*u[2] + mcosi*u[1]*u[0];
79 rd[1][1] = cosi + mcosi*u[1]*u[1];
80 rd[1][2] = -sinu*u[0] + mcosi*u[1]*u[2];
81 rd[2][0] = -sinu*u[1] + mcosi*u[2]*u[0];
82 rd[2][1] = sinu*u[0] + mcosi*u[2]*u[1];
83 rd[2][2] = cosi + mcosi*u[2]*u[2];
89 for (j=0;j<3;j++) rd[i][j] = 0.0;
127 for (
unsigned int i=0 ; i < nbpoint ; i++) {
129 if ( (std::fabs(c2P[i].get_x() + 1) > std::fabs(
vpMath::maximum(c2P[i].get_x(), 1.)))
131 (std::fabs(c1P[i].get_x() + 1) > std::fabs(
vpMath::maximum(c1P[i].get_x(), 1.))) )
136 if ((only_1==1) || (only_2==1)) ;
else n *=2 ;
154 for (
unsigned int i=0 ; i < 3 ; i++)
155 for (
unsigned int j=0 ; j < 3 ; j++)
156 c2Rc1[i][j] = c2Mc1[i][j] ;
160 for (
unsigned int i=0 ; i < nbpoint ; i++) {
162 if ( (std::fabs(c2P[i].get_x() + 1) > std::fabs(
vpMath::maximum(c2P[i].get_x(), 1.)))
164 (std::fabs(c1P[i].get_x() + 1) > std::fabs(
vpMath::maximum(c1P[i].get_x(), 1.))) )
166 p2[0] = c2P[i].
get_x() ;
167 p2[1] = c2P[i].
get_y() ;
169 p1[0] = c1P[i].
get_x() ;
170 p1[1] = c1P[i].
get_y() ;
184 H2[0][0] = x*y ; H2[0][1] = -(1+x*x) ; H2[0][2] = y ;
185 H2[1][0] = 1+y*y ; H2[1][1] = -x*y ; H2[1][2] = -x ;
190 e2[0] = Hp2[0] - c1P[i].
get_x() ;
191 e2[1] = Hp2[1] - c1P[i].
get_y() ;
197 H1[0][0] = x*y ; H1[0][1] = -(1+x*x) ; H1[0][2] = y ;
198 H1[1][0] = 1+y*y ; H1[1][1] = -x*y ; H1[1][2] = -x ;
201 e1[0] = Hp1[0] - c2P[i].
get_x() ;
202 e1[1] = Hp1[1] - c2P[i].
get_y() ;
206 if (k == 0) { L = H2 ; e = e2 ; }
216 if (k == 0) { L = H1 ; e= e1 ; }
225 if (k == 0) {L = H2 ; e = e2 ; }
243 for (
unsigned int k=0 ; k < n ; k++)
251 for (
unsigned int k=0 ; k < n ; k++)
254 W[2*k+1][2*k+1] = w[k] ;
259 for (
unsigned int k=0 ; k < 2*n ; k++) W[k][k] = 1 ;
267 for (
unsigned int i=0 ; i < 3 ; i++) v[i+3] = c2Rc1[i] ;
271 updatePoseRotation(c2Rc1, c2Mc1) ;
281 return (W*e).sumSquare() ;
288 double A1 = cMo[0][0]*oN.
getA()+ cMo[0][1]*oN.
getB() + cMo[0][2]*oN.
getC();
289 double B1 = cMo[1][0]*oN.
getA()+ cMo[1][1]*oN.
getB() + cMo[1][2]*oN.
getC();
290 double C1 = cMo[2][0]*oN.
getA()+ cMo[2][1]*oN.
getB() + cMo[2][2]*oN.
getC();
291 double D1 = oN.
getD() - (cMo[0][3]*A1 + cMo[1][3]*B1 + cMo[2][3]*C1);
333 if ((only_1==1) || (only_2==1)) ;
else n *=2 ;
348 while (
vpMath::equal(r_1,r,threshold_displacement) ==
false )
367 getPlaneInfo(oN, c1Mo, N1, d1) ;
368 getPlaneInfo(oN, c2Mo, N2, d2) ;
373 for (i=0 ; i < nbpoint ; i++)
375 p2[0] = c2P[i].
get_x() ;
376 p2[1] = c2P[i].
get_y() ;
378 p1[0] = c1P[i].
get_x() ;
379 p1[1] = c1P[i].
get_y() ;
396 Z1 = (N1[0]*x+N1[1]*y+N1[2])/d1 ;
399 H2[0][0] = -Z1 ; H2[0][1] = 0 ; H2[0][2] = x*Z1 ;
400 H2[1][0] = 0 ; H2[1][1] = -Z1 ; H2[1][2] = y*Z1 ;
401 H2[0][3] = x*y ; H2[0][4] = -(1+x*x) ; H2[0][5] = y ;
402 H2[1][3] = 1+y*y ; H2[1][4] = -x*y ; H2[1][5] = -x ;
408 for (
unsigned int k=0 ; k < 3 ; k++)
409 for (
unsigned int l=0 ; l<3 ; l++)
411 c1CFc2[k][l] = c1Rc2[k][l] ;
412 c1CFc2[k+3][l+3] = c1Rc2[k][l] ;
413 c1CFc2[k][l+3] = sTR[k][l] ;
421 e2[0] = Hp2[0] - c1P[i].
get_x() ;
422 e2[1] = Hp2[1] - c1P[i].
get_y() ;
427 Z1 = (N2[0]*x+N2[1]*y+N2[2])/d2 ;
429 H1[0][0] = -Z1 ; H1[0][1] = 0 ; H1[0][2] = x*Z1 ;
430 H1[1][0] = 0 ; H1[1][1] = -Z1 ; H1[1][2] = y*Z1;
431 H1[0][3] = x*y ; H1[0][4] = -(1+x*x) ; H1[0][5] = y ;
432 H1[1][3] = 1+y*y ; H1[1][4] = -x*y ; H1[1][5] = -x ;
435 e1[0] = Hp1[0] - c2P[i].
get_x() ;
436 e1[1] = Hp1[1] - c2P[i].
get_y() ;
441 if (k == 0) { L = H2 ; e = e2 ; }
451 if (k == 0) { L = H1 ; e= e1 ; }
460 if (k == 0) {L = H2 ; e = e2 ; }
477 for (
unsigned int k=0 ; k < n ; k++)
485 for (
unsigned int k=0 ; k < n ; k++)
488 W[2*k+1][2*k+1] = w[k] ;
493 for (
unsigned int k=0 ; k < 2*n ; k++) W[k][k] = 1 ;
509 if (r < 1e-15) {break ; }
510 if (iter>1000){break ; }
511 if (r>r_1) { break ; }
515 return (W*e).sumSquare() ;
554 if ((only_1==1) || (only_2==1)) ;
else n *=2 ;
569 while (
vpMath::equal(r_1,r,threshold_displacement) ==
false )
592 for (i=0 ; i < nbpoint ; i++)
594 getPlaneInfo(oN[i], c1Mo, N1, d1) ;
595 getPlaneInfo(oN[i], c2Mo, N2, d2) ;
596 p2[0] = c2P[i].
get_x() ;
597 p2[1] = c2P[i].
get_y() ;
599 p1[0] = c1P[i].
get_x() ;
600 p1[1] = c1P[i].
get_y() ;
617 Z1 = (N1[0]*x+N1[1]*y+N1[2])/d1 ;
620 H2[0][0] = -Z1 ; H2[0][1] = 0 ; H2[0][2] = x*Z1 ;
621 H2[1][0] = 0 ; H2[1][1] = -Z1 ; H2[1][2] = y*Z1 ;
622 H2[0][3] = x*y ; H2[0][4] = -(1+x*x) ; H2[0][5] = y ;
623 H2[1][3] = 1+y*y ; H2[1][4] = -x*y ; H2[1][5] = -x ;
629 for (
unsigned int k=0 ; k < 3 ; k++)
630 for (
unsigned int l=0 ; l<3 ; l++)
632 c1CFc2[k][l] = c1Rc2[k][l] ;
633 c1CFc2[k+3][l+3] = c1Rc2[k][l] ;
634 c1CFc2[k][l+3] = sTR[k][l] ;
642 e2[0] = Hp2[0] - c1P[i].
get_x() ;
643 e2[1] = Hp2[1] - c1P[i].
get_y() ;
648 Z1 = (N2[0]*x+N2[1]*y+N2[2])/d2 ;
650 H1[0][0] = -Z1 ; H1[0][1] = 0 ; H1[0][2] = x*Z1 ;
651 H1[1][0] = 0 ; H1[1][1] = -Z1 ; H1[1][2] = y*Z1;
652 H1[0][3] = x*y ; H1[0][4] = -(1+x*x) ; H1[0][5] = y ;
653 H1[1][3] = 1+y*y ; H1[1][4] = -x*y ; H1[1][5] = -x ;
656 e1[0] = Hp1[0] - c2P[i].
get_x() ;
657 e1[1] = Hp1[1] - c2P[i].
get_y() ;
662 if (k == 0) { L = H2 ; e = e2 ; }
672 if (k == 0) { L = H1 ; e= e1 ; }
681 if (k == 0) {L = H2 ; e = e2 ; }
698 for (
unsigned int k=0 ; k < n ; k++)
706 for (
unsigned int k=0 ; k < n ; k++)
709 W[2*k+1][2*k+1] = w[k] ;
714 for (
unsigned int k=0 ; k < 2*n ; k++) W[k][k] = 1 ;
730 if (r < 1e-15) {break ; }
731 if (iter>1000){break ; }
732 if (r>r_1) { break ; }
736 return (W*e).sumSquare() ;
Definition of the vpMatrix class.
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
static bool equal(double x, double y, double s=0.001)
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)
vpMatrix()
Basic constructor.
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
Class that defines what is a point.
static Type maximum(const Type &a, const Type &b)
The vpRotationMatrix considers the particular case of a rotation matrix.
void insert(const vpRotationMatrix &R)
static double sqr(double x)
vpRowVector t() const
transpose of Vector
static double computeRotation(unsigned int nbpoint, vpPoint *c1P, vpPoint *c2P, vpHomogeneousMatrix &c2Mc1, int userobust)
void extract(vpRotationMatrix &R) const
double get_x() const
Get the point x coordinate in the image plane.
static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B)
Stack two Matrices C = [ A B ]^T.
Class that provides a data structure for the column vectors as well as a set of operations on these v...
vpHomogeneousMatrix inverse() const
static vpHomogeneousMatrix direct(const vpColVector &v)
Contains an M-Estimator and various influence function.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
This class defines the container for a plane geometrical structure.
void setThreshold(const double noise_threshold)
void setIteration(const unsigned int iter)
Set iteration.
Class that consider the case of a translation vector.
void resize(const unsigned int i, const bool flagNullify=true)