1 #include "perf_precomp.hpp" 2 3 using namespace std; 4 using namespace cv; 5 using namespace perf; 6 using std::tr1::make_tuple; 7 using std::tr1::get; 8 9 CV_ENUM(MethodType, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED) 10 11 typedef std::tr1::tuple<Size, Size, MethodType> ImgSize_TmplSize_Method_t; 12 typedef perf::TestBaseWithParam<ImgSize_TmplSize_Method_t> ImgSize_TmplSize_Method; 13 14 PERF_TEST_P(ImgSize_TmplSize_Method, matchTemplateSmall, 15 testing::Combine( 16 testing::Values(szSmall128, cv::Size(320, 240), 17 cv::Size(640, 480), cv::Size(800, 600), 18 cv::Size(1024, 768), cv::Size(1280, 1024)), 19 testing::Values(cv::Size(12, 12), cv::Size(28, 9), 20 cv::Size(8, 30), cv::Size(16, 16)), 21 MethodType::all() 22 ) 23 ) 24 { 25 Size imgSz = get<0>(GetParam()); 26 Size tmplSz = get<1>(GetParam()); 27 int method = get<2>(GetParam()); 28 29 Mat img(imgSz, CV_8UC1); 30 Mat tmpl(tmplSz, CV_8UC1); 31 Mat result(imgSz - tmplSz + Size(1,1), CV_32F); 32 33 declare 34 .in(img, WARMUP_RNG) 35 .in(tmpl, WARMUP_RNG) 36 .out(result) 37 .time(30); 38 39 TEST_CYCLE() matchTemplate(img, tmpl, result, method); 40 41 bool isNormed = 42 method == TM_CCORR_NORMED || 43 method == TM_SQDIFF_NORMED || 44 method == TM_CCOEFF_NORMED; 45 double eps = isNormed ? 1e-5 46 : 255 * 255 * tmpl.total() * 1e-6; 47 48 SANITY_CHECK(result, eps); 49 } 50 51 PERF_TEST_P(ImgSize_TmplSize_Method, matchTemplateBig, 52 testing::Combine( 53 testing::Values(cv::Size(1280, 1024)), 54 testing::Values(cv::Size(1260, 1000), cv::Size(1261, 1013)), 55 MethodType::all() 56 ) 57 ) 58 { 59 Size imgSz = get<0>(GetParam()); 60 Size tmplSz = get<1>(GetParam()); 61 int method = get<2>(GetParam()); 62 63 Mat img(imgSz, CV_8UC1); 64 Mat tmpl(tmplSz, CV_8UC1); 65 Mat result(imgSz - tmplSz + Size(1,1), CV_32F); 66 67 declare 68 .in(img, WARMUP_RNG) 69 .in(tmpl, WARMUP_RNG) 70 .out(result) 71 .time(30); 72 73 TEST_CYCLE() matchTemplate(img, tmpl, result, method); 74 75 bool isNormed = 76 method == TM_CCORR_NORMED || 77 method == TM_SQDIFF_NORMED || 78 method == TM_CCOEFF_NORMED; 79 double eps = isNormed ? 1e-6 80 : 255.0 * 255.0 * (double)tmpl.total() * 1e-6; 81 82 SANITY_CHECK(result, eps); 83 } 84