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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #include "test_precomp.hpp"
48 IMPLEMENT_PARAM_CLASS(KSize, cv::Size)
50 cv::Mat getInnerROI(cv::InputArray m_, cv::Size ksize)
52 cv::Mat m = getMat(m_);
53 cv::Rect roi(ksize.width, ksize.height, m.cols - 2 * ksize.width, m.rows - 2 * ksize.height);
57 cv::Mat getInnerROI(cv::InputArray m, int ksize)
59 return getInnerROI(m, cv::Size(ksize, ksize));
62 /////////////////////////////////////////////////////////////////////////////////////////////////
65 IMPLEMENT_PARAM_CLASS(Anchor, cv::Point)
67 PARAM_TEST_CASE(Blur, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Anchor, UseRoi)
69 cv::gpu::DeviceInfo devInfo;
78 devInfo = GET_PARAM(0);
82 anchor = GET_PARAM(4);
83 useRoi = GET_PARAM(5);
85 cv::gpu::setDevice(devInfo.deviceID());
89 TEST_P(Blur, Accuracy)
91 cv::Mat src = randomMat(size, type);
93 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
94 cv::gpu::blur(loadMat(src, useRoi), dst, ksize, anchor);
97 cv::blur(src, dst_gold, ksize, anchor);
99 EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 1.0);
102 INSTANTIATE_TEST_CASE_P(GPU_Filter, Blur, testing::Combine(
105 testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
106 testing::Values(KSize(cv::Size(3, 3)), KSize(cv::Size(5, 5)), KSize(cv::Size(7, 7))),
107 testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
110 /////////////////////////////////////////////////////////////////////////////////////////////////
113 IMPLEMENT_PARAM_CLASS(Deriv_X, int)
114 IMPLEMENT_PARAM_CLASS(Deriv_Y, int)
116 PARAM_TEST_CASE(Sobel, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Deriv_X, Deriv_Y, BorderType, UseRoi)
118 cv::gpu::DeviceInfo devInfo;
129 devInfo = GET_PARAM(0);
132 ksize = GET_PARAM(3);
135 borderType = GET_PARAM(6);
136 useRoi = GET_PARAM(7);
138 cv::gpu::setDevice(devInfo.deviceID());
142 TEST_P(Sobel, Accuracy)
144 if (dx == 0 && dy == 0)
147 cv::Mat src = randomMat(size, type);
149 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
150 cv::gpu::Sobel(loadMat(src, useRoi), dst, -1, dx, dy, ksize.width, 1.0, borderType);
153 cv::Sobel(src, dst_gold, -1, dx, dy, ksize.width, 1.0, 0.0, borderType);
155 EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.1);
158 INSTANTIATE_TEST_CASE_P(GPU_Filter, Sobel, testing::Combine(
161 testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
162 testing::Values(KSize(cv::Size(3, 3)), KSize(cv::Size(5, 5)), KSize(cv::Size(7, 7))),
163 testing::Values(Deriv_X(0), Deriv_X(1), Deriv_X(2)),
164 testing::Values(Deriv_Y(0), Deriv_Y(1), Deriv_Y(2)),
165 testing::Values(BorderType(cv::BORDER_REFLECT101),
166 BorderType(cv::BORDER_REPLICATE),
167 BorderType(cv::BORDER_CONSTANT),
168 BorderType(cv::BORDER_REFLECT)),
171 /////////////////////////////////////////////////////////////////////////////////////////////////
174 PARAM_TEST_CASE(Scharr, cv::gpu::DeviceInfo, cv::Size, MatType, Deriv_X, Deriv_Y, BorderType, UseRoi)
176 cv::gpu::DeviceInfo devInfo;
186 devInfo = GET_PARAM(0);
191 borderType = GET_PARAM(5);
192 useRoi = GET_PARAM(6);
194 cv::gpu::setDevice(devInfo.deviceID());
198 TEST_P(Scharr, Accuracy)
203 cv::Mat src = randomMat(size, type);
205 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
206 cv::gpu::Scharr(loadMat(src, useRoi), dst, -1, dx, dy, 1.0, borderType);
209 cv::Scharr(src, dst_gold, -1, dx, dy, 1.0, 0.0, borderType);
211 EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.1);
214 INSTANTIATE_TEST_CASE_P(GPU_Filter, Scharr, testing::Combine(
217 testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
218 testing::Values(Deriv_X(0), Deriv_X(1)),
219 testing::Values(Deriv_Y(0), Deriv_Y(1)),
220 testing::Values(BorderType(cv::BORDER_REFLECT101),
221 BorderType(cv::BORDER_REPLICATE),
222 BorderType(cv::BORDER_CONSTANT),
223 BorderType(cv::BORDER_REFLECT)),
226 /////////////////////////////////////////////////////////////////////////////////////////////////
229 PARAM_TEST_CASE(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, BorderType, UseRoi)
231 cv::gpu::DeviceInfo devInfo;
240 devInfo = GET_PARAM(0);
243 ksize = GET_PARAM(3);
244 borderType = GET_PARAM(4);
245 useRoi = GET_PARAM(5);
247 cv::gpu::setDevice(devInfo.deviceID());
251 TEST_P(GaussianBlur, Accuracy)
253 cv::Mat src = randomMat(size, type);
254 double sigma1 = randomDouble(0.1, 1.0);
255 double sigma2 = randomDouble(0.1, 1.0);
257 if (ksize.height > 16 && !supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
262 cv::gpu::GaussianBlur(loadMat(src), dst, ksize, sigma1, sigma2, borderType);
264 catch (const cv::Exception& e)
266 ASSERT_EQ(CV_StsNotImplemented, e.code);
271 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
272 cv::gpu::GaussianBlur(loadMat(src, useRoi), dst, ksize, sigma1, sigma2, borderType);
275 cv::GaussianBlur(src, dst_gold, ksize, sigma1, sigma2, borderType);
277 EXPECT_MAT_NEAR(dst_gold, dst, 4.0);
281 INSTANTIATE_TEST_CASE_P(GPU_Filter, GaussianBlur, testing::Combine(
284 testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
285 testing::Values(KSize(cv::Size(3, 3)),
286 KSize(cv::Size(5, 5)),
287 KSize(cv::Size(7, 7)),
288 KSize(cv::Size(9, 9)),
289 KSize(cv::Size(11, 11)),
290 KSize(cv::Size(13, 13)),
291 KSize(cv::Size(15, 15)),
292 KSize(cv::Size(17, 17)),
293 KSize(cv::Size(19, 19)),
294 KSize(cv::Size(21, 21)),
295 KSize(cv::Size(23, 23)),
296 KSize(cv::Size(25, 25)),
297 KSize(cv::Size(27, 27)),
298 KSize(cv::Size(29, 29)),
299 KSize(cv::Size(31, 31))),
300 testing::Values(BorderType(cv::BORDER_REFLECT101),
301 BorderType(cv::BORDER_REPLICATE),
302 BorderType(cv::BORDER_CONSTANT),
303 BorderType(cv::BORDER_REFLECT)),
306 /////////////////////////////////////////////////////////////////////////////////////////////////
309 PARAM_TEST_CASE(Laplacian, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, UseRoi)
311 cv::gpu::DeviceInfo devInfo;
319 devInfo = GET_PARAM(0);
322 ksize = GET_PARAM(3);
323 useRoi = GET_PARAM(4);
325 cv::gpu::setDevice(devInfo.deviceID());
329 TEST_P(Laplacian, Accuracy)
331 cv::Mat src = randomMat(size, type);
333 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
334 cv::gpu::Laplacian(loadMat(src, useRoi), dst, -1, ksize.width);
337 cv::Laplacian(src, dst_gold, -1, ksize.width);
339 EXPECT_MAT_NEAR(dst_gold, dst, src.depth() < CV_32F ? 0.0 : 1e-3);
342 INSTANTIATE_TEST_CASE_P(GPU_Filter, Laplacian, testing::Combine(
345 testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)),
346 testing::Values(KSize(cv::Size(1, 1)), KSize(cv::Size(3, 3))),
349 /////////////////////////////////////////////////////////////////////////////////////////////////
352 IMPLEMENT_PARAM_CLASS(Iterations, int)
354 PARAM_TEST_CASE(Erode, cv::gpu::DeviceInfo, cv::Size, MatType, Anchor, Iterations, UseRoi)
356 cv::gpu::DeviceInfo devInfo;
365 devInfo = GET_PARAM(0);
368 anchor = GET_PARAM(3);
369 iterations = GET_PARAM(4);
370 useRoi = GET_PARAM(5);
372 cv::gpu::setDevice(devInfo.deviceID());
376 TEST_P(Erode, Accuracy)
378 cv::Mat src = randomMat(size, type);
379 cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
381 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
382 cv::gpu::erode(loadMat(src, useRoi), dst, kernel, anchor, iterations);
385 cv::erode(src, dst_gold, kernel, anchor, iterations);
387 cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
389 EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
392 INSTANTIATE_TEST_CASE_P(GPU_Filter, Erode, testing::Combine(
395 testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
396 testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
397 testing::Values(Iterations(1), Iterations(2), Iterations(3)),
400 /////////////////////////////////////////////////////////////////////////////////////////////////
403 PARAM_TEST_CASE(Dilate, cv::gpu::DeviceInfo, cv::Size, MatType, Anchor, Iterations, UseRoi)
405 cv::gpu::DeviceInfo devInfo;
414 devInfo = GET_PARAM(0);
417 anchor = GET_PARAM(3);
418 iterations = GET_PARAM(4);
419 useRoi = GET_PARAM(5);
421 cv::gpu::setDevice(devInfo.deviceID());
425 TEST_P(Dilate, Accuracy)
427 cv::Mat src = randomMat(size, type);
428 cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
430 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
431 cv::gpu::dilate(loadMat(src, useRoi), dst, kernel, anchor, iterations);
434 cv::dilate(src, dst_gold, kernel, anchor, iterations);
436 cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
438 EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
441 INSTANTIATE_TEST_CASE_P(GPU_Filter, Dilate, testing::Combine(
444 testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
445 testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
446 testing::Values(Iterations(1), Iterations(2), Iterations(3)),
449 /////////////////////////////////////////////////////////////////////////////////////////////////
452 CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT)
453 #define ALL_MORPH_OPS testing::Values(MorphOp(cv::MORPH_OPEN), MorphOp(cv::MORPH_CLOSE), MorphOp(cv::MORPH_GRADIENT), MorphOp(cv::MORPH_TOPHAT), MorphOp(cv::MORPH_BLACKHAT))
455 PARAM_TEST_CASE(MorphEx, cv::gpu::DeviceInfo, cv::Size, MatType, MorphOp, Anchor, Iterations, UseRoi)
457 cv::gpu::DeviceInfo devInfo;
467 devInfo = GET_PARAM(0);
470 morphOp = GET_PARAM(3);
471 anchor = GET_PARAM(4);
472 iterations = GET_PARAM(5);
473 useRoi = GET_PARAM(6);
475 cv::gpu::setDevice(devInfo.deviceID());
479 TEST_P(MorphEx, Accuracy)
481 cv::Mat src = randomMat(size, type);
482 cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
484 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
485 cv::gpu::morphologyEx(loadMat(src, useRoi), dst, morphOp, kernel, anchor, iterations);
488 cv::morphologyEx(src, dst_gold, morphOp, kernel, anchor, iterations);
490 cv::Size border = cv::Size(kernel.cols + (iterations + 1) * kernel.cols + 2, kernel.rows + (iterations + 1) * kernel.rows + 2);
492 EXPECT_MAT_NEAR(getInnerROI(dst_gold, border), getInnerROI(dst, border), 0.0);
495 INSTANTIATE_TEST_CASE_P(GPU_Filter, MorphEx, testing::Combine(
498 testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
500 testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
501 testing::Values(Iterations(1), Iterations(2), Iterations(3)),
504 /////////////////////////////////////////////////////////////////////////////////////////////////
507 PARAM_TEST_CASE(Filter2D, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Anchor, BorderType, UseRoi)
509 cv::gpu::DeviceInfo devInfo;
521 devInfo = GET_PARAM(0);
524 ksize = GET_PARAM(3);
525 anchor = GET_PARAM(4);
526 borderType = GET_PARAM(5);
527 useRoi = GET_PARAM(6);
529 cv::gpu::setDevice(devInfo.deviceID());
533 TEST_P(Filter2D, Accuracy)
535 cv::Mat src = randomMat(size, type);
536 cv::Mat kernel = randomMat(cv::Size(ksize.width, ksize.height), CV_32FC1, 0.0, 1.0);
538 cv::gpu::GpuMat dst = createMat(size, type, useRoi);
539 cv::gpu::filter2D(loadMat(src, useRoi), dst, -1, kernel, anchor, borderType);
542 cv::filter2D(src, dst_gold, -1, kernel, anchor, 0, borderType);
544 EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) == CV_32F ? 1e-1 : 1.0);
547 INSTANTIATE_TEST_CASE_P(GPU_Filter, Filter2D, testing::Combine(
550 testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC4)),
551 testing::Values(KSize(cv::Size(3, 3)), KSize(cv::Size(5, 5)), KSize(cv::Size(7, 7)), KSize(cv::Size(11, 11)), KSize(cv::Size(13, 13)), KSize(cv::Size(15, 15))),
552 testing::Values(Anchor(cv::Point(-1, -1)), Anchor(cv::Point(0, 0)), Anchor(cv::Point(2, 2))),
553 testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT)),