perf_matchTemplate.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "../perf_precomp.hpp"
  2. #include "opencv2/ts/ocl_perf.hpp"
  3. #ifdef HAVE_OPENCL
  4. namespace opencv_test {
  5. namespace ocl {
  6. CV_ENUM(MethodType, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED)
  7. typedef tuple<Size, Size, MethodType, MatType> ImgSize_TmplSize_Method_MatType_t;
  8. typedef TestBaseWithParam<ImgSize_TmplSize_Method_MatType_t> ImgSize_TmplSize_Method_MatType;
  9. OCL_PERF_TEST_P(ImgSize_TmplSize_Method_MatType, MatchTemplate,
  10. ::testing::Combine(
  11. testing::Values(cv::Size(640, 480), cv::Size(1280, 1024)),
  12. testing::Values(cv::Size(11, 11), cv::Size(16, 16), cv::Size(41, 41)),
  13. MethodType::all(),
  14. testing::Values(CV_8UC1, CV_8UC3, CV_32FC1, CV_32FC3)
  15. )
  16. )
  17. {
  18. const ImgSize_TmplSize_Method_MatType_t params = GetParam();
  19. const Size imgSz = get<0>(params), tmplSz = get<1>(params);
  20. const int method = get<2>(params);
  21. int type = get<3>(GetParam());
  22. UMat img(imgSz, type), tmpl(tmplSz, type);
  23. UMat result(imgSz - tmplSz + Size(1, 1), CV_32F);
  24. declare.in(img, tmpl, WARMUP_RNG).out(result);
  25. OCL_TEST_CYCLE() matchTemplate(img, tmpl, result, method);
  26. bool isNormed =
  27. method == TM_CCORR_NORMED ||
  28. method == TM_SQDIFF_NORMED ||
  29. method == TM_CCOEFF_NORMED;
  30. double eps = isNormed ? 3e-2
  31. : 255 * 255 * tmpl.total() * 1e-4;
  32. SANITY_CHECK(result, eps, ERROR_RELATIVE);
  33. }
  34. /////////// matchTemplate (performance tests from 2.4) ////////////////////////
  35. typedef Size_MatType CV_TM_CCORRFixture;
  36. OCL_PERF_TEST_P(CV_TM_CCORRFixture, matchTemplate,
  37. ::testing::Combine(::testing::Values(Size(1000, 1000), Size(2000, 2000)),
  38. OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))
  39. {
  40. const Size_MatType_t params = GetParam();
  41. const Size srcSize = get<0>(params), templSize(5, 5);
  42. const int type = get<1>(params);
  43. UMat src(srcSize, type), templ(templSize, type);
  44. const Size dstSize(src.cols - templ.cols + 1, src.rows - templ.rows + 1);
  45. UMat dst(dstSize, CV_32F);
  46. declare.in(src, templ, WARMUP_RNG).out(dst);
  47. OCL_TEST_CYCLE() cv::matchTemplate(src, templ, dst, CV_TM_CCORR);
  48. SANITY_CHECK(dst, 1e-4);
  49. }
  50. typedef TestBaseWithParam<Size> CV_TM_CCORR_NORMEDFixture;
  51. OCL_PERF_TEST_P(CV_TM_CCORR_NORMEDFixture, matchTemplate,
  52. ::testing::Values(Size(1000, 1000), Size(2000, 2000), Size(4000, 4000)))
  53. {
  54. const Size srcSize = GetParam(), templSize(5, 5);
  55. UMat src(srcSize, CV_8UC1), templ(templSize, CV_8UC1);
  56. const Size dstSize(src.cols - templ.cols + 1, src.rows - templ.rows + 1);
  57. UMat dst(dstSize, CV_8UC1);
  58. declare.in(src, templ, WARMUP_RNG).out(dst);
  59. OCL_TEST_CYCLE() cv::matchTemplate(src, templ, dst, CV_TM_CCORR_NORMED);
  60. SANITY_CHECK(dst, 3e-2);
  61. }
  62. } } // namespace
  63. #endif // HAVE_OPENCL