50 #include <visp/vpHomography.h>
51 #include <visp/vpMatrix.h>
52 #include <visp/vpMatrixException.h>
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
60 vpHomography::HartleyNormalization(
const std::vector<double> &x,
const std::vector<double> &y,
61 std::vector<double> &xn, std::vector<double> &yn,
62 double &xg,
double &yg,
double &coef)
64 if (x.size() != y.size())
66 "Hartley normalization require that x and y vector have the same dimension"));
68 unsigned int n = (
unsigned int) x.size();
77 for (
unsigned int i =0 ; i < n ; i++)
88 for(
unsigned int i=0; i<n;i++)
101 if(std::fabs(distance) <= std::numeric_limits<double>::epsilon())
104 coef=sqrt(2.0)/distance;
106 for(
unsigned int i=0; i<n;i++)
114 vpHomography::HartleyNormalization(
unsigned int n,
115 const double *x,
const double *y,
116 double *xn,
double *yn,
117 double &xg,
double &yg,
124 for (i =0 ; i < n ; i++)
148 if(std::fabs(distance) <= std::numeric_limits<double>::epsilon())
151 coef=sqrt(2.0)/distance;
163 vpHomography::HartleyDenormalization(
vpHomography &aHbn,
165 double xg1,
double yg1,
double coef1,
166 double xg2,
double yg2,
double coef2 )
180 T1[0][0]=T1[1][1]=coef1;
181 T1[0][2]=-coef1*xg1 ;
182 T1[1][2]=-coef1*yg1 ;
184 T2[0][0]=T2[1][1]=coef2;
185 T2[0][2]=-coef2*xg2 ;
186 T2[1][2]=-coef2*yg2 ;
188 T2T=T2.pseudoInverse(1e-16) ;
191 for(
unsigned int i=0; i<3; i++)
192 for(
unsigned int j=0; j<3; j++)
193 aHbn_[i][j] = aHbn[i][j];
197 for (
unsigned int i=0 ; i < 3 ; i++)
198 for (
unsigned int j=0 ; j < 3 ; j++)
199 aHb[i][j] = maHb[i][j] ;
202 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
204 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
226 double *xb,
double *yb,
227 double *xa,
double *ya ,
237 xbn =
new double [n];
238 ybn =
new double [n];
240 double xg1, yg1, coef1 ;
241 vpHomography::HartleyNormalization(n,
248 xan =
new double [n];
249 yan =
new double [n];
251 double xg2, yg2, coef2 ;
252 vpHomography::HartleyNormalization(n,
262 vpHomography::HartleyDenormalization(aHbn,aHb,xg1,yg1,coef1,xg2,yg2, coef2);
276 #endif //#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
278 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
339 double *xb,
double *yb,
340 double *xa,
double *ya ,
347 vpTRACE(
"there must be at least 4 points in the both images\n") ;
365 for(
unsigned int i=0; i<n;i++)
373 A[2*i][6]=xb[i]*ya[i] ;
374 A[2*i][7]=yb[i]*ya[i];
384 A[2*i+1][6]=-xb[i]*xa[i];
385 A[2*i+1][7]=-yb[i]*xa[i];
391 for (
unsigned int i=0; i < 9; i ++) {
403 for(
unsigned int i = 0; i<9;i++) if(D[i]>1e-7) rank++;
406 vpTRACE(
" Rank is : %d, should be 8", rank);
408 "\n\t\t Matrix rank is deficient")) ;
414 double smallestSv = 1e30 ;
415 unsigned int indexSmallestSv = 0 ;
416 for (
unsigned int i=0 ; i < 9 ; i++)
417 if ((D[i] < smallestSv) ){ smallestSv = D[i] ;indexSmallestSv = i ; }
420 h=V.
getCol(indexSmallestSv);
423 for(
unsigned int i =0;i<3;i++)
425 for(
unsigned int j=0;j<3;j++)
438 std::cout <<std::endl << me << std::endl ;
443 #endif // #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
504 const std::vector<double> &xa,
const std::vector<double> &ya ,
508 unsigned int n = (
unsigned int) xb.size();
509 if (yb.size() != n || xa.size() != n || ya.size() != n)
511 "Bad dimension for DLT homography estimation"));
518 std::vector<double> xan, yan, xbn, ybn;
520 double xg1=0., yg1=0., coef1=0., xg2=0., yg2=0., coef2=0.;
525 vpHomography::HartleyNormalization(xb, yb, xbn, ybn, xg1, yg1, coef1);
526 vpHomography::HartleyNormalization(xa, ya, xan, yan, xg2, yg2, coef2);
548 for(
unsigned int i=0; i<n;i++)
556 A[2*i][6]=xbn[i]*yan[i] ;
557 A[2*i][7]=ybn[i]*yan[i];
567 A[2*i+1][6]=-xbn[i]*xan[i];
568 A[2*i+1][7]=-ybn[i]*xan[i];
569 A[2*i+1][8]=-xan[i] ;
574 for (
unsigned int i=0; i < 9; i ++) {
586 for(
unsigned int i = 0; i<9;i++) if(D[i]>1e-7) rank++;
589 vpTRACE(
" Rank is : %d, should be 8", rank);
591 "\n\t\t Matrix rank is deficient")) ;
597 double smallestSv = 1e30 ;
598 unsigned int indexSmallestSv = 0 ;
599 for (
unsigned int i=0 ; i < 9 ; i++)
600 if ((D[i] < smallestSv) ){ smallestSv = D[i] ;indexSmallestSv = i ; }
602 h=V.
getCol(indexSmallestSv);
605 for(
unsigned int i =0;i<3;i++)
607 for(
unsigned int j=0;j<3;j++)
613 vpHomography::HartleyDenormalization(aHbn, aHb, xg1, yg1, coef1, xg2, yg2, coef2);
628 std::cout <<std::endl << me << std::endl ;
Definition of the vpMatrix class.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
error that can be emited by ViSP classes.
This class aims to compute the homography wrt.two images.
void svd(vpColVector &w, vpMatrix &v)
static double sqr(double x)
vpColVector getCol(const unsigned int j) const
static void DLT(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, bool normalization=true)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
error that can be emited by the vpMatrix class and its derivates
static vp_deprecated void HartleyDLT(unsigned int n, double *xb, double *yb, double *xa, double *ya, vpHomography &aHb)
Computes the homography matrix using the DLT (Direct Linear Transform) algorithm on normalized data...