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" 119 int test_planar_fail = 0, test_non_planar_fail = 0, fail = 0;
128 std::cout <<
"Start test considering planar case with 4 points..." << std::endl;
129 std::cout <<
"===================================================" << std::endl;
136 std::vector<vpPoint> P(npt);
139 P[0].setWorldCoordinates(-L, -L, Z);
140 P[1].setWorldCoordinates( L, -L, Z);
141 P[2].setWorldCoordinates( L, L, Z);
142 P[3].setWorldCoordinates(-L, L, Z);
146 for (
int i = 0; i < npt; i++) {
147 P[i].project(cMo_ref);
154 print_pose(cMo_ref, std::string(
"Reference pose"));
156 std::cout <<
"-------------------------------------------------" << std::endl;
159 print_pose(cMo, std::string(
"Pose estimated by Lagrange"));
160 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange");
161 test_planar_fail |= fail;
163 std::cout <<
"--------------------------------------------------" << std::endl;
166 print_pose(cMo, std::string(
"Pose estimated by Dementhon"));
167 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon");
168 test_planar_fail |= fail;
170 std::cout <<
"--------------------------------------------------" << std::endl;
176 print_pose(cMo, std::string(
"Pose estimated by Ransac"));
177 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Ransac");
178 test_planar_fail |= fail;
180 std::cout <<
"--------------------------------------------------" << std::endl;
183 print_pose(cMo, std::string(
"Pose estimated by Lagrange then Lowe"));
184 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange then Lowe");
185 test_planar_fail |= fail;
187 std::cout <<
"--------------------------------------------------" << std::endl;
190 print_pose(cMo, std::string(
"Pose estimated by Dementhon then Lowe"));
191 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then Lowe");
192 test_planar_fail |= fail;
195 std::cout <<
"--------------------------------------------------" << std::endl;
198 print_pose(cMo, std::string(
"Pose estimated by VVS"));
199 fail = compare_pose(pose, cMo_ref, cMo,
"pose by VVS");
200 test_planar_fail |= fail;
202 std::cout <<
"-------------------------------------------------" << std::endl;
205 print_pose(cMo, std::string(
"Pose estimated by Dementhon then by VVS"));
206 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then by VVS");
207 test_planar_fail |= fail;
209 std::cout <<
"-------------------------------------------------" << std::endl;
212 print_pose(cMo, std::string(
"Pose estimated by Lagrange then by VVS"));
213 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange then by VVS");
214 test_planar_fail |= fail;
223 std::cout <<
"\nStart test considering non-planar case with 6 points..." << std::endl;
224 std::cout <<
"=======================================================" << std::endl;
230 std::vector<vpPoint> P(npt);
231 P[0].setWorldCoordinates(-L, -L, 0);
232 P[0].setWorldCoordinates(-L, -L, -0.02);
233 P[1].setWorldCoordinates( L, -L, 0);
234 P[2].setWorldCoordinates( L, L, 0);
235 P[3].setWorldCoordinates(-2 * L, 3 * L, 0);
236 P[4].setWorldCoordinates(-L, L, 0.01);
237 P[5].setWorldCoordinates( L, L/2., 0.03);
241 for (
int i = 0; i < npt; i++) {
242 P[i].project(cMo_ref);
248 print_pose(cMo_ref, std::string(
"Reference pose"));
250 std::cout <<
"-------------------------------------------------" << std::endl;
253 print_pose(cMo, std::string(
"Pose estimated by Lagrange"));
254 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange");
255 test_non_planar_fail |= fail;
257 std::cout <<
"--------------------------------------------------" << std::endl;
260 print_pose(cMo, std::string(
"Pose estimated by Dementhon"));
261 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon");
262 test_non_planar_fail |= fail;
264 std::cout <<
"--------------------------------------------------" << std::endl;
269 print_pose(cMo, std::string(
"Pose estimated by Ransac"));
270 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Ransac");
271 test_non_planar_fail |= fail;
273 std::cout <<
"--------------------------------------------------" << std::endl;
276 print_pose(cMo, std::string(
"Pose estimated by Lagrange then Lowe"));
277 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange then Lowe");
278 test_non_planar_fail |= fail;
280 std::cout <<
"--------------------------------------------------" << std::endl;
283 print_pose(cMo, std::string(
"Pose estimated by Dementhon then Lowe"));
284 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then Lowe");
285 test_non_planar_fail |= fail;
289 std::cout <<
"--------------------------------------------------" << std::endl;
292 print_pose(cMo, std::string(
"Pose estimated by VVS"));
293 fail = compare_pose(pose, cMo_ref, cMo,
"pose by VVS");
294 test_non_planar_fail |= fail;
296 std::cout <<
"-------------------------------------------------" << std::endl;
299 print_pose(cMo, std::string(
"Pose estimated by Dementhon then by VVS"));
300 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then by VVS");
301 test_non_planar_fail |= fail;
303 std::cout <<
"-------------------------------------------------" << std::endl;
306 print_pose(cMo, std::string(
"Pose estimated by Lagrange then by VVS"));
307 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange then by VVS");
308 test_non_planar_fail |= fail;
315 std::cout <<
"\nStart test considering non-planar case with 4 points..." << std::endl;
316 std::cout <<
"=======================================================" << std::endl;
320 std::vector<vpPoint> P(npt);
321 P[0].setWorldCoordinates(-L2, -L2, 0);
322 P[1].setWorldCoordinates( L2, -L2, 0.2);
323 P[2].setWorldCoordinates( L2, L2, -0.1);
324 P[3].setWorldCoordinates(-L2, L2, 0);
331 for (
int i = 0; i < npt; i++) {
332 P[i].project(cMo_ref);
338 print_pose(cMo_ref, std::string(
"Reference pose"));
340 std::cout <<
"--------------------------------------------------" << std::endl;
343 print_pose(cMo, std::string(
"Pose estimated by Dementhon"));
344 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon");
345 test_non_planar_fail |= fail;
347 std::cout <<
"--------------------------------------------------" << std::endl;
352 print_pose(cMo, std::string(
"Pose estimated by Ransac"));
353 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Ransac");
354 test_non_planar_fail |= fail;
356 std::cout <<
"--------------------------------------------------" << std::endl;
359 print_pose(cMo, std::string(
"Pose estimated by Dementhon then Lowe"));
360 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then Lowe");
361 test_non_planar_fail |= fail;
364 std::cout <<
"--------------------------------------------------" << std::endl;
367 print_pose(cMo, std::string(
"Pose estimated by VVS"));
368 fail = compare_pose(pose, cMo_ref, cMo,
"pose by VVS");
369 test_non_planar_fail |= fail;
371 std::cout <<
"-------------------------------------------------" << std::endl;
374 print_pose(cMo, std::string(
"Pose estimated by Dementhon then by VVS"));
375 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon then by VVS");
376 test_non_planar_fail |= fail;
378 std::cout <<
"-------------------------------------------------" << std::endl;
381 std::cout <<
"=======================================================" << std::endl;
382 std::cout <<
"Pose estimation test from planar points: " << (test_planar_fail ?
"fail" :
"is ok") << std::endl;
383 std::cout <<
"Pose estimation test from non-planar points: " << (test_non_planar_fail ?
"fail" :
"is ok") << std::endl;
384 std::cout <<
"Global pose estimation test: " << ((test_planar_fail | test_non_planar_fail) ?
"fail" :
"is ok") << std::endl;
386 return ((test_planar_fail | test_non_planar_fail) ? EXIT_FAILURE : EXIT_SUCCESS);
388 std::cout <<
"Catch an exception: " << e << 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.
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the sum of squared residuals expressed in meter^2 for the pose matrix cMo...
void addPoint(const vpPoint &P)