37 #include <visp3/core/vpCameraParameters.h>
38 #include <visp3/core/vpConfig.h>
39 #include <visp3/core/vpHomogeneousMatrix.h>
40 #include <visp3/core/vpImage.h>
41 #include <visp3/core/vpPoint.h>
42 #include <visp3/vision/vpPose.h>
43 #include <visp3/vision/vpPoseFeatures.h>
52 #ifdef ENABLE_VISP_NAMESPACE
56 #if defined(VISP_HAVE_MODULE_VISUAL_FEATURES) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 class vp_createPointClass
63 vp_createPointClass() : value(0) { }
78 int test_pose(
bool use_robust)
81 std::cout <<
"** Test robust pose estimation from features\n" << std::endl;
83 std::cout <<
"** Test pose estimation from features\n" << std::endl;
90 std::cout <<
"Reference pose used to create the visual features : " << std::endl;
91 std::cout << pose_ref.
t() << std::endl;
95 std::vector<vpPoint> pts;
101 pts.push_back(
vpPoint(0.0, -val, val2));
102 pts.push_back(
vpPoint(0.0, val, val2));
103 pts.push_back(
vpPoint(-val, val, val2));
106 pts.push_back(
vpPoint(-val, -val / 2.0, val2));
107 pts.push_back(
vpPoint(val, val / 2.0, val2));
110 pts.push_back(
vpPoint(0.0, 0.0, -1.5));
127 pts[0].project(cMo_ref);
128 pts[1].project(cMo_ref);
129 pts[2].project(cMo_ref);
131 pts[3].project(cMo_ref);
132 pts[4].project(cMo_ref);
134 pts[5].project(cMo_ref);
143 pose.addFeaturePoint(pts[0]);
145 pose.addFeaturePoint(pts[2]);
147 pose.addFeaturePoint3D(pts[5]);
149 pose.addFeatureVanishingPoint(l1, l2);
155 pose.addFeatureEllipse(circle);
161 vp_createPointClass cpClass;
162 int (vp_createPointClass::*ptrClass)(
vpFeaturePoint &,
const vpPoint &) = &vp_createPointClass::vp_createPoint;
163 pose.addSpecificFeature(&cpClass, ptrClass, fp, pts[1]);
164 pose.addSpecificFeature(&vp_createLine, fl, line);
165 pose.addSpecificFeature(ptr, fs, pts[3], pts[4]);
167 pose.setVerbose(
true);
169 pose.setVVSIterMax(200);
170 pose.setCovarianceComputation(
true);
174 std::cout <<
"\nPose used as initialisation of the pose computation : " << std::endl;
175 std::cout << pose_est.
t() << std::endl;
178 pose.computePose(cMo_est);
180 pose.computePose(cMo_est, vpPoseFeatures::ROBUST_VIRTUAL_VS);
183 std::cout <<
"\nEstimated pose from visual features : " << std::endl;
185 std::cout <<
"\nRobust estimated pose from visual features : " << std::endl;
188 std::cout << pose_est.
t() << std::endl;
190 std::cout <<
"\nResulting covariance (Diag): " << std::endl;
191 vpMatrix covariance = pose.getCovarianceMatrix();
192 std::cout << covariance[0][0] <<
" " << covariance[1][1] <<
" " << covariance[2][2] <<
" " << covariance[3][3] <<
" "
193 << covariance[4][4] <<
" " << covariance[5][5] <<
" " << std::endl;
196 for (
unsigned int i = 0; i < 6; i++) {
197 if (std::fabs(pose_ref[i] - pose_est[i]) > 0.001)
201 std::cout <<
"\nPose is " << (test_fail ?
"badly" :
"well") <<
" estimated\n" << std::endl;
209 #if defined(VISP_HAVE_MODULE_VISUAL_FEATURES) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) \
210 && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
212 if (test_pose(
false))
225 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV and enable c++11 min standard " << std::endl;
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
error that can be emitted by ViSP classes.
const std::string & getStringMessage() const
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Class that defines a 2D line visual feature which is composed by two parameters that are and ,...
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
void setWorldCoordinates(const double &oA1, const double &oB1, const double &oC1, const double &oD1, const double &oA2, const double &oB2, const double &oC2, const double &oD2)
static double rad(double deg)
Implementation of a matrix and operations on matrices.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Implementation of a pose vector and operations on poses.
vpPoseVector & buildFrom(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const double &tuz)