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