48 #include <visp3/core/vpDebug.h>
49 #include <visp3/vision/vpHomography.h>
50 #include <visp3/core/vpMatrix.h>
51 #include <visp3/core/vpRobust.h>
54 #include <visp3/core/vpException.h>
55 #include <visp3/core/vpMatrixException.h>
142 aMb.
buildFrom(arb[0],arb[1],arb[2],arb[3],arb[4],arb[5]) ;
199 vpHomography::insert(
const vpPlane &p)
218 for(
unsigned int i=0; i<3; i++)
219 for(
unsigned int j=0; j<3; j++)
220 H[i][j] = Minv[i][j];
271 for(
unsigned int i = 0; i < 3; i++) {
272 for(
unsigned int j = 0; j < 3; j++) {
274 for(
unsigned int k = 0; k < 3; k ++) {
275 s += (*this)[i][k] * H[k][j];
295 for(
unsigned int i=0; i<3; i++) {
297 for(
unsigned int j=0; j<3; j++)
298 a[i] += (*
this)[i][j] * b[j];
322 for (
unsigned int i=0; i < 9; i ++) {
346 v1[0] = (*this)[0][0]*v[0] + (*this)[0][1]*v[1]+ (*this)[0][2]*v[2] ;
347 v1[1] = (*this)[1][0]*v[0] + (*this)[1][1]*v[1]+ (*this)[1][2]*v[2] ;
348 v1[2] = (*this)[2][0]*v[0] + (*this)[2][1]*v[1]+ (*this)[2][2]*v[2] ;
373 if (std::fabs(v) <= std::numeric_limits<double>::epsilon())
378 for (
unsigned int i=0; i < 9; i ++) {
389 if (std::fabs(v) <= std::numeric_limits<double>::epsilon())
394 for (
unsigned int i=0;i<9;i++)
409 for (
unsigned int i=0; i< 3; i++)
410 for (
unsigned int j=0; j< 3; j++)
411 (*
this)[i][j] = H[i][j];
427 for (
unsigned int i=0; i< 3; i++)
428 for (
unsigned int j=0; j< 3; j++)
429 (*
this)[i][j] = H[i][j];
447 for (
unsigned int i=0 ; i < 3 ; i++)
448 for (
unsigned int j=0 ; j < 3 ; j++)
467 vpHomography::build()
472 for (
unsigned int i=0 ; i < 3 ; i++)
475 for (
unsigned int j=0 ; j < 3 ; j++)
476 aRb[i][j] = aMb[i][j];
481 double d = bP.
getD() ;
486 for (
unsigned int i=0 ; i < 3 ; i++)
487 for (
unsigned int j=0 ; j < 3 ; j++)
488 (*
this)[i][j] = aHb[i][j];
507 for (
unsigned int i=0 ; i < 3 ; i++)
510 for (
unsigned int j=0 ; j < 3 ; j++)
511 aRb[i][j] = aMb[i][j];
516 double d = bP.
getD() ;
521 for (
unsigned int i=0 ; i < 3 ; i++)
522 for (
unsigned int j=0 ; j < 3 ; j++)
523 aHb[i][j] = aHb_[i][j];
533 for (
unsigned int i=0 ; i < 3 ; i++)
534 for (
unsigned int j=0 ; j < 3; j++)
536 (*this)[i][j] = 1.0 ;
541 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
553 #endif // #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
567 double xa = iPa.
get_u();
568 double ya = iPa.
get_v();
570 double z = xa * H[2][0] + ya * H[2][1] + H[2][2];
571 double xb = (xa * H[0][0] + ya * H[0][1] + H[0][2]) / z;
572 double yb = (xa * H[1][0] + ya * H[1][1] + H[1][2]) / z;
590 double xa = Pa.
get_x();
591 double ya = Pa.
get_y();
592 double z = xa * bHa[2][0] + ya * bHa[2][1] + bHa[2][2];
593 double xb = (xa * bHa[0][0] + ya * bHa[0][1] + bHa[0][2]) / z;
594 double yb = (xa * bHa[1][0] + ya * bHa[1][1] + bHa[1][2]) / z;
633 const std::vector<double> &xa,
const std::vector<double> &ya,
635 std::vector<bool> &inliers,
637 double weights_threshold,
641 unsigned int n = (
unsigned int) xb.size();
642 if (yb.size() != n || xa.size() != n || ya.size() != n)
644 "Bad dimension for robust homography estimation"));
651 std::vector<double> xan, yan, xbn, ybn;
653 double xg1=0., yg1=0., coef1=0., xg2=0., yg2=0., coef2=0.;
658 vpHomography::HartleyNormalization(xb, yb, xbn, ybn, xg1, yg1, coef1);
659 vpHomography::HartleyNormalization(xa, ya, xan, yan, xg2, yg2, coef2);
668 unsigned int nbLinesA = 2;
672 vpMatrix W(nbLinesA*n, nbLinesA*n) ;
679 for (
unsigned int i=0; i < nbLinesA*n; i ++) {
684 for(
unsigned int i=0; i<n;i++) {
685 A[nbLinesA*i][0]=xbn[i];
686 A[nbLinesA*i][1]=ybn[i];
691 A[nbLinesA*i][6]=-xbn[i]*xan[i] ;
692 A[nbLinesA*i][7]=-ybn[i]*xan[i];
694 A[nbLinesA*i+1][0]=0 ;
695 A[nbLinesA*i+1][1]=0;
696 A[nbLinesA*i+1][2]=0;
697 A[nbLinesA*i+1][3]=xbn[i];
698 A[nbLinesA*i+1][4]=ybn[i];
699 A[nbLinesA*i+1][5]=1;
700 A[nbLinesA*i+1][6]=-xbn[i]*yan[i];
701 A[nbLinesA*i+1][7]=-ybn[i]*yan[i];
703 Y[nbLinesA*i] = xan[i];
704 Y[nbLinesA*i+1] = yan[i];
709 unsigned int iter = 0;
712 while (iter < niter) {
724 for (
unsigned int i=0; i < n*nbLinesA; i ++) {
728 for(
unsigned int i=0;i<8;i++)
733 aHbnorm /= aHbnorm[2][2] ;
739 unsigned int nbinliers = 0;
740 for(
unsigned int i=0; i< n; i++) {
741 if (w[i*2] < weights_threshold && w[i*2+1] < weights_threshold)
751 vpHomography::HartleyDenormalization(aHbn, aHb, xg1, yg1, coef1, xg2, yg2, coef2);
759 for (
unsigned int i=0 ; i < n ; i++) {
761 a[0] = xa[i] ; a[1] = ya[i] ; a[2] = 1 ;
762 b[0] = xb[i] ; b[1] = yb[i] ; b[2] = 1 ;
764 c = aHb*b ; c /= c[2] ;
765 residual += (a-c).sumSquare();
769 residual = sqrt(residual/nbinliers);
788 double u = ipb.
get_u();
789 double v = ipb.
get_v();
791 double u_a = (*this)[0][0] * u + (*this)[0][1] * v + (*this)[0][2];
792 double v_a = (*this)[1][0] * u + (*this)[1][1] * v + (*this)[1][2];
793 double w_a = (*this)[2][0] * u + (*this)[2][1] * v + (*this)[2][2];
795 if(std::fabs(w_a) > std::numeric_limits<double>::epsilon()){
796 ipa.
set_u(u_a / w_a);
797 ipa.
set_v(v_a / w_a);
810 for(
unsigned int i=0; i<3; i++)
811 for(
unsigned int j=0; j<3; j++)
812 M[i][j] = (*
this)[i][j];
vpMatrix get_K_inverse() const
void buildFrom(const vpRotationMatrix &aRb, const vpTranslationVector &atb, const vpPlane &bP)
Construction from Translation and rotation and a plane.
Implementation of a matrix and operations on matrices.
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)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Implementation of an homogeneous matrix and operations on such kind of matrices.
error that can be emited by ViSP classes.
void set_x(const double x)
Set the point x coordinate in the image plane.
Type * data
Address of the first element of the data array.
Implementation of a generic 2D array used as vase class of matrices and vectors.
vpImagePoint projection(const vpImagePoint &p)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
Return the number of columns of the 2D array.
double get_y() const
Get the point y coordinate in the image plane.
double get_w() const
Get the point w coordinate in the image plane.
Class that defines what is a point.
Implementation of a rotation matrix and operations on such kind of matrices.
void insert(const vpRotationMatrix &R)
Implementation of an homography and operations on homographies.
void set_u(const double u)
vpHomography()
initialize an homography as Identity
void set_v(const double v)
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.
void set_w(const double w)
Set the point w coordinate in the image plane.
double get_x() const
Get the point x coordinate in the image plane.
unsigned int getRows() const
Return the number of rows of the 2D array.
vpColVector getNormal() const
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomography operator/(const double &v) const
void save(std::ofstream &f) const
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)
Implementation of column vector and the associated operations.
Implementation of a pose vector and operations on poses.
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.
vpHomography operator*(const vpHomography &H) const
void setIteration(const unsigned int iter)
Set iteration.
Class that consider the case of a translation vector.
Implementation of a rotation vector as axis-angle minimal representation.