41 #include <visp3/core/vpMatrix.h>
42 #include <visp3/core/vpMatrixException.h>
43 #include <visp3/vision/vpHomography.h>
48 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50 void vpHomography::HartleyNormalization(
const std::vector<double> &x,
const std::vector<double> &y,
51 std::vector<double> &xn, std::vector<double> &yn,
double &xg,
double &yg,
54 if (x.size() != y.size())
56 "have the same dimension"));
58 unsigned int n = (
unsigned int)x.size();
67 for (
unsigned int i = 0; i < n; i++) {
77 for (
unsigned int i = 0; i < n; i++) {
78 double xni = x[i] - xg;
79 double yni = y[i] - yg;
89 if (std::fabs(distance) <= std::numeric_limits<double>::epsilon())
92 coef = sqrt(2.0) / distance;
94 for (
unsigned int i = 0; i < n; i++) {
100 void vpHomography::HartleyNormalization(
unsigned int n,
const double *x,
const double *y,
double *xn,
double *yn,
101 double &xg,
double &yg,
double &coef)
107 for (i = 0; i < n; i++) {
117 for (i = 0; i < n; i++) {
118 double xni = x[i] - xg;
119 double yni = y[i] - yg;
129 if (std::fabs(distance) <= std::numeric_limits<double>::epsilon())
132 coef = sqrt(2.0) / distance;
134 for (i = 0; i < n; i++) {
142 void vpHomography::HartleyDenormalization(
vpHomography &aHbn,
vpHomography &aHb,
double xg1,
double yg1,
double coef1,
143 double xg2,
double yg2,
double coef2)
157 T1[0][0] = T1[1][1] = coef1;
158 T1[0][2] = -coef1 * xg1;
159 T1[1][2] = -coef1 * yg1;
161 T2[0][0] = T2[1][1] = coef2;
162 T2[0][2] = -coef2 * xg2;
163 T2[1][2] = -coef2 * yg2;
165 T2T = T2.pseudoInverse(1e-16);
168 for (
unsigned int i = 0; i < 3; i++)
169 for (
unsigned int j = 0; j < 3; j++)
170 aHbn_[i][j] = aHbn[i][j];
174 for (
unsigned int i = 0; i < 3; i++)
175 for (
unsigned int j = 0; j < 3; j++)
176 aHb[i][j] = maHb[i][j];
181 void vpHomography::DLT(
const std::vector<double> &xb,
const std::vector<double> &yb,
const std::vector<double> &xa,
182 const std::vector<double> &ya,
vpHomography &aHb,
bool normalization)
184 unsigned int n = (
unsigned int)xb.size();
185 if (yb.size() != n || xa.size() != n || ya.size() != n)
193 std::vector<double> xan, yan, xbn, ybn;
195 double xg1 = 0., yg1 = 0., coef1 = 0., xg2 = 0., yg2 = 0., coef2 = 0.;
200 vpHomography::HartleyNormalization(xb, yb, xbn, ybn, xg1, yg1, coef1);
201 vpHomography::HartleyNormalization(xa, ya, xan, yan, xg2, yg2, coef2);
222 for (
unsigned int i = 0; i < n; i++) {
226 A[2 * i][3] = -xbn[i];
227 A[2 * i][4] = -ybn[i];
229 A[2 * i][6] = xbn[i] * yan[i];
230 A[2 * i][7] = ybn[i] * yan[i];
231 A[2 * i][8] = yan[i];
233 A[2 * i + 1][0] = xbn[i];
234 A[2 * i + 1][1] = ybn[i];
239 A[2 * i + 1][6] = -xbn[i] * xan[i];
240 A[2 * i + 1][7] = -ybn[i] * xan[i];
241 A[2 * i + 1][8] = -xan[i];
246 for (
unsigned int i = 0; i < 9; i++) {
258 for (
unsigned int i = 0; i < 9; i++)
268 double smallestSv = 1e30;
269 unsigned int indexSmallestSv = 0;
270 for (
unsigned int i = 0; i < 9; i++)
271 if ((D[i] < smallestSv)) {
276 h = V.
getCol(indexSmallestSv);
279 for (
unsigned int i = 0; i < 3; i++) {
280 for (
unsigned int j = 0; j < 3; j++)
281 aHbn[i][j] = h[3 * i + j];
286 vpHomography::HartleyDenormalization(aHbn, aHb, xg1, yg1, coef1, xg2, yg2, coef2);
296 std::cout << std::endl << me << std::endl;
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of an homography and operations on homographies.
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)
static double sqr(double x)
error that can be emitted by the vpMatrix class and its derivatives
@ rankDeficient
Rank deficient.
Implementation of a matrix and operations on matrices.
void svd(vpColVector &w, vpMatrix &V)
vpColVector getCol(unsigned int j) const