46 #include <visp3/core/vpCameraParameters.h>
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpDisplay.h>
49 #include <visp3/core/vpException.h>
50 #include <visp3/core/vpMath.h>
51 #include <visp3/core/vpMeterPixelConversion.h>
52 #include <visp3/vision/vpPose.h>
53 #include <visp3/vision/vpPoseException.h>
58 #define DEBUG_LEVEL1 0
65 std::cout <<
"begin vpPose::Init() " << std::endl;
74 computeCovariance =
false;
75 covarianceMatrix.
clear();
76 ransacNbInlierConsensus = 4;
77 ransacMaxTrials = 1000;
78 ransacInliers.clear();
79 ransacInlierIndex.clear();
80 ransacThreshold = 0.0001;
81 distanceToPlaneForCoplanarityTest = 0.001;
84 useParallelRansac =
false;
85 nbParallelRansacThreads = 0;
89 std::cout <<
"end vpPose::Init() " << std::endl;
95 : npt(0), listP(), residual(0), lambda(0.25), vvsIterMax(200), c3d(), computeCovariance(false), covarianceMatrix(),
96 ransacNbInlierConsensus(4), ransacMaxTrials(1000), ransacInliers(), ransacInlierIndex(), ransacThreshold(0.0001),
97 distanceToPlaneForCoplanarityTest(0.001), ransacFlag(
vpPose::NO_FILTER), listOfPoints(),
98 useParallelRansac(false),
99 nbParallelRansacThreads(0),
110 std::cout <<
"begin vpPose::~vpPose() " << std::endl;
116 std::cout <<
"end vpPose::~vpPose() " << std::endl;
125 listOfPoints.clear();
139 listP.push_back(newP);
140 listOfPoints.push_back(newP);
154 listP.insert(
listP.end(), lP.begin(), lP.end());
155 listOfPoints.insert(listOfPoints.end(), lP.begin(), lP.end());
174 coplanar_plane_type = 0;
183 double x1 = 0, x2 = 0, x3 = 0, y1 = 0, y2 = 0, y3 = 0, z1 = 0, z2 = 0, z3 = 0;
185 std::list<vpPoint>::const_iterator it =
listP.begin();
190 bool degenerate =
true;
191 bool not_on_origin =
true;
192 std::list<vpPoint>::const_iterator it_tmp;
194 std::list<vpPoint>::const_iterator it_i, it_j, it_k;
195 for (it_i =
listP.begin(); it_i !=
listP.end(); ++it_i) {
196 if (degenerate ==
false) {
202 if ((std::fabs(P1.
get_oX()) <= std::numeric_limits<double>::epsilon()) &&
203 (std::fabs(P1.
get_oY()) <= std::numeric_limits<double>::epsilon()) &&
204 (std::fabs(P1.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
205 not_on_origin =
false;
207 not_on_origin =
true;
212 for (it_j = it_tmp; it_j !=
listP.end(); ++it_j) {
213 if (degenerate ==
false) {
218 if ((std::fabs(P2.
get_oX()) <= std::numeric_limits<double>::epsilon()) &&
219 (std::fabs(P2.
get_oY()) <= std::numeric_limits<double>::epsilon()) &&
220 (std::fabs(P2.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
221 not_on_origin =
false;
223 not_on_origin =
true;
228 for (it_k = it_tmp; it_k !=
listP.end(); ++it_k) {
230 if ((std::fabs(P3.
get_oX()) <= std::numeric_limits<double>::epsilon()) &&
231 (std::fabs(P3.
get_oY()) <= std::numeric_limits<double>::epsilon()) &&
232 (std::fabs(P3.
get_oZ()) <= std::numeric_limits<double>::epsilon())) {
233 not_on_origin =
false;
235 not_on_origin =
true;
259 if (cross_prod.
sumSquare() <= std::numeric_limits<double>::epsilon())
264 if (degenerate ==
false)
273 coplanar_plane_type = 4;
277 double a = y1 * z2 - y1 * z3 - y2 * z1 + y2 * z3 + y3 * z1 - y3 * z2;
278 double b = -x1 * z2 + x1 * z3 + x2 * z1 - x2 * z3 - x3 * z1 + x3 * z2;
279 double c = x1 * y2 - x1 * y3 - x2 * y1 + x2 * y3 + x3 * y1 - x3 * y2;
280 double d = -x1 * y2 * z3 + x1 * y3 * z2 + x2 * y1 * z3 - x2 * y3 * z1 - x3 * y1 * z2 + x3 * y2 * z1;
284 if (std::fabs(b) <= std::numeric_limits<double>::epsilon() &&
285 std::fabs(c) <= std::numeric_limits<double>::epsilon()) {
286 coplanar_plane_type = 1;
287 }
else if (std::fabs(a) <= std::numeric_limits<double>::epsilon() &&
288 std::fabs(c) <= std::numeric_limits<double>::epsilon()) {
289 coplanar_plane_type = 2;
290 }
else if (std::fabs(a) <= std::numeric_limits<double>::epsilon() &&
291 std::fabs(b) <= std::numeric_limits<double>::epsilon()) {
292 coplanar_plane_type = 3;
297 for (it =
listP.begin(); it !=
listP.end(); ++it) {
302 if (fabs(dist) > distanceToPlaneForCoplanarityTest) {
326 double squared_error = 0;
328 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
330 double x = P.
get_x();
331 double y = P.
get_y();
337 return (squared_error);
366 "Not enough point (%d) to compute the pose ",
npt));
375 "Dementhon method cannot be used in that case "
376 "(at least 4 points are required)"
377 "Not enough point (%d) to compute the pose ",
npt));
381 int coplanar_plane_type = 0;
382 bool plan =
coplanar(coplanar_plane_type);
393 int coplanar_plane_type;
394 bool plan =
coplanar(coplanar_plane_type);
399 if (coplanar_plane_type == 4) {
401 "Lagrange method cannot be used in that case "
402 "(points are collinear)"));
406 "Lagrange method cannot be used in that case "
407 "(at least 4 points are required). "
408 "Not enough point (%d) to compute the pose ",
npt));
414 "Lagrange method cannot be used in that case "
415 "(at least 6 points are required when 3D points are non coplanar). "
416 "Not enough point (%d) to compute the pose ",
npt));
424 "Ransac method cannot be used in that case "
425 "(at least 4 points are required). "
426 "Not enough point (%d) to compute the pose ",
npt));
459 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
462 std::cout <<
"3D oP " << P.
oP.
t();
463 std::cout <<
"3D cP " << P.
cP.
t();
464 std::cout <<
"2D " << P.
p.
t();
505 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
523 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
556 std::vector<double> rectx(4);
557 std::vector<double> recty(4);
566 std::vector<double> irectx(4);
567 std::vector<double> irecty(4);
568 irectx[0] = (p1.
get_x());
569 irecty[0] = (p1.
get_y());
570 irectx[1] = (p2.
get_x());
571 irecty[1] = (p2.
get_y());
572 irectx[2] = (p3.
get_x());
573 irecty[2] = (p3.
get_y());
574 irectx[3] = (p4.
get_x());
575 irecty[3] = (p4.
get_y());
583 for (
unsigned int i = 0; i < 3; i++)
584 for (
unsigned int j = 0; j < 3; j++)
599 double s = sqrt(kh1.sumSquare()) / sqrt(kh2.sumSquare());