|
7 | 7 |
|
8 | 8 | namespace opencv_test { namespace {
|
9 | 9 |
|
| 10 | +static std::string getMethodName(HandEyeCalibrationMethod method) |
| 11 | +{ |
| 12 | + std::string method_name = ""; |
| 13 | + switch (method) |
| 14 | + { |
| 15 | + case CALIB_HAND_EYE_TSAI: |
| 16 | + method_name = "Tsai"; |
| 17 | + break; |
| 18 | + |
| 19 | + case CALIB_HAND_EYE_PARK: |
| 20 | + method_name = "Park"; |
| 21 | + break; |
| 22 | + |
| 23 | + case CALIB_HAND_EYE_HORAUD: |
| 24 | + method_name = "Horaud"; |
| 25 | + break; |
| 26 | + |
| 27 | + case CALIB_HAND_EYE_ANDREFF: |
| 28 | + method_name = "Andreff"; |
| 29 | + break; |
| 30 | + |
| 31 | + case CALIB_HAND_EYE_DANIILIDIS: |
| 32 | + method_name = "Daniilidis"; |
| 33 | + break; |
| 34 | + |
| 35 | + default: |
| 36 | + break; |
| 37 | + } |
| 38 | + |
| 39 | + return method_name; |
| 40 | +} |
| 41 | + |
10 | 42 | class CV_CalibrateHandEyeTest : public cvtest::BaseTest
|
11 | 43 | {
|
12 | 44 | public:
|
@@ -48,7 +80,6 @@ class CV_CalibrateHandEyeTest : public cvtest::BaseTest
|
48 | 80 | std::vector<Mat> &R_target2cam, std::vector<Mat> &t_target2cam,
|
49 | 81 | bool noise, Mat& R_cam2gripper, Mat& t_cam2gripper);
|
50 | 82 | Mat homogeneousInverse(const Mat& T);
|
51 |
| - std::string getMethodName(HandEyeCalibrationMethod method); |
52 | 83 | double sign_double(double val);
|
53 | 84 |
|
54 | 85 | double eps_rvec[5];
|
@@ -340,45 +371,95 @@ Mat CV_CalibrateHandEyeTest::homogeneousInverse(const Mat& T)
|
340 | 371 | return Tinv;
|
341 | 372 | }
|
342 | 373 |
|
343 |
| -std::string CV_CalibrateHandEyeTest::getMethodName(HandEyeCalibrationMethod method) |
| 374 | +double CV_CalibrateHandEyeTest::sign_double(double val) |
344 | 375 | {
|
345 |
| - std::string method_name = ""; |
346 |
| - switch (method) |
347 |
| - { |
348 |
| - case CALIB_HAND_EYE_TSAI: |
349 |
| - method_name = "Tsai"; |
350 |
| - break; |
| 376 | + return (0 < val) - (val < 0); |
| 377 | +} |
351 | 378 |
|
352 |
| - case CALIB_HAND_EYE_PARK: |
353 |
| - method_name = "Park"; |
354 |
| - break; |
| 379 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
355 | 380 |
|
356 |
| - case CALIB_HAND_EYE_HORAUD: |
357 |
| - method_name = "Horaud"; |
358 |
| - break; |
| 381 | +TEST(Calib3d_CalibrateHandEye, regression) { CV_CalibrateHandEyeTest test; test.safe_run(); } |
359 | 382 |
|
360 |
| - case CALIB_HAND_EYE_ANDREFF: |
361 |
| - method_name = "Andreff"; |
362 |
| - break; |
| 383 | +TEST(Calib3d_CalibrateHandEye, regression_17986) |
| 384 | +{ |
| 385 | + const std::string camera_poses_filename = findDataFile("cv/hand_eye_calibration/cali.txt"); |
| 386 | + const std::string end_effector_poses = findDataFile("cv/hand_eye_calibration/robot_cali.txt"); |
363 | 387 |
|
364 |
| - case CALIB_HAND_EYE_DANIILIDIS: |
365 |
| - method_name = "Daniilidis"; |
366 |
| - break; |
| 388 | + std::vector<Mat> R_target2cam; |
| 389 | + std::vector<Mat> t_target2cam; |
| 390 | + // Parse camera poses |
| 391 | + { |
| 392 | + std::ifstream file(camera_poses_filename.c_str()); |
| 393 | + ASSERT_TRUE(file.is_open()); |
| 394 | + |
| 395 | + int ndata = 0; |
| 396 | + file >> ndata; |
| 397 | + R_target2cam.reserve(ndata); |
| 398 | + t_target2cam.reserve(ndata); |
| 399 | + |
| 400 | + std::string image_name; |
| 401 | + Matx33d cameraMatrix; |
| 402 | + Matx33d R; |
| 403 | + Matx31d t; |
| 404 | + Matx16d distCoeffs; |
| 405 | + Matx13d distCoeffs2; |
| 406 | + while (file >> image_name >> |
| 407 | + cameraMatrix(0,0) >> cameraMatrix(0,1) >> cameraMatrix(0,2) >> |
| 408 | + cameraMatrix(1,0) >> cameraMatrix(1,1) >> cameraMatrix(1,2) >> |
| 409 | + cameraMatrix(2,0) >> cameraMatrix(2,1) >> cameraMatrix(2,2) >> |
| 410 | + R(0,0) >> R(0,1) >> R(0,2) >> |
| 411 | + R(1,0) >> R(1,1) >> R(1,2) >> |
| 412 | + R(2,0) >> R(2,1) >> R(2,2) >> |
| 413 | + t(0) >> t(1) >> t(2) >> |
| 414 | + distCoeffs(0) >> distCoeffs(1) >> distCoeffs(2) >> distCoeffs(3) >> distCoeffs(4) >> |
| 415 | + distCoeffs2(0) >> distCoeffs2(1) >> distCoeffs2(2)) { |
| 416 | + R_target2cam.push_back(Mat(R)); |
| 417 | + t_target2cam.push_back(Mat(t)); |
| 418 | + } |
| 419 | + } |
367 | 420 |
|
368 |
| - default: |
369 |
| - break; |
| 421 | + std::vector<Mat> R_gripper2base; |
| 422 | + std::vector<Mat> t_gripper2base; |
| 423 | + // Parse end-effector poses |
| 424 | + { |
| 425 | + std::ifstream file(end_effector_poses.c_str()); |
| 426 | + ASSERT_TRUE(file.is_open()); |
| 427 | + |
| 428 | + int ndata = 0; |
| 429 | + file >> ndata; |
| 430 | + R_gripper2base.reserve(ndata); |
| 431 | + t_gripper2base.reserve(ndata); |
| 432 | + |
| 433 | + Matx33d R; |
| 434 | + Matx31d t; |
| 435 | + Matx14d last_row; |
| 436 | + while (file >> |
| 437 | + R(0,0) >> R(0,1) >> R(0,2) >> t(0) >> |
| 438 | + R(1,0) >> R(1,1) >> R(1,2) >> t(1) >> |
| 439 | + R(2,0) >> R(2,1) >> R(2,2) >> t(2) >> |
| 440 | + last_row(0) >> last_row(1) >> last_row(2) >> last_row(3)) { |
| 441 | + R_gripper2base.push_back(Mat(R)); |
| 442 | + t_gripper2base.push_back(Mat(t)); |
| 443 | + } |
370 | 444 | }
|
371 | 445 |
|
372 |
| - return method_name; |
373 |
| -} |
| 446 | + std::vector<HandEyeCalibrationMethod> methods; |
| 447 | + methods.push_back(CALIB_HAND_EYE_TSAI); |
| 448 | + methods.push_back(CALIB_HAND_EYE_PARK); |
| 449 | + methods.push_back(CALIB_HAND_EYE_HORAUD); |
| 450 | + methods.push_back(CALIB_HAND_EYE_ANDREFF); |
| 451 | + methods.push_back(CALIB_HAND_EYE_DANIILIDIS); |
374 | 452 |
|
375 |
| -double CV_CalibrateHandEyeTest::sign_double(double val) |
376 |
| -{ |
377 |
| - return (0 < val) - (val < 0); |
378 |
| -} |
| 453 | + for (size_t idx = 0; idx < methods.size(); idx++) { |
| 454 | + SCOPED_TRACE(cv::format("method=%s", getMethodName(methods[idx]).c_str())); |
379 | 455 |
|
380 |
| -/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 456 | + Matx33d R_cam2gripper_est; |
| 457 | + Matx31d t_cam2gripper_est; |
| 458 | + calibrateHandEye(R_gripper2base, t_gripper2base, R_target2cam, t_target2cam, R_cam2gripper_est, t_cam2gripper_est, methods[idx]); |
381 | 459 |
|
382 |
| -TEST(Calib3d_CalibrateHandEye, regression) { CV_CalibrateHandEyeTest test; test.safe_run(); } |
| 460 | + EXPECT_TRUE(checkRange(R_cam2gripper_est)); |
| 461 | + EXPECT_TRUE(checkRange(t_cam2gripper_est)); |
| 462 | + } |
| 463 | +} |
383 | 464 |
|
384 | 465 | }} // namespace
|
0 commit comments