50 #include <visp3/core/vpDebug.h> 51 #include <visp3/core/vpMatrixException.h> 52 #include <visp3/vision/vpHomography.h> 57 #ifndef DOXYGEN_SHOULD_SKIP_THIS 58 const double eps = 1e-6;
93 void HLM(
unsigned int q_cible,
unsigned int nbpt,
double *xm,
double *ym,
double *xmi,
double *ymi,
vpMatrix &H);
95 void HLM(
unsigned int q_cible,
const std::vector<double> &xm,
const std::vector<double> &ym,
96 const std::vector<double> &xmi,
const std::vector<double> &ymi,
vpMatrix &H);
101 unsigned int i, j, k;
102 unsigned int cont_pts;
108 for (i = 0; i < 3; i++) {
109 for (j = 0; j < 3; j++) {
110 M[j][i] = p[pts_ref[i]][j];
111 Md[j][i] = pd[pts_ref[i]][j];
119 if (pts_ref[3] > 0) {
123 for (i = 0; i < 3; i++) {
124 for (j = 0; j < 3; j++) {
125 lamb_cour[i] = Mp[i][j] * p[pts_ref[3]][j];
126 lamb_des[i] = Mdp[i][j] * pd[pts_ref[3]][j];
130 for (i = 0; i < 3; i++) {
131 for (j = 0; j < 3; j++) {
132 M[i][j] = M[i][j] * lamb_cour[j];
133 Md[i][j] = Md[i][j] * lamb_des[j];
144 for (k = 0; k < nb_pts; k++) {
145 if ((pts_ref[0] != k) && (pts_ref[1] != k) && (pts_ref[2] != k)) {
146 for (i = 0; i < 3; i++) {
147 pn[cont_pts][i] = 0.0;
148 pnd[cont_pts][i] = 0.0;
149 for (j = 0; j < 3; j++) {
150 pn[cont_pts][i] = pn[cont_pts][i] + Mp[i][j] * p[k][j];
151 pnd[cont_pts][i] = pnd[cont_pts][i] + Mdp[i][j] * pd[k][j];
154 cont_pts = cont_pts + 1;
191 unsigned int contZeros, vect;
199 for (j = 0; j < nb_pts; j++) {
203 M[3 * j][3] = -points_des[j][0] * points_cour[j][2];
204 M[3 * j][4] = -points_des[j][1] * points_cour[j][2];
205 M[3 * j][5] = -points_des[j][2] * points_cour[j][2];
206 M[3 * j][6] = points_des[j][0] * points_cour[j][1];
207 M[3 * j][7] = points_des[j][1] * points_cour[j][1];
208 M[3 * j][8] = points_des[j][2] * points_cour[j][1];
210 M[3 * j + 1][0] = points_des[j][0] * points_cour[j][2];
211 M[3 * j + 1][1] = points_des[j][1] * points_cour[j][2];
212 M[3 * j + 1][2] = points_des[j][2] * points_cour[j][2];
216 M[3 * j + 1][6] = -points_des[j][0] * points_cour[j][0];
217 M[3 * j + 1][7] = -points_des[j][1] * points_cour[j][0];
218 M[3 * j + 1][8] = -points_des[j][2] * points_cour[j][0];
220 M[3 * j + 2][0] = -points_des[j][0] * points_cour[j][1];
221 M[3 * j + 2][1] = -points_des[j][1] * points_cour[j][1];
222 M[3 * j + 2][2] = -points_des[j][2] * points_cour[j][1];
223 M[3 * j + 2][3] = points_des[j][0] * points_cour[j][0];
224 M[3 * j + 2][4] = points_des[j][1] * points_cour[j][0];
225 M[3 * j + 2][5] = points_des[j][2] * points_cour[j][0];
242 vals_inf = fabs(sv[0]);
245 if (fabs(sv[0]) < eps) {
246 contZeros = contZeros + 1;
248 for (j = 1; j < 9; j++) {
249 if (fabs(sv[j]) < vals_inf) {
250 vals_inf = fabs(sv[j]);
253 if (fabs(sv[j]) < eps) {
254 contZeros = contZeros + 1;
266 for (i = 0; i < 3; i++) {
267 for (j = 0; j < 3; j++) {
268 H[i][j] = V[3 * i + j][vect];
298 unsigned int i, j, k, ii, jj;
299 unsigned int cont_pts;
302 unsigned int pts_ref[4];
343 changeFrame(pts_ref, nb_pts, pd, p, pnd, pn, M, Mdp);
345 cont_pts = nb_pts - 3;
359 for (i = 0; i < nc; i++)
360 for (j = 0; j < nc; j++)
377 for (i = 0; i < nb_pts - 5; i++) {
378 for (j = i + 1; j < nb_pts - 4; j++) {
379 for (k = j + 1; k < nb_pts - 3; k++) {
381 C[0] = pn[i][2] * pn[j][2] * pn[k][1] * pnd[k][0]
382 * (pnd[j][0] * pnd[i][1] - pnd[j][1] * pnd[i][0])
383 + pn[i][2] * pn[k][2] * pn[j][1] * pnd[j][0]
384 * (pnd[i][0] * pnd[k][1] - pnd[i][1] * pnd[k][0])
385 + pn[j][2] * pn[k][2] * pn[i][1] * pnd[i][0]
386 * (pnd[k][0] * pnd[j][1] - pnd[k][1] * pnd[j][0]);
388 C[1] = pn[i][2] * pn[j][2] * pn[k][0] * pnd[k][1]
389 * (pnd[i][0] * pnd[j][1] - pnd[i][1] * pnd[j][0])
390 + pn[i][2] * pn[k][2] * pn[j][0] * pnd[j][1]
391 * (pnd[k][0] * pnd[i][1] - pnd[k][1] * pnd[i][0])
392 + pn[j][2] * pn[k][2] * pn[i][0] * pnd[i][1]
393 * (pnd[j][0] * pnd[k][1] - pnd[j][1] * pnd[k][0]);
395 C[2] = +pn[i][1] * pn[k][1] * pn[j][2] * pnd[j][0]
396 * (pnd[k][2] * pnd[i][0] - pnd[k][0] * pnd[i][2])
397 + pn[i][1] * pn[j][1] * pn[k][2] * pnd[k][0]
398 * (pnd[i][2] * pnd[j][0] - pnd[i][0] * pnd[j][2]) +
399 pn[j][1] * pn[k][1] * pn[i][2] * pnd[i][0]
400 * (pnd[j][2] * pnd[k][0] - pnd[j][0] * pnd[k][2]);
403 C[3] = pn[i][0] * pn[j][0] * pn[k][2] * pnd[k][1]
404 * (pnd[i][2] * pnd[j][1] - pnd[i][1] * pnd[j][2])
405 + pn[i][0] * pn[k][0] * pn[j][2] * pnd[j][1]
406 * (pnd[k][2] * pnd[i][1] - pnd[k][1] * pnd[i][2])
407 + pn[j][0] * pn[k][0] * pn[i][2] * pnd[i][1]
408 * (pnd[j][2] * pnd[k][1] - pnd[j][1] * pnd[k][2]);
411 C[5] = pn[i][1] * pn[j][1] * pn[k][0] * pnd[k][2]
412 * (pnd[i][0] * pnd[j][2] - pnd[i][2] * pnd[j][0])
413 + pn[i][1] * pn[k][1] * pn[j][0] * pnd[j][2]
414 * (pnd[k][0] * pnd[i][2] - pnd[k][2] * pnd[i][0])
415 + pn[j][1] * pn[k][1] * pn[i][0] * pnd[i][2]
416 * (pnd[j][0] * pnd[k][2] - pnd[j][2] * pnd[k][0]);
418 C[6] = pn[i][0] * pn[j][0] * pn[k][1] * pnd[k][2]
419 * (pnd[i][1] * pnd[j][2] - pnd[i][2] * pnd[j][1])
420 + pn[i][0] * pn[k][0] * pn[j][1] * pnd[j][2]
421 * (pnd[k][1] * pnd[i][2] - pnd[k][2] * pnd[i][1])
422 + pn[j][0] * pn[k][0] * pn[i][1] * pnd[i][2]
423 * (pnd[j][1] * pnd[k][2] - pnd[j][2] * pnd[k][1]);
425 C[4] = pn[i][0] * pn[k][1] * pn[j][2]
426 * (pnd[k][0] * pnd[j][1] * pnd[i][2] - pnd[j][0] * pnd[i][1] * pnd[k][2])
427 + pn[k][0] * pn[i][1] * pn[j][2]
428 * (pnd[j][0] * pnd[k][1] * pnd[i][2] - pnd[i][0] * pnd[j][1] * pnd[k][2])
429 + pn[i][0] * pn[j][1] * pn[k][2]
430 * (pnd[k][0] * pnd[i][1] * pnd[j][2] - pnd[j][0] * pnd[k][1] * pnd[i][2])
431 + pn[j][0] * pn[i][1] * pn[k][2]
432 * (pnd[i][0] * pnd[k][1] * pnd[j][2] - pnd[k][0] * pnd[j][1] * pnd[i][2])
433 + pn[k][0] * pn[j][1] * pn[i][2]
434 * (pnd[j][0] * pnd[i][1] * pnd[k][2] - pnd[i][0] * pnd[k][1] * pnd[j][2])
435 + pn[j][0] * pn[k][1] * pn[i][2]
436 * (pnd[i][0] * pnd[j][1] * pnd[k][2] - pnd[k][0] * pnd[i][1] * pnd[j][2]);
440 for (ii = 0; ii < nc; ii++) {
441 for (jj = ii; jj < nc; jj++) {
442 CtC[ii][jj] = CtC[ii][jj] + C[ii] * C[jj];
450 for (i = 0; i < nc; i++) {
451 for (j = i + 1; j < nc; j++)
452 CtC[j][i] = CtC[i][j];
480 for (i = 0; i < nc; i++)
486 for (i = 1; i < nc; i++) {
487 if (svSorted[i - 1] > svSorted[i]) {
488 v_temp = svSorted[i - 1];
489 svSorted[i - 1] = svSorted[i];
490 svSorted[i] = v_temp;
506 for (j = 0; j < nc; j++) {
508 if (std::fabs(sv[j] - svSorted[cont]) <= std::fabs(
vpMath::maximum(sv[j], svSorted[cont])))
510 if (std::fabs(sv[j] / svSorted[nc - 1]) < eps)
511 cont_zeros = cont_zeros + 1;
514 if (cont_zeros > 5) {
516 HLM2D(nb_pts, pd, p, H);
538 c[0][0] = V[5][vect];
540 c[1][0] = V[6][vect];
542 c[2][0] = V[3][vect];
544 c[3][0] = V[4][vect];
547 c[4][1] = V[6][vect];
549 c[5][1] = V[5][vect];
551 c[6][1] = V[2][vect];
553 c[7][1] = V[4][vect];
556 cp = c.pseudoInverse(1e-6);
568 T[0][0] = -V[1][vect];
569 T[0][1] = V[0][vect];
570 T[1][0] = V[4][vect];
571 T[1][2] = -V[2][vect];
572 T[2][0] = -V[6][vect];
573 T[2][1] = V[2][vect];
574 T[3][0] = V[6][vect];
575 T[3][2] = -V[0][vect];
576 T[4][0] = -V[3][vect];
577 T[4][1] = V[6][vect];
578 T[5][0] = V[3][vect];
579 T[5][2] = -V[1][vect];
580 T[6][0] = -V[5][vect];
581 T[6][1] = V[4][vect];
582 T[7][0] = V[5][vect];
583 T[7][2] = -V[6][vect];
584 T[8][1] = -V[5][vect];
585 T[8][2] = V[2][vect];
588 for (i = 0; i < 3; i++)
596 void HLM(
unsigned int q_cible,
const std::vector<double> &xm,
const std::vector<double> &ym,
597 const std::vector<double> &xmi,
const std::vector<double> &ymi,
vpMatrix &H)
599 unsigned int nbpt = (
unsigned int)xm.size();
608 for (
unsigned int i = 0; i < nbpt; i++) {
626 HLM2D(nbpt, pd, p, H);
631 HLM3D(nbpt, pd, p, H);
637 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS 661 void vpHomography::HLM(
const std::vector<double> &xb,
const std::vector<double> &yb,
const std::vector<double> &xa,
662 const std::vector<double> &ya,
bool isplanar,
vpHomography &aHb)
664 unsigned int n = (
unsigned int)xb.size();
665 if (yb.size() != n || xa.size() != n || ya.size() != n)
673 unsigned int q_cible;
681 ::HLM(q_cible, xa, ya, xb, yb, H);
void svd(vpColVector &w, vpMatrix &V)
Implementation of a matrix and operations on matrices.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
error that can be emited by ViSP classes.
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)
Implementation of an homography and operations on homographies.
Implementation of column vector and the associated operations.
error that can be emited by the vpMatrix class and its derivates