46 #include <visp3/core/vpMatrix.h> 47 #include <visp3/core/vpMatrixException.h> 48 #include <visp3/vision/vpHomography.h> 53 #ifndef DOXYGEN_SHOULD_SKIP_THIS 55 void vpHomography::HartleyNormalization(
const std::vector<double> &x,
const std::vector<double> &y,
56 std::vector<double> &xn, std::vector<double> &yn,
double &xg,
double &yg,
59 if (x.size() != y.size())
61 "have the same dimension"));
63 unsigned int n = (
unsigned int)x.size();
72 for (
unsigned int i = 0; i < n; i++) {
82 for (
unsigned int i = 0; i < n; i++) {
83 double xni = x[i] - xg;
84 double yni = y[i] - yg;
94 if (std::fabs(distance) <= std::numeric_limits<double>::epsilon())
97 coef = sqrt(2.0) / distance;
99 for (
unsigned int i = 0; i < n; i++) {
105 void vpHomography::HartleyNormalization(
unsigned int n,
const double *x,
const double *y,
double *xn,
double *yn,
106 double &xg,
double &yg,
double &coef)
112 for (i = 0; i < n; i++) {
122 for (i = 0; i < n; i++) {
123 double xni = x[i] - xg;
124 double yni = y[i] - yg;
134 if (std::fabs(distance) <= std::numeric_limits<double>::epsilon())
137 coef = sqrt(2.0) / distance;
139 for (i = 0; i < n; i++) {
147 void vpHomography::HartleyDenormalization(
vpHomography &aHbn,
vpHomography &aHb,
double xg1,
double yg1,
double coef1,
148 double xg2,
double yg2,
double coef2)
162 T1[0][0] = T1[1][1] = coef1;
163 T1[0][2] = -coef1 * xg1;
164 T1[1][2] = -coef1 * yg1;
166 T2[0][0] = T2[1][1] = coef2;
167 T2[0][2] = -coef2 * xg2;
168 T2[1][2] = -coef2 * yg2;
170 T2T = T2.pseudoInverse(1e-16);
173 for (
unsigned int i = 0; i < 3; i++)
174 for (
unsigned int j = 0; j < 3; j++)
175 aHbn_[i][j] = aHbn[i][j];
179 for (
unsigned int i = 0; i < 3; i++)
180 for (
unsigned int j = 0; j < 3; j++)
181 aHb[i][j] = maHb[i][j];
184 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS 250 void vpHomography::DLT(
const std::vector<double> &xb,
const std::vector<double> &yb,
const std::vector<double> &xa,
251 const std::vector<double> &ya,
vpHomography &aHb,
bool normalization)
253 unsigned int n = (
unsigned int)xb.size();
254 if (yb.size() != n || xa.size() != n || ya.size() != n)
262 std::vector<double> xan, yan, xbn, ybn;
264 double xg1 = 0., yg1 = 0., coef1 = 0., xg2 = 0., yg2 = 0., coef2 = 0.;
269 vpHomography::HartleyNormalization(xb, yb, xbn, ybn, xg1, yg1, coef1);
270 vpHomography::HartleyNormalization(xa, ya, xan, yan, xg2, yg2, coef2);
291 for (
unsigned int i = 0; i < n; i++) {
295 A[2 * i][3] = -xbn[i];
296 A[2 * i][4] = -ybn[i];
298 A[2 * i][6] = xbn[i] * yan[i];
299 A[2 * i][7] = ybn[i] * yan[i];
300 A[2 * i][8] = yan[i];
302 A[2 * i + 1][0] = xbn[i];
303 A[2 * i + 1][1] = ybn[i];
308 A[2 * i + 1][6] = -xbn[i] * xan[i];
309 A[2 * i + 1][7] = -ybn[i] * xan[i];
310 A[2 * i + 1][8] = -xan[i];
315 for (
unsigned int i = 0; i < 9; i++) {
327 for (
unsigned int i = 0; i < 9; i++)
337 double smallestSv = 1e30;
338 unsigned int indexSmallestSv = 0;
339 for (
unsigned int i = 0; i < 9; i++)
340 if ((D[i] < smallestSv)) {
345 h = V.
getCol(indexSmallestSv);
348 for (
unsigned int i = 0; i < 3; i++) {
349 for (
unsigned int j = 0; j < 3; j++)
350 aHbn[i][j] = h[3 * i + j];
355 vpHomography::HartleyDenormalization(aHbn, aHb, xg1, yg1, coef1, xg2, yg2, coef2);
365 std::cout << std::endl << me << std::endl;
void svd(vpColVector &w, vpMatrix &V)
Implementation of a matrix and operations on matrices.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
error that can be emited by ViSP classes.
Implementation of an homography and operations on homographies.
static double sqr(double x)
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
vpColVector getCol(unsigned int j) const