42 #include <visp3/core/vpExponentialMap.h> 43 #include <visp3/core/vpHomogeneousMatrix.h> 44 #include <visp3/core/vpMath.h> 45 #include <visp3/core/vpMatrix.h> 46 #include <visp3/core/vpPlane.h> 47 #include <visp3/core/vpPoint.h> 48 #include <visp3/core/vpRobust.h> 49 #include <visp3/vision/vpHomography.h> 51 const double vpHomography::threshold_rotation = 1e-7;
52 const double vpHomography::threshold_displacement = 1e-18;
54 #ifndef DOXYGEN_SHOULD_SKIP_THIS 60 double s = sqrt(dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]);
64 for (
unsigned int i = 0; i < 3; i++)
68 double mcosi = 1 - cosi;
69 rd[0][0] = cosi + mcosi * u[0] * u[0];
70 rd[0][1] = -sinu * u[2] + mcosi * u[0] * u[1];
71 rd[0][2] = sinu * u[1] + mcosi * u[0] * u[2];
72 rd[1][0] = sinu * u[2] + mcosi * u[1] * u[0];
73 rd[1][1] = cosi + mcosi * u[1] * u[1];
74 rd[1][2] = -sinu * u[0] + mcosi * u[1] * u[2];
75 rd[2][0] = -sinu * u[1] + mcosi * u[2] * u[0];
76 rd[2][1] = sinu * u[0] + mcosi * u[2] * u[1];
77 rd[2][2] = cosi + mcosi * u[2] * u[2];
79 for (
unsigned int i = 0; i < 3; i++) {
80 for (
unsigned int j = 0; j < 3; j++)
113 for (
unsigned int i = 0; i < nbpoint; i++) {
115 if ((std::fabs(c2P[i].get_x() + 1) > std::fabs(
vpMath::maximum(c2P[i].get_x(), 1.))) &&
116 (std::fabs(c1P[i].get_x() + 1) > std::fabs(
vpMath::maximum(c1P[i].get_x(), 1.)))) {
120 if ((!only_1) && (!only_2))
127 robust.setThreshold(0.0000);
138 for (
unsigned int i = 0; i < 3; i++)
139 for (
unsigned int j = 0; j < 3; j++)
140 c2Rc1[i][j] = c2Mc1[i][j];
144 for (
unsigned int i = 0; i < nbpoint; i++) {
146 if ((std::fabs(c2P[i].get_x() + 1) > std::fabs(
vpMath::maximum(c2P[i].get_x(), 1.))) &&
147 (std::fabs(c1P[i].get_x() + 1) > std::fabs(
vpMath::maximum(c1P[i].get_x(), 1.)))) {
148 p2[0] = c2P[i].
get_x();
149 p2[1] = c2P[i].
get_y();
151 p1[0] = c1P[i].
get_x();
152 p1[1] = c1P[i].
get_y();
155 Hp2 = c2Rc1.t() * p2;
166 H2[0][1] = -(1 + x * x);
168 H2[1][0] = 1 + y * y;
175 e2[0] = Hp2[0] - c1P[i].
get_x();
176 e2[1] = Hp2[1] - c1P[i].
get_y();
183 H1[0][1] = -(1 + x * x);
185 H1[1][0] = 1 + y * y;
190 e1[0] = Hp1[0] - c2P[i].
get_x();
191 e1[1] = Hp1[1] - c2P[i].
get_y();
228 for (
unsigned int l = 0; l < n; l++) {
234 for (
unsigned int l = 0; l < n; l++) {
235 W[2 * l][2 * l] = w[l];
236 W[2 * l + 1][2 * l + 1] = w[l];
239 for (
unsigned int l = 0; l < 2 * n; l++)
243 (L).pseudoInverse(Lp, 1e-6);
247 c2rc1 = -2 * Lp * W * e;
248 for (
unsigned int i = 0; i < 3; i++)
253 updatePoseRotation(c2rc1, c2Mc1);
256 if ((W * e).sumSquare() < 1e-10)
265 return (W * e).sumSquare();
270 double A1 = cMo[0][0] * oN.
getA() + cMo[0][1] * oN.
getB() + cMo[0][2] * oN.
getC();
271 double B1 = cMo[1][0] * oN.
getA() + cMo[1][1] * oN.
getB() + cMo[1][2] * oN.
getC();
272 double C1 = cMo[2][0] * oN.
getA() + cMo[2][1] * oN.
getB() + cMo[2][2] * oN.
getC();
273 double D1 = oN.
getD() - (cMo[0][3] * A1 + cMo[1][3] * B1 + cMo[2][3] * C1);
312 robust.setThreshold(0.0000);
321 while (
vpMath::equal(r_1, r, threshold_displacement) ==
false) {
337 getPlaneInfo(oN, c1Mo, N1, d1);
338 getPlaneInfo(oN, c2Mo, N2, d2);
342 for (
unsigned int i = 0; i < nbpoint; i++) {
343 p2[0] = c2P[i].
get_x();
344 p2[1] = c2P[i].
get_y();
346 p1[0] = c1P[i].
get_x();
347 p1[1] = c1P[i].
get_y();
352 Hp2 = ((
vpMatrix)c1Rc2 + (c1Tc2 * N2.
t()) / d2) * p2;
353 Hp1 = ((
vpMatrix)c2Rc1 + (c2Tc1 * N1.
t()) / d1) * p1;
363 Z1 = (N1[0] * x + N1[1] * y + N1[2]) / d1;
372 H2[0][4] = -(1 + x * x);
374 H2[1][3] = 1 + y * y;
382 for (
unsigned int k_ = 0; k_ < 3; k_++)
383 for (
unsigned int l = 0; l < 3; l++) {
384 c1CFc2[k_][l] = c1Rc2[k_][l];
385 c1CFc2[k_ + 3][l + 3] = c1Rc2[k_][l];
386 c1CFc2[k_][l + 3] = sTR[k_][l];
392 e2[0] = Hp2[0] - c1P[i].
get_x();
393 e2[1] = Hp2[1] - c1P[i].
get_y();
398 Z1 = (N2[0] * x + N2[1] * y + N2[2]) / d2;
407 H1[0][4] = -(1 + x * x);
409 H1[1][3] = 1 + y * y;
414 e1[0] = Hp1[0] - c2P[i].
get_x();
415 e1[1] = Hp1[1] - c2P[i].
get_y();
450 for (
unsigned int l = 0; l < n; l++) {
456 for (
unsigned int l = 0; l < n; l++) {
457 W[2 * l][2 * l] = w[l];
458 W[2 * l + 1][2 * l + 1] = w[l];
461 for (
unsigned int l = 0; l < 2 * n; l++)
464 (W * L).pseudoInverse(Lp, 1e-16);
468 c2Tcc1 = -1 * Lp * W * e;
475 r = (W * e).sumSquare();
489 return (W * e).sumSquare();
524 robust.setThreshold(0.0000);
533 while (
vpMath::equal(r_1, r, threshold_displacement) ==
false) {
551 for (i = 0; i < nbpoint; i++) {
552 getPlaneInfo(oN[i], c1Mo, N1, d1);
553 getPlaneInfo(oN[i], c2Mo, N2, d2);
554 p2[0] = c2P[i].
get_x();
555 p2[1] = c2P[i].
get_y();
557 p1[0] = c1P[i].
get_x();
558 p1[1] = c1P[i].
get_y();
563 Hp2 = ((
vpMatrix)c1Rc2 + (c1Tc2 * N2.
t()) / d2) * p2;
564 Hp1 = ((
vpMatrix)c2Rc1 + (c2Tc1 * N1.
t()) / d1) * p1;
574 Z1 = (N1[0] * x + N1[1] * y + N1[2]) / d1;
583 H2[0][4] = -(1 + x * x);
585 H2[1][3] = 1 + y * y;
593 for (
unsigned int k_ = 0; k_ < 3; k_++)
594 for (
unsigned int l = 0; l < 3; l++) {
595 c1CFc2[k_][l] = c1Rc2[k_][l];
596 c1CFc2[k_ + 3][l + 3] = c1Rc2[k_][l];
597 c1CFc2[k_][l + 3] = sTR[k_][l];
603 e2[0] = Hp2[0] - c1P[i].
get_x();
604 e2[1] = Hp2[1] - c1P[i].
get_y();
609 Z1 = (N2[0] * x + N2[1] * y + N2[2]) / d2;
618 H1[0][4] = -(1 + x * x);
620 H1[1][3] = 1 + y * y;
625 e1[0] = Hp1[0] - c2P[i].
get_x();
626 e1[1] = Hp1[1] - c2P[i].
get_y();
661 for (
unsigned int k_ = 0; k_ < n; k_++) {
667 for (
unsigned int k_ = 0; k_ < n; k_++) {
668 W[2 * k_][2 * k_] = w[k_];
669 W[2 * k_ + 1][2 * k_ + 1] = w[k_];
672 for (
unsigned int k_ = 0; k_ < 2 * n; k_++)
675 (W * L).pseudoInverse(Lp, 1e-16);
679 c2Tcc1 = -1 * Lp * W * e;
686 r = (W * e).sumSquare();
700 return (W * e).sumSquare();
703 #endif //#ifndef DOXYGEN_SHOULD_SKIP_THIS Implementation of a matrix and operations on matrices.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static bool equal(double x, double y, double s=0.001)
void stack(const vpMatrix &A)
double get_y() const
Get the point y coordinate in the image plane.
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
Class that defines what is a point.
static Type maximum(const Type &a, const Type &b)
Implementation of a rotation matrix and operations on such kind of matrices.
void insert(const vpRotationMatrix &R)
static double sqr(double x)
void extract(vpRotationMatrix &R) const
double get_x() const
Get the point x coordinate in the image plane.
static void robust(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, std::vector< bool > &inlier, double &residual, double weights_threshold=0.4, unsigned int niter=4, bool normalization=true)
Implementation of column vector and the associated operations.
vpHomogeneousMatrix inverse() const
static vpHomogeneousMatrix direct(const vpColVector &v)
Contains an M-Estimator and various influence function.
This class defines the container for a plane geometrical structure.
Class that consider the case of a translation vector.
void resize(const unsigned int i, const bool flagNullify=true)