46 #include <visp3/vision/vpLevenbergMarquartd.h>
47 #include <visp3/vision/vpPose.h>
51 #define MINIMUM 0.000001
53 #define DEBUG_LEVEL1 0
80 #define MIJ(m,i,j,s) ((m) + ((long) (i) * (long) (s)) + (long) (j))
84 static double XI[NBPTMAX],YI[NBPTMAX];
85 static double XO[NBPTMAX],YO[NBPTMAX],ZO[NBPTMAX];
89 #define MINIMUM 0.000001
91 void eval_function(
int npt,
double *xc,
double *f);
92 void fcn (
int m,
int n,
double *xc,
double *fvecc,
double *jac,
int ldfjac,
int iflag);
94 void eval_function(
int npt,
double *xc,
double *f)
107 x = rd[0][0]*XO[i] + rd[0][1]*YO[i] + rd[0][2]*ZO[i] + xc[0];
108 y = rd[1][0]*XO[i] + rd[1][1]*YO[i] + rd[1][2]*ZO[i] + xc[1];
109 z = rd[2][0]*XO[i] + rd[2][1]*YO[i] + rd[2][2]*ZO[i] + xc[2];
111 f[npt+i] = y/z - YI[i];
143 void fcn (
int m,
int n,
double *xc,
double *fvecc,
double *jac,
int ldfjac,
int iflag)
145 double u[X3_SIZE], rx, ry, rz;
146 double tt, mco, co, si, u1, u2, u3, x, y, z;
147 double drxt, drxu1, drxu2, drxu3;
148 double dryt, dryu1, dryu2, dryu3;
149 double drzt, drzu1, drzu2, drzu3;
150 double dxit, dxiu1, dxiu2, dxiu3;
151 double dyit, dyiu1, dyiu2, dyiu3;
156 if (m < n) printf(
"pas assez de points\n");
159 if (iflag == 1) eval_function (npt, xc, fvecc);
170 tt = sqrt (u[0] * u[0] + u[1] * u[1] + u[2] * u[2]);
177 else u1 = u2 = u3 = 0.0;
182 for (i = 0; i < npt; i++)
189 rx = rd[0][0] * x + rd[0][1] * y + rd[0][2] * z + xc[0];
190 ry = rd[1][0] * x + rd[1][1] * y + rd[1][2] * z + xc[1];
191 rz = rd[2][0] * x + rd[2][1] * y + rd[2][2] * z + xc[2];
196 drxt = (si * u1 * u3 + co * u2) * z + (si * u1 * u2 - co * u3) * y
197 + (si * u1 * u1 - si) * x;
198 drxu1 = mco * u3 * z + mco * u2 * y + 2 * mco * u1 * x;
199 drxu2 = si * z + mco * u1 * y;
200 drxu3 = mco * u1 * z - si * y;
202 dryt = (si * u2 * u3 - co * u1) * z + (si * u2 * u2 - si) * y
203 + (co * u3 + si * u1 * u2) * x;
204 dryu1 = mco * u2 * x - si * z;
205 dryu2 = mco * u3 * z + 2 * mco * u2 * y + mco * u1 * x;
206 dryu3 = mco * u2 * z + si * x;
208 drzt = (si * u3 * u3 - si) * z + (si * u2 * u3 + co * u1) * y
209 + (si * u1 * u3 - co * u2) * x;
210 drzu1 = si * y + mco * u3 * x;
211 drzu2 = mco * u3 * y - si * x;
212 drzu3 = 2 * mco * u3 * z + mco * u2 * y + mco * u1 * x;
217 dxit = drxt / rz - rx * drzt / (rz * rz);
219 dyit = dryt / rz - ry * drzt / (rz * rz);
221 dxiu1 = drxu1 / rz - drzu1 * rx / (rz * rz);
222 dyiu1 = dryu1 / rz - drzu1 * ry / (rz * rz);
224 dxiu2 = drxu2 / rz - drzu2 * rx / (rz * rz);
225 dyiu2 = dryu2 / rz - drzu2 * ry / (rz * rz);
227 dxiu3 = drxu3 / rz - drzu3 * rx / (rz * rz);
228 dyiu3 = dryu3 / rz - drzu3 * ry / (rz * rz);
234 *MIJ(jac, 0, i, ldfjac) = 1 / rz;
235 *MIJ(jac, 1, i, ldfjac) = 0.0;
236 *MIJ(jac, 2, i, ldfjac) = - rx / (rz * rz);
239 *MIJ(jac, 3, i, ldfjac) = u1 * dxit + (1 - u1 * u1) * dxiu1 / tt
240 - u1 * u2 * dxiu2 / tt - u1 * u3 * dxiu3 / tt;
241 *MIJ(jac, 4, i, ldfjac) = u2 * dxit - u1 * u2 * dxiu1 / tt
242 + (1 - u2 * u2) * dxiu2 / tt- u2 * u3 * dxiu3 / tt;
244 *MIJ(jac, 5, i, ldfjac) = u3 * dxit - u1 * u3 * dxiu1 / tt - u2 * u3 * dxiu2 / tt
245 + (1 - u3 * u3) * dxiu3 / tt;
249 *MIJ(jac, 3, i, ldfjac) = 0.0;
250 *MIJ(jac, 4, i, ldfjac) = 0.0;
251 *MIJ(jac, 5, i, ldfjac) = 0.0;
253 *MIJ(jac, 0, npt + i, ldfjac) = 0.0;
254 *MIJ(jac, 1, npt + i, ldfjac) = 1 / rz;
255 *MIJ(jac, 2, npt + i, ldfjac) = - ry / (rz * rz);
258 *MIJ(jac, 3, npt + i, ldfjac) = u1 * dyit + (1 - u1 * u1) * dyiu1 / tt
259 - u1 * u2 * dyiu2 / tt - u1 * u3 * dyiu3 / tt;
260 *MIJ(jac, 4, npt + i, ldfjac) = u2 * dyit - u1 * u2 * dyiu1 / tt
261 + (1 - u2 * u2) * dyiu2 / tt- u2 * u3 * dyiu3 / tt;
262 *MIJ(jac, 5, npt + i, ldfjac) = u3 * dyit - u1 * u3 * dyiu1 / tt
263 - u2 * u3 * dyiu2 / tt + (1 - u3 * u3) * dyiu3 / tt;
267 *MIJ(jac, 3, npt + i, ldfjac) = 0.0;
268 *MIJ(jac, 4, npt + i, ldfjac) = 0.0;
269 *MIJ(jac, 5, npt + i, ldfjac) = 0.0;
287 std::cout <<
"begin CCalcuvpPose::PoseLowe(...) " << std::endl;
292 int info, ipvt[NBR_PAR];
294 double f[2 * NBPTMAX], sol[NBR_PAR];
295 double tol, jac[NBR_PAR][2 * NBPTMAX], wa[2 * NBPTMAX + 50];
301 lwa = 2 * NBPTMAX + 50;
302 ldfjac = 2 * NBPTMAX;
303 tol = std::numeric_limits<double>::epsilon();
312 for (
unsigned int i=0;i<3;i++)
320 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it)
330 tst_lmder = lmder1 (&fcn, m, n, sol, f, &jac[0][0], ldfjac, tol, &info, ipvt, lwa, wa);
333 std::cout <<
" in CCalculPose::PoseLowe(...) : " ;
334 std::cout <<
"pb de minimisation, returns FATAL_ERROR";
338 for (
unsigned int i = 0; i < 3; i++)
341 for (
unsigned int i=0;i<3;i++)
353 std::cout <<
"end CCalculPose::PoseLowe(...) " << std::endl;
Implementation of an homogeneous matrix and operations on such kind of matrices.
double get_oY() const
Get the point Y coordinate in the object frame.
double get_y() const
Get the point y coordinate in the image plane.
std::list< vpPoint > listP
array of point (use here class vpPoint)
Class that defines what is a point.
Implementation of a rotation matrix and operations on such kind of matrices.
void insert(const vpRotationMatrix &R)
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
double get_oZ() const
Get the point Z coordinate in the object frame.
void poseLowe(vpHomogeneousMatrix &cMo)
Compute the pose using the Lowe non linear approach it consider the minimization of a residual using ...
void extract(vpRotationMatrix &R) const
double get_x() const
Get the point x coordinate in the image plane.
double get_oX() const
Get the point X coordinate in the object frame.
Implementation of a rotation vector as axis-angle minimal representation.