Skip to content

Commit 2fed41d

Browse files
committed
imgproc(test): test bitExact cases in OCL/sepFilter2D
1 parent 6259ba1 commit 2fed41d

File tree

2 files changed

+89
-4
lines changed

2 files changed

+89
-4
lines changed

modules/imgproc/perf/opencl/perf_filters.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,62 @@ OCL_PERF_TEST_P(Filter2DFixture, Filter2D,
313313
SANITY_CHECK(dst, eps);
314314
}
315315

316+
///////////// SepFilter2D /////////////
317+
318+
typedef FilterFixture OCL_SepFilter2D;
319+
320+
PERF_TEST_P_(OCL_SepFilter2D, SepFilter2D)
321+
{
322+
const FilterParams& params = GetParam();
323+
const Size srcSize = get<0>(params);
324+
const int type = get<1>(params), ksize = get<2>(params);
325+
326+
checkDeviceMaxMemoryAllocSize(srcSize, type);
327+
328+
UMat src(srcSize, type), dst(srcSize, type);
329+
declare.in(src, WARMUP_RNG).out(dst);
330+
331+
Mat kernelX(1, ksize, CV_32FC1);
332+
randu(kernelX, -3.0, 3.0);
333+
Mat kernelY(1, ksize, CV_32FC1);
334+
randu(kernelY, -3.0, 3.0);
335+
336+
OCL_TEST_CYCLE() cv::sepFilter2D(src, dst, -1, kernelX, kernelY, cv::Point(-1, -1), 1.0f, cv::BORDER_CONSTANT);
337+
338+
SANITY_CHECK_NOTHING();
339+
}
340+
341+
PERF_TEST_P_(OCL_SepFilter2D, SepFilter2D_BitExact)
342+
{
343+
const FilterParams& params = GetParam();
344+
const Size srcSize = get<0>(params);
345+
const int type = get<1>(params), ksize = get<2>(params);
346+
347+
checkDeviceMaxMemoryAllocSize(srcSize, type);
348+
349+
UMat src(srcSize, type), dst(srcSize, type);
350+
declare.in(src, WARMUP_RNG).out(dst);
351+
352+
Mat kernelX(1, ksize, CV_32SC1);
353+
randu(kernelX, -16.0, 16.0);
354+
kernelX.convertTo(kernelX, CV_32FC1, 1/16.0f, 0);
355+
Mat kernelY(1, ksize, CV_32SC1);
356+
randu(kernelY, -16.0, 16.0);
357+
kernelY.convertTo(kernelY, CV_32FC1, 1/16.0f, 0);
358+
359+
OCL_TEST_CYCLE() cv::sepFilter2D(src, dst, -1, kernelX, kernelY, cv::Point(-1, -1), 1.0f, cv::BORDER_CONSTANT);
360+
361+
SANITY_CHECK_NOTHING();
362+
}
363+
364+
INSTANTIATE_TEST_CASE_P(/*nothing*/, OCL_SepFilter2D,
365+
::testing::Combine(
366+
::testing::Values(sz1080p),
367+
OCL_TEST_TYPES,
368+
OCL_PERF_ENUM(3, 5, 7, 9, 11)
369+
)
370+
);
371+
316372
///////////// Bilateral ////////////////////////
317373

318374
typedef TestBaseWithParam<Size> BilateralFixture;

modules/imgproc/test/ocl/test_sepfilter2d.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,27 @@ PARAM_TEST_CASE(SepFilter2D, MatDepth, Channels, BorderType, bool, bool)
7373
useRoi = GET_PARAM(4);
7474
}
7575

76-
void random_roi()
76+
void random_roi(bool bitExact)
7777
{
7878
Size ksize = randomSize(kernelMinSize, kernelMaxSize);
7979
if (1 != ksize.width % 2)
8080
ksize.width++;
8181
if (1 != ksize.height % 2)
8282
ksize.height++;
8383

84-
Mat temp = randomMat(Size(ksize.width, 1), CV_MAKE_TYPE(CV_32F, 1), -MAX_VALUE, MAX_VALUE);
84+
Mat temp = randomMat(Size(ksize.width, 1), CV_32FC1, -0.5, 1.0);
8585
cv::normalize(temp, kernelX, 1.0, 0.0, NORM_L1);
86-
temp = randomMat(Size(1, ksize.height), CV_MAKE_TYPE(CV_32F, 1), -MAX_VALUE, MAX_VALUE);
86+
temp = randomMat(Size(1, ksize.height), CV_32FC1, -0.5, 1.0);
8787
cv::normalize(temp, kernelY, 1.0, 0.0, NORM_L1);
8888

89+
if (bitExact)
90+
{
91+
kernelX.convertTo(temp, CV_32S, 256);
92+
temp.convertTo(kernelX, CV_32F, 1.0 / 256);
93+
kernelY.convertTo(temp, CV_32S, 256);
94+
temp.convertTo(kernelY, CV_32F, 1.0 / 256);
95+
}
96+
8997
Size roiSize = randomSize(ksize.width, MAX_VALUE, ksize.height, MAX_VALUE);
9098
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
9199
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
@@ -96,6 +104,11 @@ PARAM_TEST_CASE(SepFilter2D, MatDepth, Channels, BorderType, bool, bool)
96104
anchor.x = anchor.y = -1;
97105
delta = randomDouble(-100, 100);
98106

107+
if (bitExact)
108+
{
109+
delta = (int)(delta * 256) / 256.0;
110+
}
111+
99112
UMAT_UPLOAD_INPUT_PARAMETER(src);
100113
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
101114
}
@@ -110,7 +123,7 @@ OCL_TEST_P(SepFilter2D, Mat)
110123
{
111124
for (int j = 0; j < test_loop_times + 3; j++)
112125
{
113-
random_roi();
126+
random_roi(false);
114127

115128
OCL_OFF(cv::sepFilter2D(src_roi, dst_roi, -1, kernelX, kernelY, anchor, delta, borderType));
116129
OCL_ON(cv::sepFilter2D(usrc_roi, udst_roi, -1, kernelX, kernelY, anchor, delta, borderType));
@@ -119,6 +132,22 @@ OCL_TEST_P(SepFilter2D, Mat)
119132
}
120133
}
121134

135+
OCL_TEST_P(SepFilter2D, Mat_BitExact)
136+
{
137+
for (int j = 0; j < test_loop_times + 3; j++)
138+
{
139+
random_roi(true);
140+
141+
OCL_OFF(cv::sepFilter2D(src_roi, dst_roi, -1, kernelX, kernelY, anchor, delta, borderType));
142+
OCL_ON(cv::sepFilter2D(usrc_roi, udst_roi, -1, kernelX, kernelY, anchor, delta, borderType));
143+
144+
if (src_roi.depth() < CV_32F)
145+
Near(0.0);
146+
else
147+
Near(1e-3);
148+
}
149+
}
150+
122151
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, SepFilter2D,
123152
Combine(
124153
Values(CV_8U, CV_32F),

0 commit comments

Comments
 (0)