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),
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 residual_ = 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();
374 vpERROR_TRACE(
"Dementhon method cannot be used in that case ");
381 int coplanar_plane_type = 0;
382 bool plan =
coplanar(coplanar_plane_type);
407 int coplanar_plane_type;
408 bool plan =
coplanar(coplanar_plane_type);
410 if (plan ==
true && coplanar_plane_type > 0)
413 if (coplanar_plane_type == 4) {
414 vpERROR_TRACE(
"Lagrange method cannot be used in that case ");
419 vpERROR_TRACE(
"Lagrange method cannot be used in that case ");
432 vpERROR_TRACE(
"Lagrange method cannot be used in that case ");
498 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
501 std::cout <<
"3D oP " << P.
oP.
t();
502 std::cout <<
"3D cP " << P.
cP.
t();
503 std::cout <<
"2D " << P.
p.
t();
544 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
562 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it) {
595 std::vector<double> rectx(4);
596 std::vector<double> recty(4);
605 std::vector<double> irectx(4);
606 std::vector<double> irecty(4);
607 irectx[0] = (p1.
get_x());
608 irecty[0] = (p1.
get_y());
609 irectx[1] = (p2.
get_x());
610 irecty[1] = (p2.
get_y());
611 irectx[2] = (p3.
get_x());
612 irecty[2] = (p3.
get_y());
613 irectx[3] = (p4.
get_x());
614 irecty[3] = (p4.
get_y());
622 for (
unsigned int i = 0; i < 3; i++)
623 for (
unsigned int j = 0; j < 3; j++)
Implementation of a matrix and operations on matrices.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
double get_oY() const
Get the point Y coordinate in the object frame.
double residual
Residual in meter.
void poseLagrangePlan(vpHomogeneousMatrix &cMo, const int coplanar_plane_type=0)
Compute the pose of a planar object using Lagrange approach.
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)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
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)
void track(const vpHomogeneousMatrix &cMo)
std::list< vpPoint > listP
Array of point (use here class vpPoint)
double get_oX() const
Get the point X coordinate in the object frame.
void poseVirtualVS(vpHomogeneousMatrix &cMo)
Compute the pose using virtual visual servoing approach.
Class that defines what is a point.
bool poseRansac(vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
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.
void poseLowe(vpHomogeneousMatrix &cMo)
Compute the pose using the Lowe non linear approach it consider the minimization of a residual using ...
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
double get_oZ() const
Get the point Z coordinate in the object frame.
unsigned int npt
Number of point used in pose computation.
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)
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 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))
double get_x() const
Get the point x coordinate in the image plane.
double get_y() const
Get the point y coordinate in the image plane.
vpPoseMethodType
Methods that could be used to estimate the pose from points.
void setDistanceToPlaneForCoplanarityTest(double d)
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)
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the residual expressed in meter for the pose matrix 'cMo'.
void addPoint(const vpPoint &P)
vpColVector getCol(const unsigned int j) const