46 #include <visp3/vision/vpHomography.h>
47 #include <visp3/core/vpMatrix.h>
48 #include <visp3/core/vpMatrixException.h>
53 #ifndef DOXYGEN_SHOULD_SKIP_THIS
56 vpHomography::HartleyNormalization(
const std::vector<double> &x,
const std::vector<double> &y,
57 std::vector<double> &xn, std::vector<double> &yn,
58 double &xg,
double &yg,
double &coef)
60 if (x.size() != y.size())
62 "Hartley normalization require that x and y vector have the same dimension"));
64 unsigned int n = (
unsigned int) x.size();
73 for (
unsigned int i =0 ; i < n ; i++)
84 for(
unsigned int i=0; i<n;i++)
97 if(std::fabs(distance) <= std::numeric_limits<double>::epsilon())
100 coef=sqrt(2.0)/distance;
102 for(
unsigned int i=0; i<n;i++)
110 vpHomography::HartleyNormalization(
unsigned int n,
111 const double *x,
const double *y,
112 double *xn,
double *yn,
113 double &xg,
double &yg,
120 for (i =0 ; i < n ; i++)
144 if(std::fabs(distance) <= std::numeric_limits<double>::epsilon())
147 coef=sqrt(2.0)/distance;
159 vpHomography::HartleyDenormalization(
vpHomography &aHbn,
161 double xg1,
double yg1,
double coef1,
162 double xg2,
double yg2,
double coef2 )
176 T1[0][0]=T1[1][1]=coef1;
177 T1[0][2]=-coef1*xg1 ;
178 T1[1][2]=-coef1*yg1 ;
180 T2[0][0]=T2[1][1]=coef2;
181 T2[0][2]=-coef2*xg2 ;
182 T2[1][2]=-coef2*yg2 ;
184 T2T=T2.pseudoInverse(1e-16) ;
187 for(
unsigned int i=0; i<3; i++)
188 for(
unsigned int j=0; j<3; j++)
189 aHbn_[i][j] = aHbn[i][j];
193 for (
unsigned int i=0 ; i < 3 ; i++)
194 for (
unsigned int j=0 ; j < 3 ; j++)
195 aHb[i][j] = maHb[i][j] ;
198 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
259 const std::vector<double> &xa,
const std::vector<double> &ya ,
263 unsigned int n = (
unsigned int) xb.size();
264 if (yb.size() != n || xa.size() != n || ya.size() != n)
266 "Bad dimension for DLT homography estimation"));
273 std::vector<double> xan, yan, xbn, ybn;
275 double xg1=0., yg1=0., coef1=0., xg2=0., yg2=0., coef2=0.;
280 vpHomography::HartleyNormalization(xb, yb, xbn, ybn, xg1, yg1, coef1);
281 vpHomography::HartleyNormalization(xa, ya, xan, yan, xg2, yg2, coef2);
303 for(
unsigned int i=0; i<n;i++)
311 A[2*i][6]=xbn[i]*yan[i] ;
312 A[2*i][7]=ybn[i]*yan[i];
322 A[2*i+1][6]=-xbn[i]*xan[i];
323 A[2*i+1][7]=-ybn[i]*xan[i];
324 A[2*i+1][8]=-xan[i] ;
329 for (
unsigned int i=0; i < 9; i ++) {
341 for(
unsigned int i = 0; i<9;i++) if(D[i]>1e-7) rank++;
344 vpTRACE(
" Rank is : %d, should be 8", rank);
346 "\n\t\t Matrix rank is deficient")) ;
352 double smallestSv = 1e30 ;
353 unsigned int indexSmallestSv = 0 ;
354 for (
unsigned int i=0 ; i < 9 ; i++)
355 if ((D[i] < smallestSv) ){ smallestSv = D[i] ;indexSmallestSv = i ; }
357 h=V.
getCol(indexSmallestSv);
360 for(
unsigned int i =0;i<3;i++)
362 for(
unsigned int j=0;j<3;j++)
368 vpHomography::HartleyDenormalization(aHbn, aHb, xg1, yg1, coef1, xg2, yg2, coef2);
383 std::cout <<std::endl << me << std::endl ;
Implementation of a matrix and operations on matrices.
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
error that can be emited by ViSP classes.
Implementation of an homography and operations on homographies.
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)
Implementation of column vector and the associated operations.
error that can be emited by the vpMatrix class and its derivates