1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
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.
18 // Fangfang Bai, fangfang@multicorewareinc.com
19 // Jin Ma, jin@multicorewareinc.com
21 // Redistribution and use in source and binary forms, with or without modification,
22 // are permitted provided that the following conditions are met:
24 // * Redistribution's of source code must retain the above copyright notice,
25 // this list of conditions and the following disclaimer.
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 oclMaterials provided with the distribution.
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.
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.
46 #include "perf_precomp.hpp"
48 ///////////// Blur////////////////////////
51 Mat src1, dst, ocl_dst;
52 ocl::oclMat d_src1, d_dst;
54 Size ksize = Size(3, 3);
55 int bordertype = BORDER_CONSTANT;
56 int all_type[] = {CV_8UC1, CV_8UC4};
57 std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
59 for (int size = Min_Size; size <= Max_Size; size *= Multiple)
61 for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
63 SUBTEST << size << 'x' << size << "; " << type_name[j] ;
65 gen(src1, size, size, all_type[j], 0, 256);
66 gen(dst, size, size, all_type[j], 0, 256);
68 blur(src1, dst, ksize, Point(-1, -1), bordertype);
71 blur(src1, dst, ksize, Point(-1, -1), bordertype);
77 ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
81 ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
86 ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
87 d_dst.download(ocl_dst);
90 TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1.0);
95 ///////////// Laplacian////////////////////////
98 Mat src1, dst, ocl_dst;
99 ocl::oclMat d_src1, d_dst;
102 int all_type[] = {CV_8UC1, CV_8UC4};
103 std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
105 for (int size = Min_Size; size <= Max_Size; size *= Multiple)
107 for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
109 SUBTEST << size << 'x' << size << "; " << type_name[j] ;
111 gen(src1, size, size, all_type[j], 0, 256);
112 gen(dst, size, size, all_type[j], 0, 256);
114 Laplacian(src1, dst, -1, ksize, 1);
117 Laplacian(src1, dst, -1, ksize, 1);
123 ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
127 ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
132 ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
133 d_dst.download(ocl_dst);
136 TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);
142 ///////////// Erode ////////////////////
145 Mat src, dst, ker, ocl_dst;
146 ocl::oclMat d_src, d_dst;
148 int all_type[] = {CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4};
149 std::string type_name[] = {"CV_8UC1", "CV_8UC4", "CV_32FC1", "CV_32FC4"};
151 for (int size = Min_Size; size <= Max_Size; size *= Multiple)
153 for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
155 SUBTEST << size << 'x' << size << "; " << type_name[j] ;
157 gen(src, size, size, all_type[j], Scalar::all(0), Scalar::all(256));
158 ker = getStructuringElement(MORPH_RECT, Size(3, 3));
160 erode(src, dst, ker);
163 erode(src, dst, ker);
169 ocl::erode(d_src, d_dst, ker);
173 ocl::erode(d_src, d_dst, ker);
178 ocl::erode(d_src, d_dst, ker);
179 d_dst.download(ocl_dst);
182 TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);
188 ///////////// Sobel ////////////////////////
191 Mat src, dst, ocl_dst;
192 ocl::oclMat d_src, d_dst;
196 int all_type[] = {CV_8UC1, CV_8UC4};
197 std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
199 for (int size = Min_Size; size <= Max_Size; size *= Multiple)
201 for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
203 SUBTEST << size << 'x' << size << "; " << type_name[j] ;
205 gen(src, size, size, all_type[j], 0, 256);
207 Sobel(src, dst, -1, dx, dy);
210 Sobel(src, dst, -1, dx, dy);
216 ocl::Sobel(d_src, d_dst, -1, dx, dy);
220 ocl::Sobel(d_src, d_dst, -1, dx, dy);
225 ocl::Sobel(d_src, d_dst, -1, dx, dy);
226 d_dst.download(ocl_dst);
229 TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1);
234 ///////////// Scharr ////////////////////////
237 Mat src, dst, ocl_dst;
238 ocl::oclMat d_src, d_dst;
242 int all_type[] = {CV_8UC1, CV_8UC4};
243 std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
245 for (int size = Min_Size; size <= Max_Size; size *= Multiple)
247 for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
249 SUBTEST << size << 'x' << size << "; " << type_name[j] ;
251 gen(src, size, size, all_type[j], 0, 256);
253 Scharr(src, dst, -1, dx, dy);
256 Scharr(src, dst, -1, dx, dy);
262 ocl::Scharr(d_src, d_dst, -1, dx, dy);
266 ocl::Scharr(d_src, d_dst, -1, dx, dy);
271 ocl::Scharr(d_src, d_dst, -1, dx, dy);
272 d_dst.download(ocl_dst);
275 TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1);
281 ///////////// GaussianBlur ////////////////////////
282 PERFTEST(GaussianBlur)
284 Mat src, dst, ocl_dst;
285 int all_type[] = {CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4};
286 std::string type_name[] = {"CV_8UC1", "CV_8UC4", "CV_32FC1", "CV_32FC4"};
289 for (int size = Min_Size; size <= Max_Size; size *= Multiple)
291 for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
293 SUBTEST << size << 'x' << size << "; " << type_name[j] ;
295 gen(src, size, size, all_type[j], 0, 256);
297 GaussianBlur(src, dst, Size(ksize, ksize), 0);
300 GaussianBlur(src, dst, Size(ksize, ksize), 0);
303 ocl::oclMat d_src(src);
307 ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0);
311 ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0);
316 ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0);
317 d_dst.download(ocl_dst);
320 TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1.0);
326 ///////////// filter2D////////////////////////
331 for (int size = Min_Size; size <= Max_Size; size *= Multiple)
333 int all_type[] = {CV_8UC1, CV_8UC4};
334 std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
336 for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
338 gen(src, size, size, all_type[j], 0, 256);
342 SUBTEST << "ksize = " << ksize << "; " << size << 'x' << size << "; " << type_name[j] ;
345 gen(kernel, ksize, ksize, CV_32SC1, -3.0, 3.0);
349 cv::filter2D(src, dst, -1, kernel);
352 cv::filter2D(src, dst, -1, kernel);
355 ocl::oclMat d_src(src), d_dst;
358 ocl::filter2D(d_src, d_dst, -1, kernel);
362 ocl::filter2D(d_src, d_dst, -1, kernel);
367 ocl::filter2D(d_src, d_dst, -1, kernel);
368 d_dst.download(ocl_dst);
371 TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);