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))
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();
226 for (
unsigned int l = 0; l < n; l++) {
232 for (
unsigned int l = 0; l < n; l++) {
233 W[2 * l][2 * l] = w[l];
234 W[2 * l + 1][2 * l + 1] = w[l];
237 for (
unsigned int l = 0; l < 2 * n; l++)
241 (L).pseudoInverse(Lp, 1e-6);
245 c2rc1 = -2 * Lp * W * e;
246 for (
unsigned int i = 0; i < 3; i++)
251 updatePoseRotation(c2rc1, c2Mc1);
254 if ((W * e).sumSquare() < 1e-10)
263 return (W * e).sumSquare();
268 double A1 = cMo[0][0] * oN.
getA() + cMo[0][1] * oN.
getB() + cMo[0][2] * oN.
getC();
269 double B1 = cMo[1][0] * oN.
getA() + cMo[1][1] * oN.
getB() + cMo[1][2] * oN.
getC();
270 double C1 = cMo[2][0] * oN.
getA() + cMo[2][1] * oN.
getB() + cMo[2][2] * oN.
getC();
271 double D1 = oN.
getD() - (cMo[0][3] * A1 + cMo[1][3] * B1 + cMo[2][3] * C1);
319 while (
vpMath::equal(r_1, r, threshold_displacement) ==
false) {
335 getPlaneInfo(oN, c1Mo, N1, d1);
336 getPlaneInfo(oN, c2Mo, N2, d2);
340 for (
unsigned int i = 0; i < nbpoint; i++) {
341 p2[0] = c2P[i].
get_x();
342 p2[1] = c2P[i].
get_y();
344 p1[0] = c1P[i].
get_x();
345 p1[1] = c1P[i].
get_y();
350 Hp2 = ((
vpMatrix)c1Rc2 + (c1Tc2 * N2.
t()) / d2) * p2;
351 Hp1 = ((
vpMatrix)c2Rc1 + (c2Tc1 * N1.
t()) / d1) * p1;
361 Z1 = (N1[0] * x + N1[1] * y + N1[2]) / d1;
370 H2[0][4] = -(1 + x * x);
372 H2[1][3] = 1 + y * y;
380 for (
unsigned int k_ = 0; k_ < 3; k_++)
381 for (
unsigned int l = 0; l < 3; l++) {
382 c1CFc2[k_][l] = c1Rc2[k_][l];
383 c1CFc2[k_ + 3][l + 3] = c1Rc2[k_][l];
384 c1CFc2[k_][l + 3] = sTR[k_][l];
390 e2[0] = Hp2[0] - c1P[i].
get_x();
391 e2[1] = Hp2[1] - c1P[i].
get_y();
396 Z1 = (N2[0] * x + N2[1] * y + N2[2]) / d2;
405 H1[0][4] = -(1 + x * x);
407 H1[1][3] = 1 + y * y;
412 e1[0] = Hp1[0] - c2P[i].
get_x();
413 e1[1] = Hp1[1] - c2P[i].
get_y();
447 for (
unsigned int l = 0; l < n; l++) {
453 for (
unsigned int l = 0; l < n; l++) {
454 W[2 * l][2 * l] = w[l];
455 W[2 * l + 1][2 * l + 1] = w[l];
458 for (
unsigned int l = 0; l < 2 * n; l++)
461 (W * L).pseudoInverse(Lp, 1e-16);
465 c2Tcc1 = -1 * Lp * W * e;
471 r = (W * e).sumSquare();
485 return (W * e).sumSquare();
529 while (
vpMath::equal(r_1, r, threshold_displacement) ==
false) {
547 for (i = 0; i < nbpoint; i++) {
548 getPlaneInfo(oN[i], c1Mo, N1, d1);
549 getPlaneInfo(oN[i], c2Mo, N2, d2);
550 p2[0] = c2P[i].
get_x();
551 p2[1] = c2P[i].
get_y();
553 p1[0] = c1P[i].
get_x();
554 p1[1] = c1P[i].
get_y();
559 Hp2 = ((
vpMatrix)c1Rc2 + (c1Tc2 * N2.
t()) / d2) * p2;
560 Hp1 = ((
vpMatrix)c2Rc1 + (c2Tc1 * N1.
t()) / d1) * p1;
570 Z1 = (N1[0] * x + N1[1] * y + N1[2]) / d1;
579 H2[0][4] = -(1 + x * x);
581 H2[1][3] = 1 + y * y;
589 for (
unsigned int k_ = 0; k_ < 3; k_++)
590 for (
unsigned int l = 0; l < 3; l++) {
591 c1CFc2[k_][l] = c1Rc2[k_][l];
592 c1CFc2[k_ + 3][l + 3] = c1Rc2[k_][l];
593 c1CFc2[k_][l + 3] = sTR[k_][l];
599 e2[0] = Hp2[0] - c1P[i].
get_x();
600 e2[1] = Hp2[1] - c1P[i].
get_y();
605 Z1 = (N2[0] * x + N2[1] * y + N2[2]) / d2;
614 H1[0][4] = -(1 + x * x);
616 H1[1][3] = 1 + y * y;
621 e1[0] = Hp1[0] - c2P[i].
get_x();
622 e1[1] = Hp1[1] - c2P[i].
get_y();
656 for (
unsigned int k_ = 0; k_ < n; k_++) {
662 for (
unsigned int k_ = 0; k_ < n; k_++) {
663 W[2 * k_][2 * k_] = w[k_];
664 W[2 * k_ + 1][2 * k_ + 1] = w[k_];
667 for (
unsigned int k_ = 0; k_ < 2 * n; k_++)
670 (W * L).pseudoInverse(Lp, 1e-16);
674 c2Tcc1 = -1 * Lp * W * e;
680 r = (W * e).sumSquare();
694 return (W * e).sumSquare();
697 #endif //#ifndef DOXYGEN_SHOULD_SKIP_THIS Implementation of a matrix and operations on matrices.
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
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)
vpHomogeneousMatrix inverse() const
void extract(vpRotationMatrix &R) const
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
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)
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)
void resize(unsigned int i, bool flagNullify=true)
Implementation of column vector and the associated operations.
double get_x() const
Get the point x coordinate in the image plane.
static vpHomogeneousMatrix direct(const vpColVector &v)
double get_y() const
Get the point y coordinate in the image plane.
Contains an M-estimator and various influence function.
Tukey influence function.
This class defines the container for a plane geometrical structure.
void setMinMedianAbsoluteDeviation(double mad_min)
Class that consider the case of a translation vector.