1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // @Authors
18 //    Fangfang Bai, fangfang@multicorewareinc.com
19 //    Jin Ma,       jin@multicorewareinc.com
20 //
21 // Redistribution and use in source and binary forms, with or without modification,
22 // are permitted provided that the following conditions are met:
23 //
24 //   * Redistribution's of source code must retain the above copyright notice,
25 //     this list of conditions and the following disclaimer.
26 //
27 //   * Redistribution's in binary form must reproduce the above copyright notice,
28 //     this list of conditions and the following disclaimer in the documentation
29 //     and/or other materials provided with the distribution.
30 //
31 //   * The name of the copyright holders may not be used to endorse or promote products
32 //     derived from this software without specific prior written permission.
33 //
34 // This software is provided by the copyright holders and contributors as is and
35 // any express or implied warranties, including, but not limited to, the implied
36 // warranties of merchantability and fitness for a particular purpose are disclaimed.
37 // In no event shall the Intel Corporation or contributors be liable for any direct,
38 // indirect, incidental, special, exemplary, or consequential damages
39 // (including, but not limited to, procurement of substitute goods or services;
40 // loss of use, data, or profits; or business interruption) however caused
41 // and on any theory of liability, whether in contract, strict liability,
42 // or tort (including negligence or otherwise) arising in any way out of
43 // the use of this software, even if advised of the possibility of such damage.
44 //
45 //M*/
46 
47 #include "../perf_precomp.hpp"
48 #include "opencv2/ts/ocl_perf.hpp"
49 
50 #ifdef HAVE_OPENCL
51 
52 namespace cvtest {
53 namespace ocl {
54 
55 ///////////// equalizeHist ////////////////////////
56 
57 typedef TestBaseWithParam<Size> EqualizeHistFixture;
58 
OCL_PERF_TEST_P(EqualizeHistFixture,EqualizeHist,OCL_TEST_SIZES)59 OCL_PERF_TEST_P(EqualizeHistFixture, EqualizeHist, OCL_TEST_SIZES)
60 {
61     const Size srcSize = GetParam();
62     const double eps = 1;
63 
64     checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
65 
66     UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
67     declare.in(src, WARMUP_RNG).out(dst);
68 
69     OCL_TEST_CYCLE() cv::equalizeHist(src, dst);
70 
71     SANITY_CHECK(dst, eps);
72 }
73 
74 ///////////// calcHist ////////////////////////
75 
76 typedef TestBaseWithParam<Size> CalcHistFixture;
77 
OCL_PERF_TEST_P(CalcHistFixture,CalcHist,OCL_TEST_SIZES)78 OCL_PERF_TEST_P(CalcHistFixture, CalcHist, OCL_TEST_SIZES)
79 {
80     const Size srcSize = GetParam();
81 
82     const std::vector<int> channels(1, 0);
83     std::vector<float> ranges(2);
84     std::vector<int> histSize(1, 256);
85     ranges[0] = 0;
86     ranges[1] = 256;
87 
88     checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
89 
90     UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1);
91     declare.in(src, WARMUP_RNG).out(hist);
92 
93     OCL_TEST_CYCLE() cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);
94 
95     SANITY_CHECK(hist);
96 }
97 
98 ///////////// calcHist ////////////////////////
99 
100 typedef TestBaseWithParam<Size> CalcBackProjFixture;
101 
OCL_PERF_TEST_P(CalcBackProjFixture,CalcBackProj,OCL_TEST_SIZES)102 OCL_PERF_TEST_P(CalcBackProjFixture, CalcBackProj, OCL_TEST_SIZES)
103 {
104     const Size srcSize = GetParam();
105 
106     const std::vector<int> channels(1, 0);
107     std::vector<float> ranges(2);
108     std::vector<int> histSize(1, 256);
109     ranges[0] = 0;
110     ranges[1] = 256;
111 
112     checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
113 
114     UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1), dst(srcSize, CV_8UC1);
115     declare.in(src, WARMUP_RNG).out(hist);
116 
117     cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);
118 
119     declare.in(src, WARMUP_RNG).out(dst);
120     OCL_TEST_CYCLE() cv::calcBackProject(std::vector<UMat>(1,src), channels, hist, dst, ranges, 1);
121 
122     SANITY_CHECK_NOTHING();
123 }
124 
125 
126 /////////// CopyMakeBorder //////////////////////
127 
128 CV_ENUM(Border, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WRAP, BORDER_REFLECT_101)
129 
130 typedef tuple<Size, MatType, Border> CopyMakeBorderParamType;
131 typedef TestBaseWithParam<CopyMakeBorderParamType> CopyMakeBorderFixture;
132 
OCL_PERF_TEST_P(CopyMakeBorderFixture,CopyMakeBorder,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES_134,Border::all ()))133 OCL_PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder,
134             ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, Border::all()))
135 {
136     const CopyMakeBorderParamType params = GetParam();
137     const Size srcSize = get<0>(params);
138     const int type = get<1>(params), borderType = get<2>(params);
139 
140     checkDeviceMaxMemoryAllocSize(srcSize, type);
141 
142     UMat src(srcSize, type), dst;
143     const Size dstSize = srcSize + Size(12, 12);
144     dst.create(dstSize, type);
145     declare.in(src, WARMUP_RNG).out(dst);
146 
147     OCL_TEST_CYCLE() cv::copyMakeBorder(src, dst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));
148 
149     SANITY_CHECK(dst);
150 }
151 
152 ///////////// CornerMinEigenVal ////////////////////////
153 
154 typedef Size_MatType CornerMinEigenValFixture;
155 
OCL_PERF_TEST_P(CornerMinEigenValFixture,CornerMinEigenVal,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_8UC1,CV_32FC1)))156 OCL_PERF_TEST_P(CornerMinEigenValFixture, CornerMinEigenVal,
157             ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
158 {
159     const Size_MatType_t params = GetParam();
160     const Size srcSize = get<0>(params);
161     const int type = get<1>(params), borderType = BORDER_REFLECT;
162     const int blockSize = 7, apertureSize = 1 + 2 * 3;
163 
164     checkDeviceMaxMemoryAllocSize(srcSize, type);
165 
166     UMat src(srcSize, type), dst(srcSize, CV_32FC1);
167     declare.in(src, WARMUP_RNG).out(dst);
168 
169     OCL_TEST_CYCLE() cv::cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);
170 
171     SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
172 }
173 
174 ///////////// CornerHarris ////////////////////////
175 
176 typedef Size_MatType CornerHarrisFixture;
177 
OCL_PERF_TEST_P(CornerHarrisFixture,CornerHarris,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_8UC1,CV_32FC1)))178 OCL_PERF_TEST_P(CornerHarrisFixture, CornerHarris,
179             ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
180 {
181     const Size_MatType_t params = GetParam();
182     const Size srcSize = get<0>(params);
183     const int type = get<1>(params), borderType = BORDER_REFLECT;
184 
185     checkDeviceMaxMemoryAllocSize(srcSize, type);
186 
187     UMat src(srcSize, type), dst(srcSize, CV_32FC1);
188     declare.in(src, WARMUP_RNG).out(dst);
189 
190     OCL_TEST_CYCLE() cv::cornerHarris(src, dst, 5, 7, 0.1, borderType);
191 
192     SANITY_CHECK(dst, 5e-6, ERROR_RELATIVE);
193 }
194 
195 ///////////// PreCornerDetect ////////////////////////
196 
197 typedef Size_MatType PreCornerDetectFixture;
198 
OCL_PERF_TEST_P(PreCornerDetectFixture,PreCornerDetect,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_8UC1,CV_32FC1)))199 OCL_PERF_TEST_P(PreCornerDetectFixture, PreCornerDetect,
200             ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
201 {
202     const Size_MatType_t params = GetParam();
203     const Size srcSize = get<0>(params);
204     const int type = get<1>(params), borderType = BORDER_REFLECT;
205 
206     checkDeviceMaxMemoryAllocSize(srcSize, type);
207 
208     UMat src(srcSize, type), dst(srcSize, CV_32FC1);
209     declare.in(src, WARMUP_RNG).out(dst);
210 
211     OCL_TEST_CYCLE() cv::preCornerDetect(src, dst, 3, borderType);
212 
213     SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
214 }
215 
216 ///////////// Integral ////////////////////////
217 
218 typedef tuple<Size, MatDepth> IntegralParams;
219 typedef TestBaseWithParam<IntegralParams> IntegralFixture;
220 
OCL_PERF_TEST_P(IntegralFixture,Integral1,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32S,CV_32F)))221 OCL_PERF_TEST_P(IntegralFixture, Integral1, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))
222 {
223     const IntegralParams params = GetParam();
224     const Size srcSize = get<0>(params);
225     const int ddepth = get<1>(params);
226 
227     checkDeviceMaxMemoryAllocSize(srcSize, ddepth);
228 
229     UMat src(srcSize, CV_8UC1), dst(srcSize + Size(1, 1), ddepth);
230     declare.in(src, WARMUP_RNG).out(dst);
231 
232     OCL_TEST_CYCLE() cv::integral(src, dst, ddepth);
233 
234     SANITY_CHECK(dst, 2e-6, ERROR_RELATIVE);
235 }
236 
OCL_PERF_TEST_P(IntegralFixture,Integral2,::testing::Combine (OCL_TEST_SIZES,OCL_PERF_ENUM (CV_32S,CV_32F)))237 OCL_PERF_TEST_P(IntegralFixture, Integral2, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))
238 {
239     const IntegralParams params = GetParam();
240     const Size srcSize = get<0>(params);
241     const int ddepth = get<1>(params);
242 
243     checkDeviceMaxMemoryAllocSize(srcSize, ddepth);
244 
245     UMat src(srcSize, CV_8UC1), sum(srcSize + Size(1, 1), ddepth), sqsum(srcSize + Size(1, 1), CV_32F);
246     declare.in(src, WARMUP_RNG).out(sum, sqsum);
247 
248     OCL_TEST_CYCLE() cv::integral(src, sum, sqsum, ddepth, CV_32F);
249 
250     SANITY_CHECK(sum, 2e-4, ERROR_RELATIVE);
251     SANITY_CHECK(sqsum, 5e-5, ERROR_RELATIVE);
252 }
253 
254 ///////////// Threshold ////////////////////////
255 
256 CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO_INV)
257 
258 typedef tuple<Size, MatType, ThreshType> ThreshParams;
259 typedef TestBaseWithParam<ThreshParams> ThreshFixture;
260 
OCL_PERF_TEST_P(ThreshFixture,Threshold,::testing::Combine (OCL_TEST_SIZES,OCL_TEST_TYPES,ThreshType::all ()))261 OCL_PERF_TEST_P(ThreshFixture, Threshold,
262             ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, ThreshType::all()))
263 {
264     const ThreshParams params = GetParam();
265     const Size srcSize = get<0>(params);
266     const int srcType = get<1>(params);
267     const int threshType = get<2>(params);
268     const double maxValue = 220.0, threshold = 50;
269 
270     checkDeviceMaxMemoryAllocSize(srcSize, srcType);
271 
272     UMat src(srcSize, srcType), dst(srcSize, srcType);
273     declare.in(src, WARMUP_RNG).out(dst);
274 
275     OCL_TEST_CYCLE() cv::threshold(src, dst, threshold, maxValue, threshType);
276 
277     SANITY_CHECK(dst);
278 }
279 
280 ///////////// CLAHE ////////////////////////
281 
282 typedef TestBaseWithParam<Size> CLAHEFixture;
283 
OCL_PERF_TEST_P(CLAHEFixture,CLAHE,OCL_TEST_SIZES)284 OCL_PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TEST_SIZES)
285 {
286     const Size srcSize = GetParam();
287 
288     checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
289 
290     UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
291     const double clipLimit = 40.0;
292     declare.in(src, WARMUP_RNG).out(dst);
293 
294     cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
295     OCL_TEST_CYCLE() clahe->apply(src, dst);
296 
297     SANITY_CHECK(dst);
298 }
299 
300 ///////////// Canny ////////////////////////
301 
302 typedef tuple<int, bool> CannyParams;
303 typedef TestBaseWithParam<CannyParams> CannyFixture;
304 
305 OCL_PERF_TEST_P(CannyFixture, Canny, ::testing::Combine(OCL_PERF_ENUM(3, 5), Bool()))
306 {
307     const CannyParams params = GetParam();
308     int apertureSize = get<0>(params);
309     bool L2Grad = get<1>(params);
310 
311     Mat _img = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE);
312     ASSERT_TRUE(!_img.empty()) << "can't open aloe-L.png";
313 
314     UMat img;
315     _img.copyTo(img);
316     UMat edges(img.size(), CV_8UC1);
317 
318     declare.in(img, WARMUP_RNG).out(edges);
319 
320     OCL_TEST_CYCLE() cv::Canny(img, edges, 50.0, 100.0, apertureSize, L2Grad);
321 
322     if (apertureSize == 3)
323         SANITY_CHECK(edges);
324     else
325         SANITY_CHECK_NOTHING();
326 }
327 
328 
329 } } // namespace cvtest::ocl
330 
331 #endif // HAVE_OPENCL
332