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