52 #include <visp/vpDebug.h>
53 #include <visp/vpHomography.h>
54 #include <visp/vpMatrix.h>
55 #include <visp/vpRobust.h>
58 #include <visp/vpException.h>
59 #include <visp/vpMatrixException.h>
66 data =
new double [9];
77 data =
new double [9];
87 data =
new double [9];
93 const vpPlane &p) : data(NULL), aMb(), bP()
95 data =
new double [9];
101 const vpPlane &p) : data(NULL), aMb(), bP()
103 data =
new double [9];
109 data =
new double [9];
154 aMb.
buildFrom(arb[0],arb[1],arb[2],arb[3],arb[4],arb[5]) ;
211 vpHomography::insert(
const vpPlane &p)
230 for(
unsigned int i=0; i<3; i++)
231 for(
unsigned int j=0; j<3; j++)
232 H[i][j] = Minv[i][j];
278 for(
unsigned int i = 0; i < 3; i++) {
279 for(
unsigned int j = 0; j < 3; j++) {
281 for(
unsigned int k = 0; k < 3; k ++) {
282 s += (*this)[i][k] * H[k][j];
302 for(
unsigned int i=0; i<3; i++) {
304 for(
unsigned int j=0; j<3; j++)
305 a[i] += (*
this)[i][j] * b[j];
329 for (
unsigned int i=0; i < 9; i ++) {
352 if (std::fabs(v) <= std::numeric_limits<double>::epsilon())
357 for (
unsigned int i=0; i < 9; i ++) {
368 if (std::fabs(v) <= std::numeric_limits<double>::epsilon())
373 for (
unsigned int i=0;i<9;i++)
388 for (
unsigned int i=0; i< 3; i++)
389 for (
unsigned int j=0; j< 3; j++)
390 (*
this)[i][j] = H[i][j];
406 for (
unsigned int i=0; i< 3; i++)
407 for (
unsigned int j=0; j< 3; j++)
408 (*
this)[i][j] = H[i][j];
424 for (
unsigned int i=0 ; i < 3 ; i++)
425 for (
unsigned int j=0 ; j < 3 ; j++)
437 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
442 std::cout <<*
this << std::endl ;
444 #endif // #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
454 vpHomography::build()
459 for (
unsigned int i=0 ; i < 3 ; i++)
462 for (
unsigned int j=0 ; j < 3 ; j++)
463 aRb[i][j] = aMb[i][j];
468 double d = bP.
getD() ;
473 for (
unsigned int i=0 ; i < 3 ; i++)
474 for (
unsigned int j=0 ; j < 3 ; j++)
475 (*
this)[i][j] = aHb[i][j];
494 for (
unsigned int i=0 ; i < 3 ; i++)
497 for (
unsigned int j=0 ; j < 3 ; j++)
498 aRb[i][j] = aMb[i][j];
503 double d = bP.
getD() ;
508 for (
unsigned int i=0 ; i < 3 ; i++)
509 for (
unsigned int j=0 ; j < 3 ; j++)
510 aHb[i][j] = aHb_[i][j];
519 for (
unsigned int i=0 ; i < 3 ; i++)
520 for (
unsigned int j=0 ; j < 3; j++)
522 (*this)[i][j] = 1.0 ;
539 double xa = iPa.
get_u();
540 double ya = iPa.
get_v();
542 double z = xa * H[2][0] + ya * H[2][1] + H[2][2];
543 double xb = (xa * H[0][0] + ya * H[0][1] + H[0][2]) / z;
544 double yb = (xa * H[1][0] + ya * H[1][1] + H[1][2]) / z;
561 double xa = Pa.
get_x();
562 double ya = Pa.
get_y();
563 double z = xa * bHa[2][0] + ya * bHa[2][1] + bHa[2][2];
564 double xb = (xa * bHa[0][0] + ya * bHa[0][1] + bHa[0][2]) / z;
565 double yb = (xa * bHa[1][0] + ya * bHa[1][1] + bHa[1][2]) / z;
604 const std::vector<double> &xa,
const std::vector<double> &ya,
606 std::vector<bool> &inliers,
608 double weights_threshold,
612 unsigned int n = (
unsigned int) xb.size();
613 if (yb.size() != n || xa.size() != n || ya.size() != n)
615 "Bad dimension for robust homography estimation"));
622 std::vector<double> xan, yan, xbn, ybn;
624 double xg1=0., yg1=0., coef1=0., xg2=0., yg2=0., coef2=0.;
629 vpHomography::HartleyNormalization(xb, yb, xbn, ybn, xg1, yg1, coef1);
630 vpHomography::HartleyNormalization(xa, ya, xan, yan, xg2, yg2, coef2);
639 unsigned int nbLinesA = 2;
643 vpMatrix W(nbLinesA*n, nbLinesA*n) ;
650 for (
unsigned int i=0; i < nbLinesA*n; i ++) {
655 for(
unsigned int i=0; i<n;i++) {
656 A[nbLinesA*i][0]=xbn[i];
657 A[nbLinesA*i][1]=ybn[i];
662 A[nbLinesA*i][6]=-xbn[i]*xan[i] ;
663 A[nbLinesA*i][7]=-ybn[i]*xan[i];
665 A[nbLinesA*i+1][0]=0 ;
666 A[nbLinesA*i+1][1]=0;
667 A[nbLinesA*i+1][2]=0;
668 A[nbLinesA*i+1][3]=xbn[i];
669 A[nbLinesA*i+1][4]=ybn[i];
670 A[nbLinesA*i+1][5]=1;
671 A[nbLinesA*i+1][6]=-xbn[i]*yan[i];
672 A[nbLinesA*i+1][7]=-ybn[i]*yan[i];
674 Y[nbLinesA*i] = xan[i];
675 Y[nbLinesA*i+1] = yan[i];
680 unsigned int iter = 0;
683 while (iter < niter) {
695 for (
unsigned int i=0; i < n*nbLinesA; i ++) {
699 for(
unsigned int i=0;i<8;i++)
704 aHbnorm /= aHbnorm[2][2] ;
710 unsigned int nbinliers = 0;
711 for(
unsigned int i=0; i< n; i++) {
712 if (w[i*2] < weights_threshold && w[i*2+1] < weights_threshold)
722 vpHomography::HartleyDenormalization(aHbn, aHb, xg1, yg1, coef1, xg2, yg2, coef2);
730 for (
unsigned int i=0 ; i < n ; i++) {
732 a[0] = xa[i] ; a[1] = ya[i] ; a[2] = 1 ;
733 b[0] = xb[i] ; b[1] = yb[i] ; b[2] = 1 ;
735 c = aHb*b ; c /= c[2] ;
736 residual += (a-c).sumSquare();
740 residual = sqrt(residual/nbinliers);
751 VISP_EXPORT std::ostream &operator <<(std::ostream &s,
const vpHomography &H)
753 std::ios_base::fmtflags original_flags = s.flags();
756 for (
unsigned int i=0;i<H.
getRows();i++) {
757 for (
unsigned int j=0;j<H.
getCols();j++){
765 s.flags(original_flags);
vpMatrix get_K_inverse() const
void buildFrom(const vpRotationMatrix &aRb, const vpTranslationVector &atb, const vpPlane &bP)
Construction from Translation and rotation and a plane.
Definition of the vpMatrix class.
vpHomography & operator=(const vpHomography &H)
vpHomography & operator/=(double v)
Divide all the element of the homography matrix by v : Hij = Hij / v.
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
static vpImagePoint project(const vpCameraParameters &cam, const vpHomography &bHa, const vpImagePoint &iPa)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
error that can be emited by ViSP classes.
void set_x(const double x)
Set the point x coordinate in the image plane.
double get_y() const
Get the point y coordinate in the image plane.
Class that defines what is a point.
The vpRotationMatrix considers the particular case of a rotation matrix.
unsigned int size() const
void insert(const vpRotationMatrix &R)
This class aims to compute the homography wrt.two images.
unsigned int getRows() const
Return the number of rows of the homography matrix.
vp_deprecated void print()
Print the matrix.
vpRowVector t() const
Transpose of a vector.
vpHomography()
initialize an homography as Identity
void load(std::ifstream &f)
Load an homography from a file.
Generic class defining intrinsic camera parameters.
void set_y(const double y)
Set the point y coordinate in the image plane.
unsigned int getCols() const
Return the number of columns of the homography matrix.
double get_x() const
Get the point x coordinate in the image plane.
vpColVector getNormal() const
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Construction from translation vector and rotation matrix.
vpHomography operator/(const double &v) const
void save(std::ofstream &f) const
Save an homography in a file.
static void robust(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, std::vector< bool > &inlier, double &residual, double weights_threshold=0.4, unsigned int niter=4, bool normalization=true)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
The pose is a complete representation of every rigid motion in the euclidian space.
unsigned int getCols() const
Return the number of columns of the matrix.
vpHomography inverse() const
invert the homography
Contains an M-Estimator and various influence function.
error that can be emited by the vpMatrix class and its derivates
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 ...
This class defines the container for a plane geometrical structure.
unsigned int getRows() const
Return the number of rows of the matrix.
vpHomography operator*(const vpHomography &H) const
void setIteration(const unsigned int iter)
Set iteration.
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.