perf_ecc.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "perf_precomp.hpp"
  2. namespace opencv_test
  3. {
  4. using namespace perf;
  5. CV_ENUM(MotionType, MOTION_TRANSLATION, MOTION_EUCLIDEAN, MOTION_AFFINE, MOTION_HOMOGRAPHY)
  6. typedef tuple<MotionType> MotionType_t;
  7. typedef perf::TestBaseWithParam<MotionType_t> TransformationType;
  8. PERF_TEST_P(TransformationType, findTransformECC, /*testing::ValuesIn(MotionType::all())*/
  9. testing::Values((int) MOTION_TRANSLATION, (int) MOTION_EUCLIDEAN,
  10. (int) MOTION_AFFINE, (int) MOTION_HOMOGRAPHY)
  11. )
  12. {
  13. Mat img = imread(getDataPath("cv/shared/fruits_ecc.png"),0);
  14. Mat templateImage;
  15. int transform_type = get<0>(GetParam());
  16. Mat warpMat;
  17. Mat warpGround;
  18. double angle;
  19. switch (transform_type) {
  20. case MOTION_TRANSLATION:
  21. warpGround = (Mat_<float>(2,3) << 1.f, 0.f, 7.234f,
  22. 0.f, 1.f, 11.839f);
  23. warpAffine(img, templateImage, warpGround,
  24. Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
  25. break;
  26. case MOTION_EUCLIDEAN:
  27. angle = CV_PI/30;
  28. warpGround = (Mat_<float>(2,3) << (float)cos(angle), (float)-sin(angle), 12.123f,
  29. (float)sin(angle), (float)cos(angle), 14.789f);
  30. warpAffine(img, templateImage, warpGround,
  31. Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
  32. break;
  33. case MOTION_AFFINE:
  34. warpGround = (Mat_<float>(2,3) << 0.98f, 0.03f, 15.523f,
  35. -0.02f, 0.95f, 10.456f);
  36. warpAffine(img, templateImage, warpGround,
  37. Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
  38. break;
  39. case MOTION_HOMOGRAPHY:
  40. warpGround = (Mat_<float>(3,3) << 0.98f, 0.03f, 15.523f,
  41. -0.02f, 0.95f, 10.456f,
  42. 0.0002f, 0.0003f, 1.f);
  43. warpPerspective(img, templateImage, warpGround,
  44. Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
  45. break;
  46. }
  47. TEST_CYCLE()
  48. {
  49. if (transform_type<3)
  50. warpMat = Mat::eye(2,3, CV_32F);
  51. else
  52. warpMat = Mat::eye(3,3, CV_32F);
  53. findTransformECC(templateImage, img, warpMat, transform_type,
  54. TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 5, -1));
  55. }
  56. SANITY_CHECK(warpMat, 3e-3);
  57. }
  58. } // namespace