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++)
Implementation of a matrix and operations on matrices.
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=NULL)
double residual
Residual in meter.
bool coplanar(int &coplanar_plane_type)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void poseLagrangeNonPlan(vpHomogeneousMatrix &cMo)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Class to define colors available for display functionnalities.
void displayModel(vpImage< unsigned char > &I, vpCameraParameters &cam, vpColor col=vpColor::none)
void addPoints(const std::vector< vpPoint > &lP)
double get_oY() const
Get the point Y coordinate in the object frame.
void track(const vpHomogeneousMatrix &cMo)
double get_y() const
Get the point y coordinate in the image plane.
std::list< vpPoint > listP
Array of point (use here class vpPoint)
void poseVirtualVS(vpHomogeneousMatrix &cMo)
Compute the pose using virtual visual servoing approach.
Class that defines what is a point.
static void HLM(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, bool isplanar, vpHomography &aHb)
double lambda
parameters use for the virtual visual servoing approach
Implementation of an homography and operations on homographies.
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
static double poseFromRectangle(vpPoint &p1, vpPoint &p2, vpPoint &p3, vpPoint &p4, double lx, vpCameraParameters &cam, vpHomogeneousMatrix &cMo)
Carries out the camera pose the image of a rectangle and the intrinsec parameters, the length on x axis is known but the proprtion of the rectangle are unknown.
static double sqr(double x)
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
Generic class defining intrinsic camera parameters.
vpColVector getCol(const unsigned int j) const
double get_oZ() const
Get the point Z coordinate in the object frame.
void poseLagrangePlan(vpHomogeneousMatrix &cMo)
Compute the pose of a planar object using Lagrange approach.
void poseLowe(vpHomogeneousMatrix &cMo)
Compute the pose using the Lowe non linear approach it consider the minimization of a residual using ...
double get_x() const
Get the point x coordinate in the image plane.
unsigned int npt
Number of point used in pose computation.
double get_oX() const
Get the point X coordinate in the object frame.
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void setWorldCoordinates(const double oX, const double oY, const double oZ)
void poseDementhonPlan(vpHomogeneousMatrix &cMo)
Compute the pose using Dementhon approach for planar objects this is a direct implementation of the a...
Error that can be emited by the vpPose class and its derivates.
void poseDementhonNonPlan(vpHomogeneousMatrix &cMo)
Implementation of column vector and the associated operations.
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
vpPoseMethodType
Methods that could be used to estimate the pose from points.
bool poseRansac(vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=NULL)
void setDistanceToPlaneForCoplanarityTest(double d)
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
void addPoint(const vpPoint &P)
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the sum of squared residuals expressed in meter^2 for the pose matrix cMo...