45 #include <visp3/core/vpDebug.h>
46 #include <visp3/core/vpMatrixException.h>
47 #include <visp3/vision/vpHomography.h>
53 #ifndef DOXYGEN_SHOULD_SKIP_THIS
56 const double eps = 1e-6;
91 void hlm(
unsigned int q_cible,
const std::vector<double> &xm,
const std::vector<double> &ym,
92 const std::vector<double> &xmi,
const std::vector<double> &ymi,
vpMatrix &H);
101 const unsigned int val_3 = 3;
102 for (
unsigned int i = 0; i < val_3; ++i) {
103 for (
unsigned int j = 0; j < val_3; ++j) {
104 M[j][i] = p[pts_ref[i]][j];
105 Md[j][i] = pd[pts_ref[i]][j];
113 if (pts_ref[3] > 0) {
117 for (
unsigned int i = 0; i < val_3; ++i) {
118 for (
unsigned int j = 0; j < val_3; ++j) {
119 lamb_cour[i] = Mp[i][j] * p[pts_ref[3]][j];
120 lamb_des[i] = Mdp[i][j] * pd[pts_ref[3]][j];
124 for (
unsigned int i = 0; i < val_3; ++i) {
125 for (
unsigned int j = 0; j < val_3; ++j) {
126 M[i][j] = M[i][j] * lamb_cour[j];
127 Md[i][j] = Md[i][j] * lamb_des[j];
137 unsigned int cont_pts = 0;
138 for (
unsigned int k = 0; k < nb_pts; ++k) {
139 if ((pts_ref[0] != k) && (pts_ref[1] != k) && (pts_ref[2] != k)) {
140 for (
unsigned int i = 0; i < val_3; ++i) {
141 pn[cont_pts][i] = 0.0;
142 pnd[cont_pts][i] = 0.0;
143 for (
unsigned int j = 0; j < val_3; ++j) {
144 pn[cont_pts][i] = pn[cont_pts][i] + (Mp[i][j] * p[k][j]);
145 pnd[cont_pts][i] = pnd[cont_pts][i] + (Mdp[i][j] * pd[k][j]);
148 cont_pts = cont_pts + 1;
183 unsigned int contZeros, vect;
191 for (
unsigned int j = 0; j < nb_pts; ++j) {
195 M[3 * j][3] = -points_des[j][0] * points_cour[j][2];
196 M[3 * j][4] = -points_des[j][1] * points_cour[j][2];
197 M[3 * j][5] = -points_des[j][2] * points_cour[j][2];
198 M[3 * j][6] = points_des[j][0] * points_cour[j][1];
199 M[3 * j][7] = points_des[j][1] * points_cour[j][1];
200 M[3 * j][8] = points_des[j][2] * points_cour[j][1];
202 M[(3 * j) + 1][0] = points_des[j][0] * points_cour[j][2];
203 M[(3 * j) + 1][1] = points_des[j][1] * points_cour[j][2];
204 M[(3 * j) + 1][2] = points_des[j][2] * points_cour[j][2];
205 M[(3 * j) + 1][3] = 0;
206 M[(3 * j) + 1][4] = 0;
207 M[(3 * j) + 1][5] = 0;
208 M[(3 * j) + 1][6] = -points_des[j][0] * points_cour[j][0];
209 M[(3 * j) + 1][7] = -points_des[j][1] * points_cour[j][0];
210 M[(3 * j) + 1][8] = -points_des[j][2] * points_cour[j][0];
212 M[(3 * j) + 2][0] = -points_des[j][0] * points_cour[j][1];
213 M[(3 * j) + 2][1] = -points_des[j][1] * points_cour[j][1];
214 M[(3 * j) + 2][2] = -points_des[j][2] * points_cour[j][1];
215 M[(3 * j) + 2][3] = points_des[j][0] * points_cour[j][0];
216 M[(3 * j) + 2][4] = points_des[j][1] * points_cour[j][0];
217 M[(3 * j) + 2][5] = points_des[j][2] * points_cour[j][0];
218 M[(3 * j) + 2][6] = 0;
219 M[(3 * j) + 2][7] = 0;
220 M[(3 * j) + 2][8] = 0;
238 contZeros = contZeros + 1;
240 for (
unsigned int j = 1; j < 9; ++j) {
241 if (sv[j] < vals_inf) {
246 contZeros = contZeros + 1;
258 const unsigned int val_3 = 3;
259 for (
unsigned int i = 0; i < val_3; ++i) {
260 for (
unsigned int j = 0; j < val_3; ++j) {
261 H[i][j] = V[(3 * i) + j][vect];
291 unsigned int pts_ref[4];
319 changeFrame(pts_ref, nb_pts, pd, p, pnd, pn, M, Mdp);
321 unsigned int cont_pts = nb_pts - 3;
334 for (
unsigned int i = 0; i < nc; ++i) {
335 for (
unsigned int j = 0; j < nc; ++j) {
353 unsigned int cont = 0;
354 for (
unsigned int i = 0; i < (nb_pts - 5); ++i) {
355 for (
unsigned int j = i + 1; j < (nb_pts - 4); ++j) {
356 for (
unsigned int k = j + 1; k < (nb_pts - 3); ++k) {
358 C[0] = (pn[i][2] * pn[j][2] * pn[k][1] * pnd[k][0]
359 * ((pnd[j][0] * pnd[i][1]) - (pnd[j][1] * pnd[i][0])))
360 + (pn[i][2] * pn[k][2] * pn[j][1] * pnd[j][0]
361 * ((pnd[i][0] * pnd[k][1]) - (pnd[i][1] * pnd[k][0])))
362 + (pn[j][2] * pn[k][2] * pn[i][1] * pnd[i][0]
363 * ((pnd[k][0] * pnd[j][1]) - (pnd[k][1] * pnd[j][0])));
365 C[1] = (pn[i][2] * pn[j][2] * pn[k][0] * pnd[k][1]
366 * ((pnd[i][0] * pnd[j][1]) - (pnd[i][1] * pnd[j][0])))
367 + (pn[i][2] * pn[k][2] * pn[j][0] * pnd[j][1]
368 * ((pnd[k][0] * pnd[i][1]) - (pnd[k][1] * pnd[i][0])))
369 + (pn[j][2] * pn[k][2] * pn[i][0] * pnd[i][1]
370 * ((pnd[j][0] * pnd[k][1]) - (pnd[j][1] * pnd[k][0])));
372 C[2] = (pn[i][1] * pn[k][1] * pn[j][2] * pnd[j][0]
373 * ((pnd[k][2] * pnd[i][0]) - (pnd[k][0] * pnd[i][2])))
374 + (pn[i][1] * pn[j][1] * pn[k][2] * pnd[k][0]
375 * ((pnd[i][2] * pnd[j][0]) - (pnd[i][0] * pnd[j][2]))) +
376 (pn[j][1] * pn[k][1] * pn[i][2] * pnd[i][0]
377 * ((pnd[j][2] * pnd[k][0]) - (pnd[j][0] * pnd[k][2])));
380 C[3] = (pn[i][0] * pn[j][0] * pn[k][2] * pnd[k][1]
381 * ((pnd[i][2] * pnd[j][1]) - (pnd[i][1] * pnd[j][2])))
382 + (pn[i][0] * pn[k][0] * pn[j][2] * pnd[j][1]
383 * ((pnd[k][2] * pnd[i][1]) - (pnd[k][1] * pnd[i][2])))
384 + (pn[j][0] * pn[k][0] * pn[i][2] * pnd[i][1]
385 * ((pnd[j][2] * pnd[k][1]) - (pnd[j][1] * pnd[k][2])));
388 C[5] = (pn[i][1] * pn[j][1] * pn[k][0] * pnd[k][2]
389 * ((pnd[i][0] * pnd[j][2]) - (pnd[i][2] * pnd[j][0])))
390 + (pn[i][1] * pn[k][1] * pn[j][0] * pnd[j][2]
391 * ((pnd[k][0] * pnd[i][2]) - (pnd[k][2] * pnd[i][0])))
392 + (pn[j][1] * pn[k][1] * pn[i][0] * pnd[i][2]
393 * ((pnd[j][0] * pnd[k][2]) - (pnd[j][2] * pnd[k][0])));
395 C[6] = (pn[i][0] * pn[j][0] * pn[k][1] * pnd[k][2]
396 * ((pnd[i][1] * pnd[j][2]) - (pnd[i][2] * pnd[j][1])))
397 + (pn[i][0] * pn[k][0] * pn[j][1] * pnd[j][2]
398 * ((pnd[k][1] * pnd[i][2]) - (pnd[k][2] * pnd[i][1])))
399 + (pn[j][0] * pn[k][0] * pn[i][1] * pnd[i][2]
400 * ((pnd[j][1] * pnd[k][2]) - (pnd[j][2] * pnd[k][1])));
402 C[4] = (pn[i][0] * pn[k][1] * pn[j][2]
403 * ((pnd[k][0] * pnd[j][1] * pnd[i][2]) - (pnd[j][0] * pnd[i][1] * pnd[k][2])))
404 + (pn[k][0] * pn[i][1] * pn[j][2]
405 * ((pnd[j][0] * pnd[k][1] * pnd[i][2]) - (pnd[i][0] * pnd[j][1] * pnd[k][2])))
406 + (pn[i][0] * pn[j][1] * pn[k][2]
407 * ((pnd[k][0] * pnd[i][1] * pnd[j][2]) - (pnd[j][0] * pnd[k][1] * pnd[i][2])))
408 + (pn[j][0] * pn[i][1] * pn[k][2]
409 * ((pnd[i][0] * pnd[k][1] * pnd[j][2]) - (pnd[k][0] * pnd[j][1] * pnd[i][2])))
410 + (pn[k][0] * pn[j][1] * pn[i][2]
411 * ((pnd[j][0] * pnd[i][1] * pnd[k][2]) - (pnd[i][0] * pnd[k][1] * pnd[j][2])))
412 + (pn[j][0] * pn[k][1] * pn[i][2]
413 * ((pnd[i][0] * pnd[j][1] * pnd[k][2]) - (pnd[k][0] * pnd[i][1] * pnd[j][2])));
417 for (
unsigned int ii = 0; ii < nc; ++ii) {
418 for (
unsigned int jj = ii; jj < nc; ++jj) {
419 CtC[ii][jj] = CtC[ii][jj] + (C[ii] * C[jj]);
427 for (
unsigned int i = 0; i < nc; ++i) {
428 for (
unsigned int j = i + 1; j < nc; ++j) {
429 CtC[j][i] = CtC[i][j];
463 unsigned int vect = 0;
466 for (
unsigned int j = 0; j < nc; ++j) {
467 if (std::fabs(sv[j] - svSorted[cont]) <= std::fabs(
vpMath::maximum(sv[j], svSorted[cont]))) {
470 if (std::fabs(sv[j] / svSorted[nc - 1]) < eps) {
471 cont_zeros = cont_zeros + 1;
475 if (cont_zeros > 5) {
476 hlm2D(nb_pts, pd, p, H);
499 c[0][0] = V[5][vect];
501 c[1][0] = V[6][vect];
503 c[2][0] = V[3][vect];
505 c[3][0] = V[4][vect];
508 c[4][1] = V[6][vect];
510 c[5][1] = V[5][vect];
512 c[6][1] = V[2][vect];
514 c[7][1] = V[4][vect];
517 cp = c.pseudoInverse(1e-6);
529 T[0][0] = -V[1][vect];
530 T[0][1] = V[0][vect];
531 T[1][0] = V[4][vect];
532 T[1][2] = -V[2][vect];
533 T[2][0] = -V[6][vect];
534 T[2][1] = V[2][vect];
535 T[3][0] = V[6][vect];
536 T[3][2] = -V[0][vect];
537 T[4][0] = -V[3][vect];
538 T[4][1] = V[6][vect];
539 T[5][0] = V[3][vect];
540 T[5][2] = -V[1][vect];
541 T[6][0] = -V[5][vect];
542 T[6][1] = V[4][vect];
543 T[7][0] = V[5][vect];
544 T[7][2] = -V[6][vect];
545 T[8][1] = -V[5][vect];
546 T[8][2] = V[2][vect];
549 const unsigned int val_3 = 3;
550 for (
unsigned int i = 0; i < val_3; ++i) {
559 void hlm(
unsigned int q_cible,
const std::vector<double> &xm,
const std::vector<double> &ym,
560 const std::vector<double> &xmi,
const std::vector<double> &ymi,
vpMatrix &H)
562 unsigned int nbpt =
static_cast<unsigned int>(xm.size());
571 for (
unsigned int i = 0; i < nbpt; ++i) {
589 hlm2D(nbpt, pd, p, H);
594 hlm3D(nbpt, pd, p, H);
605 void vpHomography::HLM(
const std::vector<double> &xb,
const std::vector<double> &yb,
const std::vector<double> &xa,
606 const std::vector<double> &ya,
bool isplanar,
vpHomography &aHb)
608 unsigned int n =
static_cast<unsigned int>(xb.size());
609 if ((yb.size() != n) || (xa.size() != n) || (ya.size() != n)) {
619 unsigned int q_cible;
629 hlm(q_cible, xa, ya, xb, yb, H);
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Implementation of column vector and the associated operations.
static vpColVector invSort(const vpColVector &v)
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of an homography and operations on homographies.
static void HLM(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, bool isplanar, vpHomography &aHb)
static Type maximum(const Type &a, const Type &b)
error that can be emitted by the vpMatrix class and its derivatives
@ matrixError
Matrix operation error.
Implementation of a matrix and operations on matrices.
void svd(vpColVector &w, vpMatrix &V)
vpMatrix pseudoInverse(double svThreshold=1e-6) const