perf_matchTemplate.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "perf_precomp.hpp"
  5. namespace opencv_test {
  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> ImgSize_TmplSize_Method_t;
  8. typedef perf::TestBaseWithParam<ImgSize_TmplSize_Method_t> ImgSize_TmplSize_Method;
  9. PERF_TEST_P(ImgSize_TmplSize_Method, matchTemplateSmall,
  10. testing::Combine(
  11. testing::Values(szSmall128, cv::Size(320, 240),
  12. cv::Size(640, 480), cv::Size(800, 600),
  13. cv::Size(1024, 768), cv::Size(1280, 1024)),
  14. testing::Values(cv::Size(12, 12), cv::Size(28, 9),
  15. cv::Size(8, 30), cv::Size(16, 16)),
  16. MethodType::all()
  17. )
  18. )
  19. {
  20. Size imgSz = get<0>(GetParam());
  21. Size tmplSz = get<1>(GetParam());
  22. int method = get<2>(GetParam());
  23. Mat img(imgSz, CV_8UC1);
  24. Mat tmpl(tmplSz, CV_8UC1);
  25. Mat result(imgSz - tmplSz + Size(1,1), CV_32F);
  26. declare
  27. .in(img, WARMUP_RNG)
  28. .in(tmpl, WARMUP_RNG)
  29. .out(result)
  30. .time(30);
  31. TEST_CYCLE() matchTemplate(img, tmpl, result, method);
  32. bool isNormed =
  33. method == TM_CCORR_NORMED ||
  34. method == TM_SQDIFF_NORMED ||
  35. method == TM_CCOEFF_NORMED;
  36. double eps = isNormed ? 1e-5
  37. : 255 * 255 * tmpl.total() * 1e-6;
  38. SANITY_CHECK(result, eps);
  39. }
  40. PERF_TEST_P(ImgSize_TmplSize_Method, matchTemplateBig,
  41. testing::Combine(
  42. testing::Values(cv::Size(1280, 1024)),
  43. testing::Values(cv::Size(1260, 1000), cv::Size(1261, 1013)),
  44. MethodType::all()
  45. )
  46. )
  47. {
  48. Size imgSz = get<0>(GetParam());
  49. Size tmplSz = get<1>(GetParam());
  50. int method = get<2>(GetParam());
  51. Mat img(imgSz, CV_8UC1);
  52. Mat tmpl(tmplSz, CV_8UC1);
  53. Mat result(imgSz - tmplSz + Size(1,1), CV_32F);
  54. declare
  55. .in(img, WARMUP_RNG)
  56. .in(tmpl, WARMUP_RNG)
  57. .out(result)
  58. .time(30);
  59. TEST_CYCLE() matchTemplate(img, tmpl, result, method);
  60. bool isNormed =
  61. method == TM_CCORR_NORMED ||
  62. method == TM_SQDIFF_NORMED ||
  63. method == TM_CCOEFF_NORMED;
  64. double eps = isNormed ? 1e-6
  65. : 255.0 * 255.0 * (double)tmpl.total() * 1e-6;
  66. SANITY_CHECK(result, eps);
  67. }
  68. } // namespace