40 #include <visp3/core/vpMath.h> 41 #include <visp3/vision/vpPose.h> 43 #define DEBUG_LEVEL1 0 44 #define DEBUG_LEVEL2 0 45 #define DEBUG_LEVEL3 0 62 double normI = 0., normJ = 0.;
71 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
81 for (
unsigned int i = 0; i <
npt; i++) {
82 a[i][0] = c3d[i].get_oX();
83 a[i][1] = c3d[i].get_oY();
84 a[i][2] = c3d[i].get_oZ();
101 std::cout <<
"a" << std::endl << a << std::endl;
102 std::cout <<
"ata" << std::endl << ata << std::endl;
103 std::cout <<
"ata1" << std::endl << ata1 << std::endl;
104 std::cout <<
" ata*ata1" << std::endl << ata * ata1;
105 std::cout <<
" b" << std::endl << (a * ata1).t();
126 for (
unsigned int i = 0; i <
npt; i++) {
127 xprim[i] = (1 + eps[i]) * c3d[i].get_x() - c3d[0].get_x();
128 yprim[i] = (1 + eps[i]) * c3d[i].get_y() - c3d[0].get_y();
137 if (normI + normJ < 1e-10) {
140 "Division by zero in Dementhon pose computation: normI+normJ = 0"));
144 Z0 = 2 * f / (normI + normJ);
146 for (
unsigned int i = 0; i <
npt; i++) {
148 eps[i] = (c3d[i].get_oX() * k[0] + c3d[i].get_oY() * k[1] + c3d[i].get_oZ() * k[2]) / Z0;
164 cMo[0][3] = c3d[0].get_x() * 2 / (normI + normJ);
169 cMo[1][3] = c3d[0].get_y() * 2 / (normI + normJ);
176 cMo[0][3] -= (p0.
get_oX() * cMo[0][0] + p0.
get_oY() * cMo[0][1] + p0.
get_oZ() * cMo[0][2]);
177 cMo[1][3] -= (p0.
get_oX() * cMo[1][0] + p0.
get_oY() * cMo[1][1] + p0.
get_oZ() * cMo[1][2]);
178 cMo[2][3] -= (p0.
get_oX() * cMo[2][0] + p0.
get_oY() * cMo[2][1] + p0.
get_oZ() * cMo[2][2]);
182 #define EPS 0.0000001 183 #define EPS_DEM 0.001 185 static void calculRTheta(
double s,
double c,
double &r,
double &theta)
187 if ((fabs(c) > EPS_DEM) || (fabs(s) > EPS_DEM)) {
188 r = sqrt(sqrt(s * s + c * c));
189 theta = atan2(s, c) / 2.0;
191 if (fabs(c) > fabs(s)) {
211 std::cout <<
"begin (Dementhon.cc)CalculSolutionDementhon() " << std::endl;
214 double normI, normJ, normk, Z0;
226 Z0 = 2.0 / (normI + normJ);
237 cMo[0][3] = xi0 * Z0;
242 cMo[1][3] = yi0 * Z0;
250 std::cout <<
"end (Dementhon.cc)CalculSolutionDementhon() " << std::endl;
258 std::cout <<
"begin vpPose::CalculArbreDementhon() " << std::endl;
265 unsigned int iter_max = 20;
269 for (
unsigned int i = 0; i <
npt; i++) {
271 z = cMo[2][0] * c3d[i].get_oX() + cMo[2][1] * c3d[i].get_oY() + cMo[2][2] * c3d[i].get_oZ() + cMo[2][3];
283 for (
unsigned int i = 0; i <
npt; i++) {
284 xi[k] = c3d[i].get_x();
285 yi[k] = c3d[i].get_y();
289 (cMo[2][0] * c3d[i].get_oX() + cMo[2][1] * c3d[i].get_oY() + cMo[2][2] * c3d[i].get_oZ()) / cMo[2][3];
299 double smin_old = 2 * smin;
301 unsigned int cpt = 0;
302 while ((cpt < 20) && (smin_old > 0.01) && (smin <= smin_old)) {
303 double r, theta, s1, s2;
307 std::cout <<
"cpt " << cpt << std::endl;
308 std::cout <<
"smin_old " << smin_old << std::endl;
309 std::cout <<
"smin " << smin << std::endl;
319 for (
unsigned int i = 1; i <
npt; i++) {
320 double s = (1.0 + eps[cpt][i]) * xi[i] - xi[0];
321 I0[0] += b[0][i - 1] * s;
322 I0[1] += b[1][i - 1] * s;
323 I0[2] += b[2][i - 1] * s;
324 s = (1.0 + eps[cpt][i]) * yi[i] - yi[0];
325 J0[0] += b[0][i - 1] * s;
326 J0[1] += b[1][i - 1] * s;
327 J0[2] += b[2][i - 1] * s;
333 calculRTheta(s, c, r, theta);
334 double co = cos(theta);
335 double si = sin(theta);
343 std::cout <<
"I " << I.
t();
344 std::cout <<
"J " << J.
t();
348 calculSolutionDementhon(xi[0], yi[0], I, J, cMo1);
351 std::cout <<
"cMo1 " << std::endl << cMo1 << std::endl;
359 std::cout <<
"I " << I.
t();
360 std::cout <<
"J " << J.
t();
364 calculSolutionDementhon(xi[0], yi[0], I, J, cMo2);
367 std::cout <<
"cMo2 " << std::endl << cMo2 << std::endl;
374 for (
unsigned int i = 0; i <
npt; i++) {
376 eps[cpt][k] = (cMo1[2][0] * c3d[i].get_oX() + cMo1[2][1] * c3d[i].get_oY() + cMo1[2][2] * c3d[i].get_oZ()) /
385 for (
unsigned int i = 0; i <
npt; i++) {
387 eps[cpt][k] = (cMo2[2][0] * c3d[i].get_oX() + cMo2[2][1] * c3d[i].get_oY() + cMo2[2][2] * c3d[i].get_oZ()) /
395 if (smin > smin_old) {
397 std::cout <<
"Divergence " << std::endl;
404 std::cout <<
"s1 = " << s1 << std::endl;
405 std::cout <<
"s2 = " << s2 << std::endl;
406 std::cout <<
"smin = " << smin << std::endl;
407 std::cout <<
"smin_old = " << smin_old << std::endl;
413 std::cout <<
"end vpPose::CalculArbreDementhon() return " << erreur << std::endl;
430 std::cout <<
"begin CCalculPose::PoseDementhonPlan()" << std::endl;
433 unsigned int i, j, k;
439 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
455 for (i = 1; i <
npt; i++) {
456 a[i - 1][0] = c3d[i].get_oX();
457 a[i - 1][1] = c3d[i].get_oY();
458 a[i - 1][2] = c3d[i].get_oZ();
479 std::cout <<
"a" << std::endl << a << std::endl;
480 std::cout <<
"ata" << std::endl << ata << std::endl;
489 unsigned int imin = 0;
495 unsigned int nc = sv.getRows();
496 for (i = 0; i < nc; i++)
502 for (i = 0; i < nc; i++)
507 for (i = 0; i < nc; i++) {
516 std::cout <<
"rang: " << irank << std::endl;
518 std::cout <<
"imin = " << imin << std::endl;
519 std::cout <<
"sv " << sv.t() << std::endl;
523 for (i = 0; i < ata.
getRows(); i++) {
524 for (j = 0; j < ata.
getCols(); j++) {
526 for (k = 0; k < nc; k++)
528 ata1[i][j] += ((v[i][k] * ata[j][k]) / sv[k]);
541 std::cout <<
"a" << std::endl << a << std::endl;
542 std::cout <<
"ata" << std::endl << ata_sav << std::endl;
543 std::cout <<
"ata1" << std::endl << ata1 << std::endl;
544 std::cout <<
"ata1*ata" << std::endl << ata1 * ata_sav;
545 std::cout <<
"b" << std::endl << b;
546 std::cout <<
"U " << U.
t() << std::endl;
553 for (i = 0; i <
npt; i++) {
554 xi[i] = c3d[i].get_x();
555 yi[i] = c3d[i].get_y();
565 for (i = 1; i <
npt; i++) {
566 I0[0] += b[0][i - 1] * (xi[i] - xi[0]);
567 I0[1] += b[1][i - 1] * (xi[i] - xi[0]);
568 I0[2] += b[2][i - 1] * (xi[i] - xi[0]);
570 J0[0] += b[0][i - 1] * (yi[i] - yi[0]);
571 J0[1] += b[1][i - 1] * (yi[i] - yi[0]);
572 J0[2] += b[2][i - 1] * (yi[i] - yi[0]);
577 std::cout <<
"I0 " << I0.
t();
578 std::cout <<
"J0 " << J0.
t();
585 double r, theta, si, co;
586 calculRTheta(s, c, r, theta);
595 calculSolutionDementhon(xi[0], yi[0], I, J, cMo1f);
604 calculSolutionDementhon(xi[0], yi[0], I, J, cMo2f);
608 if ((erreur1 == 0) && (erreur2 == -1))
610 if ((erreur1 == -1) && (erreur2 == 0))
612 if ((erreur1 == 0) && (erreur2 == 0)) {
622 cMo[0][3] -= p0.
get_oX() * cMo[0][0] + p0.
get_oY() * cMo[0][1] + p0.
get_oZ() * cMo[0][2];
623 cMo[1][3] -= p0.
get_oX() * cMo[1][0] + p0.
get_oY() * cMo[1][1] + p0.
get_oZ() * cMo[1][2];
624 cMo[2][3] -= p0.
get_oX() * cMo[2][0] + p0.
get_oY() * cMo[2][1] + p0.
get_oZ() * cMo[2][2];
627 std::cout <<
"end CCalculPose::PoseDementhonPlan()" << std::endl;
645 double residual_ = 0;
648 for (
unsigned int i = 0; i <
npt; i++) {
650 double X = c3d[i].get_oX() * cMo[0][0] + c3d[i].get_oY() * cMo[0][1] + c3d[i].get_oZ() * cMo[0][2] + cMo[0][3];
651 double Y = c3d[i].get_oX() * cMo[1][0] + c3d[i].get_oY() * cMo[1][1] + c3d[i].get_oZ() * cMo[1][2] + cMo[1][3];
652 double Z = c3d[i].get_oX() * cMo[2][0] + c3d[i].get_oY() * cMo[2][1] + c3d[i].get_oZ() * cMo[2][2] + cMo[2][3];
void svd(vpColVector &w, vpMatrix &V)
int calculArbreDementhon(vpMatrix &b, vpColVector &U, vpHomogeneousMatrix &cMo)
Implementation of a matrix and operations on matrices.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
void set_oZ(const double oZ)
Set the point Z coordinate in the object frame.
double get_oY() const
Get the point Y coordinate in the object frame.
static vpColVector cross(const vpColVector &a, const vpColVector &b)
Implementation of an homogeneous matrix and operations on such kind of matrices.
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.
unsigned int getRows() const
std::list< vpPoint > listP
Array of point (use here class vpPoint)
double get_oX() const
Get the point X coordinate in the object frame.
Class that defines what is a point.
unsigned int getCols() const
vpColVector & normalize()
static double sqr(double x)
void set_oX(const double oX)
Set the point X coordinate in the object frame.
double get_oZ() const
Get the point Z coordinate in the object frame.
unsigned int npt
Number of point used in pose computation.
void poseDementhonPlan(vpHomogeneousMatrix &cMo)
Compute the pose using Dementhon approach for planar objects this is a direct implementation of the a...
void poseDementhonNonPlan(vpHomogeneousMatrix &cMo)
Compute the pose using Dementhon approach for non planar objects this is a direct implementation of t...
Implementation of column vector and the associated operations.
static double dotProd(const vpColVector &a, const vpColVector &b)
void set_oY(const double oY)
Set the point Y coordinate in the object frame.
vpColVector getCol(const unsigned int j) const
double computeResidualDementhon(const vpHomogeneousMatrix &cMo)
Compute and return the residual expressed in meter for the pose matrix 'pose'.
void resize(const unsigned int i, const bool flagNullify=true)