41 #include <visp3/core/vpDebug.h> 42 #include <visp3/core/vpHomogeneousMatrix.h> 43 #include <visp3/core/vpMath.h> 44 #include <visp3/core/vpPoint.h> 45 #include <visp3/core/vpRotationMatrix.h> 46 #include <visp3/core/vpRxyzVector.h> 47 #include <visp3/core/vpTranslationVector.h> 48 #include <visp3/vision/vpPose.h> 66 const std::string &legend);
73 std::cout << std::endl
75 <<
"tx = " << cpo[0] <<
"\n " 76 <<
"ty = " << cpo[1] <<
"\n " 77 <<
"tz = " << cpo[2] <<
"\n " 78 <<
"tux = vpMath::rad(" <<
vpMath::deg(cpo[3]) <<
")\n " 79 <<
"tuy = vpMath::rad(" <<
vpMath::deg(cpo[4]) <<
")\n " 80 <<
"tuz = vpMath::rad(" <<
vpMath::deg(cpo[5]) <<
")\n" 86 const std::string &legend)
94 for (
unsigned int i = 0; i < 6; i++) {
95 if (std::fabs(pose_ref[i] - pose_est[i]) > 0.001)
99 std::cout <<
"Based on 3D parameters " << legend <<
" is " << (fail ?
"badly" :
"well") <<
" estimated" << std::endl;
103 if (pose.
listP.size() < 4) {
105 std::cout <<
"Not enough point" << std::endl;
108 r = sqrt(r / pose.
listP.size());
110 fail = (r > 0.001) ? 1 : 0;
111 std::cout <<
"Based on 2D residual (" << r <<
") " << legend <<
" is " << (fail ?
"badly" :
"well") <<
" estimated" 118 #if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 120 int test_planar_fail = 0, test_non_planar_fail = 0, fail = 0;
129 std::cout <<
"Start test considering planar case with 4 points..." << std::endl;
130 std::cout <<
"===================================================" << std::endl;
137 std::vector<vpPoint> P(npt);
140 P[0].setWorldCoordinates(-L, -L, Z);
141 P[1].setWorldCoordinates( L, -L, Z);
142 P[2].setWorldCoordinates( L, L, Z);
143 P[3].setWorldCoordinates(-L, L, Z);
147 for (
int i = 0; i < npt; i++) {
148 P[i].project(cMo_ref);
155 print_pose(cMo_ref, std::string(
"Reference pose"));
157 std::cout <<
"-------------------------------------------------" << std::endl;
160 print_pose(cMo, std::string(
"Pose estimated by Lagrange"));
161 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange");
162 test_planar_fail |= fail;
164 std::cout <<
"--------------------------------------------------" << std::endl;
167 print_pose(cMo, std::string(
"Pose estimated by Dementhon"));
168 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon");
169 test_planar_fail |= fail;
171 std::cout <<
"--------------------------------------------------" << std::endl;
177 print_pose(cMo, std::string(
"Pose estimated by Ransac"));
178 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Ransac");
179 test_planar_fail |= fail;
181 std::cout <<
"--------------------------------------------------" << std::endl;
184 print_pose(cMo, std::string(
"Pose estimated by Lagrange then Lowe"));
185 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange then Lowe");
186 test_planar_fail |= fail;
188 std::cout <<
"--------------------------------------------------" << std::endl;
191 print_pose(cMo, std::string(
"Pose estimated by Dementhon then Lowe"));
192 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then Lowe");
193 test_planar_fail |= fail;
196 std::cout <<
"--------------------------------------------------" << std::endl;
199 print_pose(cMo, std::string(
"Pose estimated by VVS"));
200 fail = compare_pose(pose, cMo_ref, cMo,
"pose by VVS");
201 test_planar_fail |= fail;
203 std::cout <<
"-------------------------------------------------" << std::endl;
206 print_pose(cMo, std::string(
"Pose estimated by Dementhon then by VVS"));
207 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then by VVS");
208 test_planar_fail |= fail;
210 std::cout <<
"-------------------------------------------------" << std::endl;
213 print_pose(cMo, std::string(
"Pose estimated by Lagrange then by VVS"));
214 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange then by VVS");
215 test_planar_fail |= fail;
224 std::cout <<
"\nStart test considering non-planar case with 6 points..." << std::endl;
225 std::cout <<
"=======================================================" << std::endl;
231 std::vector<vpPoint> P(npt);
232 P[0].setWorldCoordinates(-L, -L, 0);
233 P[0].setWorldCoordinates(-L, -L, -0.02);
234 P[1].setWorldCoordinates( L, -L, 0);
235 P[2].setWorldCoordinates( L, L, 0);
236 P[3].setWorldCoordinates(-2 * L, 3 * L, 0);
237 P[4].setWorldCoordinates(-L, L, 0.01);
238 P[5].setWorldCoordinates( L, L/2., 0.03);
242 for (
int i = 0; i < npt; i++) {
243 P[i].project(cMo_ref);
249 print_pose(cMo_ref, std::string(
"Reference pose"));
251 std::cout <<
"-------------------------------------------------" << std::endl;
254 print_pose(cMo, std::string(
"Pose estimated by Lagrange"));
255 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange");
256 test_non_planar_fail |= fail;
258 std::cout <<
"--------------------------------------------------" << std::endl;
261 print_pose(cMo, std::string(
"Pose estimated by Dementhon"));
262 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon");
263 test_non_planar_fail |= fail;
265 std::cout <<
"--------------------------------------------------" << std::endl;
270 print_pose(cMo, std::string(
"Pose estimated by Ransac"));
271 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Ransac");
272 test_non_planar_fail |= fail;
274 std::cout <<
"--------------------------------------------------" << std::endl;
277 print_pose(cMo, std::string(
"Pose estimated by Lagrange then Lowe"));
278 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange then Lowe");
279 test_non_planar_fail |= fail;
281 std::cout <<
"--------------------------------------------------" << std::endl;
284 print_pose(cMo, std::string(
"Pose estimated by Dementhon then Lowe"));
285 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then Lowe");
286 test_non_planar_fail |= fail;
290 std::cout <<
"--------------------------------------------------" << std::endl;
293 print_pose(cMo, std::string(
"Pose estimated by VVS"));
294 fail = compare_pose(pose, cMo_ref, cMo,
"pose by VVS");
295 test_non_planar_fail |= fail;
297 std::cout <<
"-------------------------------------------------" << std::endl;
300 print_pose(cMo, std::string(
"Pose estimated by Dementhon then by VVS"));
301 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then by VVS");
302 test_non_planar_fail |= fail;
304 std::cout <<
"-------------------------------------------------" << std::endl;
307 print_pose(cMo, std::string(
"Pose estimated by Lagrange then by VVS"));
308 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange then by VVS");
309 test_non_planar_fail |= fail;
316 std::cout <<
"\nStart test considering non-planar case with 4 points..." << std::endl;
317 std::cout <<
"=======================================================" << std::endl;
321 std::vector<vpPoint> P(npt);
322 P[0].setWorldCoordinates(-L2, -L2, 0);
323 P[1].setWorldCoordinates( L2, -L2, 0.2);
324 P[2].setWorldCoordinates( L2, L2, -0.1);
325 P[3].setWorldCoordinates(-L2, L2, 0);
332 for (
int i = 0; i < npt; i++) {
333 P[i].project(cMo_ref);
339 print_pose(cMo_ref, std::string(
"Reference pose"));
341 std::cout <<
"--------------------------------------------------" << std::endl;
344 print_pose(cMo, std::string(
"Pose estimated by Dementhon"));
345 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon");
346 test_non_planar_fail |= fail;
348 std::cout <<
"--------------------------------------------------" << std::endl;
353 print_pose(cMo, std::string(
"Pose estimated by Ransac"));
354 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Ransac");
355 test_non_planar_fail |= fail;
357 std::cout <<
"--------------------------------------------------" << std::endl;
360 print_pose(cMo, std::string(
"Pose estimated by Dementhon then Lowe"));
361 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then Lowe");
362 test_non_planar_fail |= fail;
365 std::cout <<
"--------------------------------------------------" << std::endl;
368 print_pose(cMo, std::string(
"Pose estimated by VVS"));
369 fail = compare_pose(pose, cMo_ref, cMo,
"pose by VVS");
370 test_non_planar_fail |= fail;
372 std::cout <<
"-------------------------------------------------" << std::endl;
375 print_pose(cMo, std::string(
"Pose estimated by Dementhon then by VVS"));
376 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then by VVS");
377 test_non_planar_fail |= fail;
379 std::cout <<
"-------------------------------------------------" << std::endl;
382 std::cout <<
"=======================================================" << std::endl;
383 std::cout <<
"Pose estimation test from planar points: " << (test_planar_fail ?
"fail" :
"is ok") << std::endl;
384 std::cout <<
"Pose estimation test from non-planar points: " << (test_non_planar_fail ?
"fail" :
"is ok") << std::endl;
385 std::cout <<
"Global pose estimation test: " << ((test_planar_fail | test_non_planar_fail) ?
"fail" :
"is ok") << std::endl;
387 return ((test_planar_fail | test_non_planar_fail) ? EXIT_FAILURE : EXIT_SUCCESS);
389 std::cout <<
"Catch an exception: " << e << std::endl;
393 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=NULL)
Implementation of an homogeneous matrix and operations on such kind of matrices.
error that can be emited by ViSP classes.
void setRansacThreshold(const double &t)
std::list< vpPoint > listP
Array of point (use here class vpPoint)
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
static double rad(double deg)
void setRansacNbInliersToReachConsensus(const unsigned int &nbC)
static double deg(double rad)
Implementation of a pose vector and operations on poses.
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...