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-2013, Advanced Micro Devices, Inc., 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 the copyright holders 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 OpenCV Foundation 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"
43 #include "opencv2/ts/ocl_test.hpp"
52 //////////////////////////////// LUT /////////////////////////////////////////////////
54 PARAM_TEST_CASE(Lut, MatDepth, MatDepth, Channels, bool, bool)
56 int src_depth, lut_depth;
58 bool use_roi, same_cn;
60 TEST_DECLARE_INPUT_PARAMETER(src)
61 TEST_DECLARE_INPUT_PARAMETER(lut)
62 TEST_DECLARE_OUTPUT_PARAMETER(dst)
66 src_depth = GET_PARAM(0);
67 lut_depth = GET_PARAM(1);
69 same_cn = GET_PARAM(3);
70 use_roi = GET_PARAM(4);
73 void generateTestData()
75 const int src_type = CV_MAKE_TYPE(src_depth, cn);
76 const int lut_type = CV_MAKE_TYPE(lut_depth, same_cn ? cn : 1);
77 const int dst_type = CV_MAKE_TYPE(lut_depth, cn);
79 Size roiSize = randomSize(1, MAX_VALUE);
80 Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
81 randomSubMat(src, src_roi, roiSize, srcBorder, src_type, 0, 256);
83 Size lutRoiSize = Size(256, 1);
84 Border lutBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
85 randomSubMat(lut, lut_roi, lutRoiSize, lutBorder, lut_type, 5, 16);
87 Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
88 randomSubMat(dst, dst_roi, roiSize, dstBorder, dst_type, 5, 16);
90 UMAT_UPLOAD_INPUT_PARAMETER(src)
91 UMAT_UPLOAD_INPUT_PARAMETER(lut)
92 UMAT_UPLOAD_OUTPUT_PARAMETER(dst)
95 void Near(double threshold = 0.)
97 OCL_EXPECT_MATS_NEAR(dst, threshold)
103 for (int j = 0; j < test_loop_times; j++)
107 OCL_OFF(cv::LUT(src_roi, lut_roi, dst_roi));
108 OCL_ON(cv::LUT(usrc_roi, ulut_roi, udst_roi));
114 ///////////////////////// ArithmTestBase ///////////////////////////
116 PARAM_TEST_CASE(ArithmTestBase, MatDepth, Channels, bool)
122 cv::Scalar val_in_range;
124 TEST_DECLARE_INPUT_PARAMETER(src1)
125 TEST_DECLARE_INPUT_PARAMETER(src2)
126 TEST_DECLARE_INPUT_PARAMETER(mask)
127 TEST_DECLARE_OUTPUT_PARAMETER(dst1)
128 TEST_DECLARE_OUTPUT_PARAMETER(dst2)
132 depth = GET_PARAM(0);
134 use_roi = GET_PARAM(2);
137 virtual void generateTestData()
139 const int type = CV_MAKE_TYPE(depth, cn);
141 double minV = getMinVal(type);
142 double maxV = getMaxVal(type);
144 Size roiSize = randomSize(1, MAX_VALUE);
145 Border src1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
146 randomSubMat(src1, src1_roi, roiSize, src1Border, type, minV, maxV);
148 Border src2Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
149 randomSubMat(src2, src2_roi, roiSize, src2Border, type, std::max(-1540., minV), std::min(1740., maxV));
151 Border dst1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
152 randomSubMat(dst1, dst1_roi, roiSize, dst1Border, type, 5, 16);
154 Border dst2Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
155 randomSubMat(dst2, dst2_roi, roiSize, dst2Border, type, 5, 16);
157 Border maskBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
158 randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, 0, 2);
159 cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
161 val = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0),
162 rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0));
164 val_in_range = cv::Scalar(rng.uniform(minV, maxV), rng.uniform(minV, maxV),
165 rng.uniform(minV, maxV), rng.uniform(minV, maxV));
167 UMAT_UPLOAD_INPUT_PARAMETER(src1)
168 UMAT_UPLOAD_INPUT_PARAMETER(src2)
169 UMAT_UPLOAD_INPUT_PARAMETER(mask)
170 UMAT_UPLOAD_OUTPUT_PARAMETER(dst1)
171 UMAT_UPLOAD_OUTPUT_PARAMETER(dst2)
174 void Near(double threshold = 0.)
176 OCL_EXPECT_MATS_NEAR(dst1, threshold)
179 void Near1(double threshold = 0.)
181 OCL_EXPECT_MATS_NEAR(dst2, threshold)
185 //////////////////////////////// Add /////////////////////////////////////////////////
187 typedef ArithmTestBase Add;
191 for (int j = 0; j < test_loop_times; j++)
195 OCL_OFF(cv::add(src1_roi, src2_roi, dst1_roi));
196 OCL_ON(cv::add(usrc1_roi, usrc2_roi, udst1_roi));
201 OCL_TEST_P(Add, Mat_Mask)
203 for (int j = 0; j < test_loop_times; j++)
207 OCL_OFF(cv::add(src1_roi, src2_roi, dst1_roi, mask_roi));
208 OCL_ON(cv::add(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
213 OCL_TEST_P(Add, Scalar)
215 for (int j = 0; j < test_loop_times; j++)
219 OCL_OFF(cv::add(src1_roi, val, dst1_roi));
220 OCL_ON(cv::add(val, usrc1_roi, udst1_roi));
225 OCL_TEST_P(Add, Scalar_Mask)
227 for (int j = 0; j < test_loop_times; j++)
231 OCL_OFF(cv::add(src1_roi, val, dst1_roi, mask_roi));
232 OCL_ON(cv::add(usrc1_roi, val, udst1_roi, umask_roi));
237 //////////////////////////////////////// Subtract //////////////////////////////////////////////
239 typedef ArithmTestBase Subtract;
241 OCL_TEST_P(Subtract, Mat)
243 for (int j = 0; j < test_loop_times; j++)
247 OCL_OFF(cv::subtract(src1_roi, src2_roi, dst1_roi));
248 OCL_ON(cv::subtract(usrc1_roi, usrc2_roi, udst1_roi));
253 OCL_TEST_P(Subtract, Mat_Mask)
255 for (int j = 0; j < test_loop_times; j++)
259 OCL_OFF(cv::subtract(src1_roi, src2_roi, dst1_roi, mask_roi));
260 OCL_ON(cv::subtract(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
265 OCL_TEST_P(Subtract, Scalar)
267 for (int j = 0; j < test_loop_times; j++)
271 OCL_OFF(cv::subtract(val, src1_roi, dst1_roi));
272 OCL_ON(cv::subtract(val, usrc1_roi, udst1_roi));
277 OCL_TEST_P(Subtract, Scalar_Mask)
279 for (int j = 0; j < test_loop_times; j++)
283 OCL_OFF(cv::subtract(src1_roi, val, dst1_roi, mask_roi));
284 OCL_ON(cv::subtract(usrc1_roi, val, udst1_roi, umask_roi));
289 //////////////////////////////// Mul /////////////////////////////////////////////////
291 typedef ArithmTestBase Mul;
295 for (int j = 0; j < test_loop_times; j++)
299 OCL_OFF(cv::multiply(src1_roi, src2_roi, dst1_roi));
300 OCL_ON(cv::multiply(usrc1_roi, usrc2_roi, udst1_roi));
305 OCL_TEST_P(Mul, Scalar)
307 for (int j = 0; j < test_loop_times; j++)
311 OCL_OFF(cv::multiply(src1_roi, val, dst1_roi));
312 OCL_ON(cv::multiply(val, usrc1_roi, udst1_roi));
314 Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
318 OCL_TEST_P(Mul, Mat_Scale)
320 for (int j = 0; j < test_loop_times; j++)
324 OCL_OFF(cv::multiply(src1_roi, src2_roi, dst1_roi, val[0]));
325 OCL_ON(cv::multiply(usrc1_roi, usrc2_roi, udst1_roi, val[0]));
327 Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
331 OCL_TEST_P(Mul, Mat_Scalar_Scale)
333 for (int j = 0; j < test_loop_times; j++)
337 OCL_OFF(cv::multiply(src1_roi, val, dst1_roi, val[0]));
338 OCL_ON(cv::multiply(usrc1_roi, val, udst1_roi, val[0]));
340 Near(udst1_roi.depth() >= CV_32F ? 1e-2 : 1);
345 //////////////////////////////// Div /////////////////////////////////////////////////
347 typedef ArithmTestBase Div;
351 for (int j = 0; j < test_loop_times; j++)
355 OCL_OFF(cv::divide(src1_roi, src2_roi, dst1_roi));
356 OCL_ON(cv::divide(usrc1_roi, usrc2_roi, udst1_roi));
361 OCL_TEST_P(Div, Scalar)
363 for (int j = 0; j < test_loop_times; j++)
367 OCL_OFF(cv::divide(val, src1_roi, dst1_roi));
368 OCL_ON(cv::divide(val, usrc1_roi, udst1_roi));
370 Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
374 OCL_TEST_P(Div, Scalar2)
376 for (int j = 0; j < test_loop_times; j++)
380 OCL_OFF(cv::divide(src1_roi, val, dst1_roi));
381 OCL_ON(cv::divide(usrc1_roi, val, udst1_roi));
383 Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
387 OCL_TEST_P(Div, Mat_Scale)
389 for (int j = 0; j < test_loop_times; j++)
393 OCL_OFF(cv::divide(src1_roi, src2_roi, dst1_roi, val[0]));
394 OCL_ON(cv::divide(usrc1_roi, usrc2_roi, udst1_roi, val[0]));
396 Near(udst1_roi.depth() >= CV_32F ? 4e-3 : 1);
400 OCL_TEST_P(Div, Mat_Scalar_Scale)
402 for (int j = 0; j < test_loop_times; j++)
406 OCL_OFF(cv::divide(src1_roi, val, dst1_roi, val[0]));
407 OCL_ON(cv::divide(usrc1_roi, val, udst1_roi, val[0]));
409 Near(udst1_roi.depth() >= CV_32F ? 4e-3 : 1);
413 OCL_TEST_P(Div, Recip)
415 for (int j = 0; j < test_loop_times; j++)
419 OCL_OFF(cv::divide(val[0], src1_roi, dst1_roi));
420 OCL_ON(cv::divide(val[0], usrc1_roi, udst1_roi));
422 Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
426 //////////////////////////////// Min/Max /////////////////////////////////////////////////
428 typedef ArithmTestBase Min;
432 for (int j = 0; j < test_loop_times; j++)
436 OCL_OFF(cv::max(src1_roi, src2_roi, dst1_roi));
437 OCL_ON(cv::max(usrc1_roi, usrc2_roi, udst1_roi));
442 typedef ArithmTestBase Max;
446 for (int j = 0; j < test_loop_times; j++)
450 OCL_OFF(cv::min(src1_roi, src2_roi, dst1_roi));
451 OCL_ON(cv::min(usrc1_roi, usrc2_roi, udst1_roi));
456 //////////////////////////////// Absdiff /////////////////////////////////////////////////
458 typedef ArithmTestBase Absdiff;
460 OCL_TEST_P(Absdiff, Mat)
462 for (int j = 0; j < test_loop_times; j++)
466 OCL_OFF(cv::absdiff(src1_roi, src2_roi, dst1_roi));
467 OCL_ON(cv::absdiff(usrc1_roi, usrc2_roi, udst1_roi));
472 OCL_TEST_P(Absdiff, Scalar)
474 for (int j = 0; j < test_loop_times; j++)
478 OCL_OFF(cv::absdiff(src1_roi, val, dst1_roi));
479 OCL_ON(cv::absdiff(usrc1_roi, val, udst1_roi));
484 //////////////////////////////// CartToPolar /////////////////////////////////////////////////
486 typedef ArithmTestBase CartToPolar;
488 OCL_TEST_P(CartToPolar, angleInDegree)
490 for (int j = 0; j < test_loop_times; j++)
494 OCL_OFF(cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi, true));
495 OCL_ON(cv::cartToPolar(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi, true));
501 OCL_TEST_P(CartToPolar, angleInRadians)
503 for (int j = 0; j < test_loop_times; j++)
507 OCL_OFF(cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi));
508 OCL_ON(cv::cartToPolar(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi));
514 //////////////////////////////// PolarToCart /////////////////////////////////////////////////
516 typedef ArithmTestBase PolarToCart;
518 OCL_TEST_P(PolarToCart, angleInDegree)
520 for (int j = 0; j < test_loop_times; j++)
524 OCL_OFF(cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi, true));
525 OCL_ON(cv::polarToCart(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi, true));
532 OCL_TEST_P(PolarToCart, angleInRadians)
534 for (int j = 0; j < test_loop_times; j++)
538 OCL_OFF(cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi));
539 OCL_ON(cv::polarToCart(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi));
546 //////////////////////////////// Transpose /////////////////////////////////////////////////
548 typedef ArithmTestBase Transpose;
550 OCL_TEST_P(Transpose, Mat)
552 for (int j = 0; j < test_loop_times; j++)
556 OCL_OFF(cv::transpose(src1_roi, dst1_roi));
557 OCL_ON(cv::transpose(usrc1_roi, udst1_roi));
563 OCL_TEST_P(Transpose, SquareInplace)
565 const int type = CV_MAKE_TYPE(depth, cn);
567 for (int j = 0; j < test_loop_times; j++)
569 Size roiSize = randomSize(1, MAX_VALUE);
570 roiSize.height = roiSize.width; // make it square
572 Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
573 randomSubMat(src1, src1_roi, roiSize, srcBorder, type, 5, 16);
575 UMAT_UPLOAD_OUTPUT_PARAMETER(src1);
577 OCL_OFF(cv::transpose(src1_roi, src1_roi));
578 OCL_ON(cv::transpose(usrc1_roi, usrc1_roi));
580 OCL_EXPECT_MATS_NEAR(src1, 0)
584 //////////////////////////////// Bitwise_and /////////////////////////////////////////////////
586 typedef ArithmTestBase Bitwise_and;
588 OCL_TEST_P(Bitwise_and, Mat)
590 for (int j = 0; j < test_loop_times; j++)
594 OCL_OFF(cv::bitwise_and(src1_roi, src2_roi, dst1_roi));
595 OCL_ON(cv::bitwise_and(usrc1_roi, usrc2_roi, udst1_roi));
600 OCL_TEST_P(Bitwise_and, Mat_Mask)
602 for (int j = 0; j < test_loop_times; j++)
606 OCL_OFF(cv::bitwise_and(src1_roi, src2_roi, dst1_roi, mask_roi));
607 OCL_ON(cv::bitwise_and(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
612 OCL_TEST_P(Bitwise_and, Scalar)
614 for (int j = 0; j < test_loop_times; j++)
618 OCL_OFF(cv::bitwise_and(src1_roi, val, dst1_roi));
619 OCL_ON(cv::bitwise_and(usrc1_roi, val, udst1_roi));
624 OCL_TEST_P(Bitwise_and, Scalar_Mask)
626 for (int j = 0; j < test_loop_times; j++)
630 OCL_OFF(cv::bitwise_and(src1_roi, val, dst1_roi, mask_roi));
631 OCL_ON(cv::bitwise_and(usrc1_roi, val, udst1_roi, umask_roi));
636 //////////////////////////////// Bitwise_or /////////////////////////////////////////////////
638 typedef ArithmTestBase Bitwise_or;
640 OCL_TEST_P(Bitwise_or, Mat)
642 for (int j = 0; j < test_loop_times; j++)
646 OCL_OFF(cv::bitwise_or(src1_roi, src2_roi, dst1_roi));
647 OCL_ON(cv::bitwise_or(usrc1_roi, usrc2_roi, udst1_roi));
652 OCL_TEST_P(Bitwise_or, Mat_Mask)
654 for (int j = 0; j < test_loop_times; j++)
658 OCL_OFF(cv::bitwise_or(src1_roi, src2_roi, dst1_roi, mask_roi));
659 OCL_ON(cv::bitwise_or(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
664 OCL_TEST_P(Bitwise_or, Scalar)
666 for (int j = 0; j < test_loop_times; j++)
670 OCL_OFF(cv::bitwise_or(src1_roi, val, dst1_roi));
671 OCL_ON(cv::bitwise_or(usrc1_roi, val, udst1_roi));
676 OCL_TEST_P(Bitwise_or, Scalar_Mask)
678 for (int j = 0; j < test_loop_times; j++)
682 OCL_OFF(cv::bitwise_or(src1_roi, val, dst1_roi, mask_roi));
683 OCL_ON(cv::bitwise_or(val, usrc1_roi, udst1_roi, umask_roi));
688 //////////////////////////////// Bitwise_xor /////////////////////////////////////////////////
690 typedef ArithmTestBase Bitwise_xor;
692 OCL_TEST_P(Bitwise_xor, Mat)
694 for (int j = 0; j < test_loop_times; j++)
698 OCL_OFF(cv::bitwise_xor(src1_roi, src2_roi, dst1_roi));
699 OCL_ON(cv::bitwise_xor(usrc1_roi, usrc2_roi, udst1_roi));
704 OCL_TEST_P(Bitwise_xor, Mat_Mask)
706 for (int j = 0; j < test_loop_times; j++)
710 OCL_OFF(cv::bitwise_xor(src1_roi, src2_roi, dst1_roi, mask_roi));
711 OCL_ON(cv::bitwise_xor(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
716 OCL_TEST_P(Bitwise_xor, Scalar)
718 for (int j = 0; j < test_loop_times; j++)
722 OCL_OFF(cv::bitwise_xor(src1_roi, val, dst1_roi));
723 OCL_ON(cv::bitwise_xor(usrc1_roi, val, udst1_roi));
728 OCL_TEST_P(Bitwise_xor, Scalar_Mask)
730 for (int j = 0; j < test_loop_times; j++)
734 OCL_OFF(cv::bitwise_xor(src1_roi, val, dst1_roi, mask_roi));
735 OCL_ON(cv::bitwise_xor(usrc1_roi, val, udst1_roi, umask_roi));
740 //////////////////////////////// Bitwise_not /////////////////////////////////////////////////
742 typedef ArithmTestBase Bitwise_not;
744 OCL_TEST_P(Bitwise_not, Mat)
746 for (int j = 0; j < test_loop_times; j++)
750 OCL_OFF(cv::bitwise_not(src1_roi, dst1_roi));
751 OCL_ON(cv::bitwise_not(usrc1_roi, udst1_roi));
756 //////////////////////////////// Compare /////////////////////////////////////////////////
758 typedef ArithmTestBase Compare;
760 static const int cmp_codes[] = { CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE };
761 static const char* cmp_strs[] = { "CMP_EQ", "CMP_GT", "CMP_GE", "CMP_LT", "CMP_LE", "CMP_NE" };
762 static const int cmp_num = sizeof(cmp_codes) / sizeof(int);
764 OCL_TEST_P(Compare, Mat)
766 for (int i = 0; i < cmp_num; ++i)
768 SCOPED_TRACE(cmp_strs[i]);
769 for (int j = 0; j < test_loop_times; j++)
773 OCL_OFF(cv::compare(src1_roi, src2_roi, dst1_roi, cmp_codes[i]));
774 OCL_ON(cv::compare(usrc1_roi, usrc2_roi, udst1_roi, cmp_codes[i]));
781 OCL_TEST_P(Compare, Scalar)
783 for (int i = 0; i < cmp_num; ++i)
785 SCOPED_TRACE(cmp_strs[i]);
786 for (int j = 0; j < test_loop_times; j++)
790 OCL_OFF(cv::compare(src1_roi, val_in_range, dst1_roi, cmp_codes[i]));
791 OCL_ON(cv::compare(usrc1_roi, val_in_range, udst1_roi, cmp_codes[i]));
798 OCL_TEST_P(Compare, Scalar2)
800 for (int i = 0; i < cmp_num; ++i)
802 SCOPED_TRACE(cmp_strs[i]);
803 for (int j = 0; j < test_loop_times; j++)
807 OCL_OFF(cv::compare(val_in_range, src1_roi, dst1_roi, cmp_codes[i]));
808 OCL_ON(cv::compare(val_in_range, usrc1_roi, udst1_roi, cmp_codes[i]));
815 //////////////////////////////// Pow /////////////////////////////////////////////////
817 typedef ArithmTestBase Pow;
821 static const double pows[] = { -4, -1, -2.5, 0, 1, 2, 3.7, 4 };
823 for (int j = 0; j < test_loop_times; j++)
824 for (int k = 0, size = sizeof(pows) / sizeof(double); k < size; ++k)
828 OCL_OFF(cv::pow(src1_roi, pows[k], dst1_roi));
829 OCL_ON(cv::pow(usrc1_roi, pows[k], udst1_roi));
835 //////////////////////////////// AddWeighted /////////////////////////////////////////////////
837 typedef ArithmTestBase AddWeighted;
839 OCL_TEST_P(AddWeighted, Mat)
841 for (int j = 0; j < test_loop_times; j++)
845 const double alpha = 2.0, beta = 1.0, gama = 3.0;
847 OCL_OFF(cv::addWeighted(src1_roi, alpha, src2_roi, beta, gama, dst1_roi));
848 OCL_ON(cv::addWeighted(usrc1_roi, alpha, usrc2_roi, beta, gama, udst1_roi));
854 //////////////////////////////// setIdentity /////////////////////////////////////////////////
856 typedef ArithmTestBase SetIdentity;
858 OCL_TEST_P(SetIdentity, Mat)
860 for (int j = 0; j < test_loop_times; j++)
864 OCL_OFF(cv::setIdentity(dst1_roi, val));
865 OCL_ON(cv::setIdentity(udst1_roi, val));
873 struct RepeatTestCase :
874 public ArithmTestBase
878 virtual void generateTestData()
880 const int type = CV_MAKE_TYPE(depth, cn);
882 nx = randomInt(1, 4);
883 ny = randomInt(1, 4);
885 Size srcRoiSize = randomSize(1, MAX_VALUE);
886 Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
887 randomSubMat(src1, src1_roi, srcRoiSize, srcBorder, type, 2, 11);
889 Size dstRoiSize(srcRoiSize.width * nx, srcRoiSize.height * ny);
890 Border dst1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
891 randomSubMat(dst1, dst1_roi, dstRoiSize, dst1Border, type, 5, 16);
893 UMAT_UPLOAD_INPUT_PARAMETER(src1)
894 UMAT_UPLOAD_OUTPUT_PARAMETER(dst1)
898 typedef RepeatTestCase Repeat;
900 OCL_TEST_P(Repeat, Mat)
902 for (int i = 0; i < test_loop_times; ++i)
906 OCL_OFF(cv::repeat(src1_roi, ny, nx, dst1_roi));
907 OCL_ON(cv::repeat(usrc1_roi, ny, nx, udst1_roi));
913 //////////////////////////////// CountNonZero /////////////////////////////////////////////////
915 typedef ArithmTestBase CountNonZero;
917 OCL_TEST_P(CountNonZero, MAT)
919 for (int j = 0; j < test_loop_times; j++)
924 OCL_OFF(cpures = cv::countNonZero(src1_roi));
925 OCL_ON(gpures = cv::countNonZero(usrc1_roi));
927 EXPECT_EQ(cpures, gpures);
931 //////////////////////////////// Sum /////////////////////////////////////////////////
933 typedef ArithmTestBase Sum;
937 for (int j = 0; j < test_loop_times; j++)
941 Scalar cpures, gpures;
942 OCL_OFF(cpures = cv::sum(src1_roi));
943 OCL_ON(gpures = cv::sum(usrc1_roi));
945 for (int i = 0; i < cn; ++i)
946 EXPECT_NEAR(cpures[i], gpures[i], 0.1);
950 //////////////////////////////// meanStdDev /////////////////////////////////////////////////
952 typedef ArithmTestBase MeanStdDev;
954 OCL_TEST_P(MeanStdDev, Mat)
956 for (int j = 0; j < test_loop_times; j++)
960 Scalar cpu_mean, cpu_stddev;
961 Scalar gpu_mean, gpu_stddev;
963 OCL_OFF(cv::meanStdDev(src1_roi, cpu_mean, cpu_stddev));
964 OCL_ON(cv::meanStdDev(usrc1_roi, gpu_mean, gpu_stddev));
966 for (int i = 0; i < cn; ++i)
968 EXPECT_NEAR(cpu_mean[i], gpu_mean[i], 0.1);
969 EXPECT_NEAR(cpu_stddev[i], gpu_stddev[i], 0.1);
974 OCL_TEST_P(MeanStdDev, Mat_Mask)
976 for (int j = 0; j < test_loop_times; j++)
980 Scalar cpu_mean, cpu_stddev;
981 Scalar gpu_mean, gpu_stddev;
983 OCL_OFF(cv::meanStdDev(src1_roi, cpu_mean, cpu_stddev, mask_roi));
984 OCL_ON(cv::meanStdDev(usrc1_roi, gpu_mean, gpu_stddev, umask_roi));
986 for (int i = 0; i < cn; ++i)
988 EXPECT_NEAR(cpu_mean[i], gpu_mean[i], 0.1);
989 EXPECT_NEAR(cpu_stddev[i], gpu_stddev[i], 0.1);
994 OCL_TEST(MeanStdDev_, ZeroMask)
997 UMat um(size, CV_32SC1), umask(size, CV_8UC1, Scalar::all(0));
998 Mat m(size, CV_32SC1), mask(size, CV_8UC1, Scalar::all(0));
1000 Scalar cpu_mean, cpu_stddev;
1001 Scalar gpu_mean, gpu_stddev;
1003 OCL_OFF(cv::meanStdDev(m, cpu_mean, cpu_stddev, mask));
1004 OCL_ON(cv::meanStdDev(um, gpu_mean, gpu_stddev, umask));
1006 for (int i = 0; i < 4; ++i)
1008 EXPECT_NEAR(cpu_mean[i], gpu_mean[i], 0.1);
1009 EXPECT_NEAR(cpu_stddev[i], gpu_stddev[i], 0.1);
1013 //////////////////////////////////////// Log /////////////////////////////////////////
1015 typedef ArithmTestBase Log;
1017 OCL_TEST_P(Log, Mat)
1019 for (int j = 0; j < test_loop_times; j++)
1023 OCL_OFF(cv::log(src1_roi, dst1_roi));
1024 OCL_ON(cv::log(usrc1_roi, udst1_roi));
1029 //////////////////////////////////////// Exp /////////////////////////////////////////
1031 typedef ArithmTestBase Exp;
1033 OCL_TEST_P(Exp, Mat)
1035 for (int j = 0; j < test_loop_times; j++)
1039 OCL_OFF(cv::exp(src1_roi, dst1_roi));
1040 OCL_ON(cv::exp(usrc1_roi, udst1_roi));
1045 //////////////////////////////////////// Phase /////////////////////////////////////////
1047 typedef ArithmTestBase Phase;
1049 OCL_TEST_P(Phase, angleInDegree)
1051 for (int j = 0; j < test_loop_times; j++)
1055 OCL_OFF(cv::phase(src1_roi, src2_roi, dst1_roi, true));
1056 OCL_ON(cv::phase(usrc1_roi, usrc2_roi, udst1_roi, true));
1061 OCL_TEST_P(Phase, angleInRadians)
1063 for (int j = 0; j < test_loop_times; j++)
1067 OCL_OFF(cv::phase(src1_roi, src2_roi, dst1_roi));
1068 OCL_ON(cv::phase(usrc1_roi, usrc2_roi, udst1_roi));
1073 //////////////////////////////////////// Magnitude /////////////////////////////////////////
1075 typedef ArithmTestBase Magnitude;
1077 OCL_TEST_P(Magnitude, Mat)
1079 for (int j = 0; j < test_loop_times; j++)
1083 OCL_OFF(cv::magnitude(src1_roi, src2_roi, dst1_roi));
1084 OCL_ON(cv::magnitude(usrc1_roi, usrc2_roi, udst1_roi));
1085 Near(depth == CV_64F ? 1e-5 : 1e-2);
1089 //////////////////////////////// Flip /////////////////////////////////////////////////
1091 typedef ArithmTestBase Flip;
1095 for (int j = 0; j < test_loop_times; j++)
1099 OCL_OFF(cv::flip(src1_roi, dst1_roi, 0));
1100 OCL_ON(cv::flip(usrc1_roi, udst1_roi, 0));
1107 for (int j = 0; j < test_loop_times; j++)
1111 OCL_OFF(cv::flip(src1_roi, dst1_roi, 1));
1112 OCL_ON(cv::flip(usrc1_roi, udst1_roi, 1));
1117 OCL_TEST_P(Flip, BOTH)
1119 for (int j = 0; j < test_loop_times; j++)
1123 OCL_OFF(cv::flip(src1_roi, dst1_roi, -1));
1124 OCL_ON(cv::flip(usrc1_roi, udst1_roi, -1));
1128 //////////////////////////////////////// minMaxIdx /////////////////////////////////////////
1130 typedef ArithmTestBase MinMaxIdx;
1132 OCL_TEST_P(MinMaxIdx, Mat)
1134 for (int j = 0; j < test_loop_times; j++)
1138 int p1[2], p2[2], up1[2], up2[2];
1139 double minv, maxv, uminv, umaxv;
1141 if(src1_roi.channels() > 1)
1143 OCL_OFF(cv::minMaxIdx(src2_roi, &minv, &maxv) );
1144 OCL_ON(cv::minMaxIdx(usrc2_roi, &uminv, &umaxv));
1146 EXPECT_DOUBLE_EQ(minv, uminv);
1147 EXPECT_DOUBLE_EQ(maxv, umaxv);
1151 OCL_OFF(cv::minMaxIdx(src2_roi, &minv, &maxv, p1, p2, noArray()));
1152 OCL_ON(cv::minMaxIdx(usrc2_roi, &uminv, &umaxv, up1, up2, noArray()));
1154 EXPECT_DOUBLE_EQ(minv, uminv);
1155 EXPECT_DOUBLE_EQ(maxv, umaxv);
1156 for( int i = 0; i < 2; i++)
1158 EXPECT_EQ(p1[i], up1[i]);
1159 EXPECT_EQ(p2[i], up2[i]);
1165 typedef ArithmTestBase MinMaxIdx_Mask;
1167 OCL_TEST_P(MinMaxIdx_Mask, Mat)
1169 for (int j = 0; j < test_loop_times; j++)
1173 int p1[2], p2[2], up1[2], up2[2];
1174 double minv, maxv, uminv, umaxv;
1176 OCL_OFF(cv::minMaxIdx(src2_roi, &minv, &maxv, p1, p2, mask_roi));
1177 OCL_ON(cv::minMaxIdx(usrc2_roi, &uminv, &umaxv, up1, up2, umask_roi));
1179 EXPECT_DOUBLE_EQ(minv, uminv);
1180 EXPECT_DOUBLE_EQ(maxv, umaxv);
1181 for( int i = 0; i < 2; i++)
1183 EXPECT_EQ(p1[i], up1[i]);
1184 EXPECT_EQ(p2[i], up2[i]);
1190 //////////////////////////////// Norm /////////////////////////////////////////////////
1192 static bool relativeError(double actual, double expected, double eps)
1194 return std::abs(actual - expected) / actual < eps;
1197 typedef ArithmTestBase Norm;
1199 OCL_TEST_P(Norm, NORM_INF_1arg)
1201 for (int j = 0; j < test_loop_times; j++)
1205 OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_INF));
1206 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_INF));
1208 EXPECT_NEAR(cpuRes, gpuRes, 0.1);
1212 OCL_TEST_P(Norm, NORM_INF_1arg_mask)
1214 for (int j = 0; j < test_loop_times; j++)
1218 OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_INF, mask_roi));
1219 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_INF, umask_roi));
1221 EXPECT_NEAR(cpuRes, gpuRes, 0.1);
1225 OCL_TEST_P(Norm, NORM_L1_1arg)
1227 for (int j = 0; j < test_loop_times; j++)
1231 OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_L1));
1232 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_L1));
1234 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1238 OCL_TEST_P(Norm, NORM_L1_1arg_mask)
1240 for (int j = 0; j < test_loop_times; j++)
1244 OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_L1, mask_roi));
1245 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_L1, umask_roi));
1247 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1251 OCL_TEST_P(Norm, NORM_L2_1arg)
1253 for (int j = 0; j < test_loop_times; j++)
1257 OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_L2));
1258 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_L2));
1260 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1264 OCL_TEST_P(Norm, NORM_L2_1arg_mask)
1266 for (int j = 0; j < test_loop_times; j++)
1270 OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_L2, mask_roi));
1271 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_L2, umask_roi));
1273 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1277 OCL_TEST_P(Norm, NORM_INF_2args)
1279 for (int relative = 0; relative < 2; ++relative)
1280 for (int j = 0; j < test_loop_times; j++)
1284 int type = NORM_INF;
1286 type |= NORM_RELATIVE;
1288 OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type));
1289 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type));
1291 EXPECT_NEAR(cpuRes, gpuRes, 0.1);
1295 OCL_TEST_P(Norm, NORM_INF_2args_mask)
1297 for (int relative = 0; relative < 2; ++relative)
1298 for (int j = 0; j < test_loop_times; j++)
1302 int type = NORM_INF;
1304 type |= NORM_RELATIVE;
1306 OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type, mask_roi));
1307 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type, umask_roi));
1309 EXPECT_NEAR(cpuRes, gpuRes, 0.1);
1313 OCL_TEST_P(Norm, NORM_L1_2args)
1315 for (int relative = 0; relative < 2; ++relative)
1316 for (int j = 0; j < test_loop_times; j++)
1322 type |= NORM_RELATIVE;
1324 OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type));
1325 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type));
1327 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1331 OCL_TEST_P(Norm, NORM_L1_2args_mask)
1333 for (int relative = 0; relative < 2; ++relative)
1334 for (int j = 0; j < test_loop_times; j++)
1340 type |= NORM_RELATIVE;
1342 OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type, mask_roi));
1343 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type, umask_roi));
1345 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1349 OCL_TEST_P(Norm, NORM_L2_2args)
1351 for (int relative = 0; relative < 2; ++relative)
1352 for (int j = 0; j < test_loop_times; j++)
1358 type |= NORM_RELATIVE;
1360 OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type));
1361 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type));
1363 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1367 OCL_TEST_P(Norm, NORM_L2_2args_mask)
1369 for (int relative = 0; relative < 2; ++relative)
1370 for (int j = 0; j < test_loop_times; j++)
1376 type |= NORM_RELATIVE;
1378 OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type, mask_roi));
1379 OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type, umask_roi));
1381 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1385 //////////////////////////////// UMat::dot ////////////////////////////////////////////////
1387 typedef ArithmTestBase UMatDot;
1389 OCL_TEST_P(UMatDot, Mat)
1391 for (int j = 0; j < test_loop_times; j++)
1395 OCL_OFF(const double cpuRes = src1_roi.dot(src2_roi));
1396 OCL_ON(const double gpuRes = usrc1_roi.dot(usrc2_roi));
1398 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1402 //////////////////////////////// Sqrt ////////////////////////////////////////////////
1404 typedef ArithmTestBase Sqrt;
1406 OCL_TEST_P(Sqrt, Mat)
1408 for (int j = 0; j < test_loop_times; j++)
1412 OCL_OFF(cv::sqrt(src1_roi, dst1_roi));
1413 OCL_ON(cv::sqrt(usrc1_roi, udst1_roi));
1419 //////////////////////////////// Normalize ////////////////////////////////////////////////
1421 typedef ArithmTestBase Normalize;
1423 OCL_TEST_P(Normalize, Mat)
1425 static int modes[] = { CV_MINMAX, CV_L2, CV_L1, CV_C };
1427 for (int j = 0; j < test_loop_times; j++)
1431 for (int i = 0, size = sizeof(modes) / sizeof(modes[0]); i < size; ++i)
1433 OCL_OFF(cv::normalize(src1_roi, dst1_roi, 10, 110, modes[i], src1_roi.type(), mask_roi));
1434 OCL_ON(cv::normalize(usrc1_roi, udst1_roi, 10, 110, modes[i], src1_roi.type(), umask_roi));
1441 //////////////////////////////////////// InRange ///////////////////////////////////////////////
1443 PARAM_TEST_CASE(InRange, MatDepth, Channels, bool /*Scalar or not*/, bool /*Roi*/)
1447 bool scalars, use_roi;
1448 cv::Scalar val1, val2;
1450 TEST_DECLARE_INPUT_PARAMETER(src1)
1451 TEST_DECLARE_INPUT_PARAMETER(src2)
1452 TEST_DECLARE_INPUT_PARAMETER(src3)
1453 TEST_DECLARE_OUTPUT_PARAMETER(dst)
1455 virtual void SetUp()
1457 depth = GET_PARAM(0);
1459 scalars = GET_PARAM(2);
1460 use_roi = GET_PARAM(3);
1463 virtual void generateTestData()
1465 const int type = CV_MAKE_TYPE(depth, cn);
1467 Size roiSize = randomSize(1, MAX_VALUE);
1468 Border src1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
1469 randomSubMat(src1, src1_roi, roiSize, src1Border, type, -40, 40);
1471 Border src2Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
1472 randomSubMat(src2, src2_roi, roiSize, src2Border, type, -40, 40);
1474 Border src3Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
1475 randomSubMat(src3, src3_roi, roiSize, src3Border, type, -40, 40);
1477 Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1478 randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_8UC1, 5, 16);
1480 val1 = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0),
1481 rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0));
1482 val2 = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0),
1483 rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0));
1485 UMAT_UPLOAD_INPUT_PARAMETER(src1)
1486 UMAT_UPLOAD_INPUT_PARAMETER(src2)
1487 UMAT_UPLOAD_INPUT_PARAMETER(src3)
1488 UMAT_UPLOAD_OUTPUT_PARAMETER(dst)
1493 OCL_EXPECT_MATS_NEAR(dst, 0)
1497 OCL_TEST_P(InRange, Mat)
1499 for (int j = 0; j < test_loop_times; j++)
1503 OCL_OFF(cv::inRange(src1_roi, src2_roi, src3_roi, dst_roi));
1504 OCL_ON(cv::inRange(usrc1_roi, usrc2_roi, usrc3_roi, udst_roi));
1510 OCL_TEST_P(InRange, Scalar)
1512 for (int j = 0; j < test_loop_times; j++)
1516 OCL_OFF(cv::inRange(src1_roi, val1, val2, dst_roi));
1517 OCL_ON(cv::inRange(usrc1_roi, val1, val2, udst_roi));
1523 //////////////////////////////// ConvertScaleAbs ////////////////////////////////////////////////
1525 typedef ArithmTestBase ConvertScaleAbs;
1527 OCL_TEST_P(ConvertScaleAbs, Mat)
1529 for (int j = 0; j < test_loop_times; j++)
1533 OCL_OFF(cv::convertScaleAbs(src1_roi, dst1_roi, val[0], val[1]));
1534 OCL_ON(cv::convertScaleAbs(usrc1_roi, udst1_roi, val[0], val[1]));
1536 Near(depth <= CV_32S ? 1 : 1e-6);
1540 //////////////////////////////// ScaleAdd ////////////////////////////////////////////////
1542 typedef ArithmTestBase ScaleAdd;
1544 OCL_TEST_P(ScaleAdd, Mat)
1546 for (int j = 0; j < test_loop_times; j++)
1550 OCL_OFF(cv::scaleAdd(src1_roi, val[0], src2_roi, dst1_roi));
1551 OCL_ON(cv::scaleAdd(usrc1_roi, val[0], usrc2_roi, udst1_roi));
1553 Near(depth <= CV_32S ? 1 : 1e-3);
1557 //////////////////////////////// PatchNans ////////////////////////////////////////////////
1559 PARAM_TEST_CASE(PatchNaNs, Channels, bool)
1565 TEST_DECLARE_INPUT_PARAMETER(src)
1567 virtual void SetUp()
1570 use_roi = GET_PARAM(1);
1573 virtual void generateTestData()
1575 const int type = CV_MAKE_TYPE(CV_32F, cn);
1577 Size roiSize = randomSize(1, 10);
1578 Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1579 randomSubMat(src, src_roi, roiSize, srcBorder, type, -40, 40);
1582 roiSize.width *= cn;
1583 for (int y = 0; y < roiSize.height; ++y)
1585 float * const ptr = src_roi.ptr<float>(y);
1586 for (int x = 0; x < roiSize.width; ++x)
1587 ptr[x] = randomInt(-1, 1) == 0 ? std::numeric_limits<float>::quiet_NaN() : ptr[x];
1590 value = randomDouble(-100, 100);
1592 UMAT_UPLOAD_INPUT_PARAMETER(src)
1597 OCL_EXPECT_MATS_NEAR(src, 0)
1601 OCL_TEST_P(PatchNaNs, Mat)
1603 for (int j = 0; j < test_loop_times; j++)
1607 OCL_OFF(cv::patchNaNs(src_roi, value));
1608 OCL_ON(cv::patchNaNs(usrc_roi, value));
1614 //////////////////////////////// Psnr ////////////////////////////////////////////////
1616 typedef ArithmTestBase Psnr;
1618 OCL_TEST_P(Psnr, Mat)
1620 for (int j = 0; j < test_loop_times; j++)
1624 double cpuRes = 0, gpuRes = 0;
1626 OCL_OFF(cpuRes = cv::PSNR(src1_roi, src2_roi));
1627 OCL_ON(gpuRes = cv::PSNR(usrc1_roi, usrc2_roi));
1629 EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1633 //////////////////////////////////////// Reduce /////////////////////////////////////////////
1635 PARAM_TEST_CASE(Reduce, std::pair<MatDepth, MatDepth>, Channels, int, bool)
1637 int sdepth, ddepth, cn, dim, dtype;
1640 TEST_DECLARE_INPUT_PARAMETER(src)
1641 TEST_DECLARE_OUTPUT_PARAMETER(dst)
1643 virtual void SetUp()
1645 const std::pair<MatDepth, MatDepth> p = GET_PARAM(0);
1650 use_roi = GET_PARAM(3);
1653 virtual void generateTestData()
1655 const int stype = CV_MAKE_TYPE(sdepth, cn);
1656 dtype = CV_MAKE_TYPE(ddepth, cn);
1658 Size roiSize = randomSize(1, MAX_VALUE);
1659 Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1660 randomSubMat(src, src_roi, roiSize, srcBorder, stype, -40, 40);
1662 Size dstRoiSize = Size(dim == 0 ? roiSize.width : 1, dim == 0 ? 1 : roiSize.height);
1663 Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1664 randomSubMat(dst, dst_roi, dstRoiSize, dstBorder, dtype, 5, 16);
1666 UMAT_UPLOAD_INPUT_PARAMETER(src)
1667 UMAT_UPLOAD_OUTPUT_PARAMETER(dst)
1671 typedef Reduce ReduceSum;
1673 OCL_TEST_P(ReduceSum, Mat)
1675 for (int j = 0; j < test_loop_times; j++)
1679 OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_SUM, dtype));
1680 OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_SUM, dtype));
1682 double eps = ddepth <= CV_32S ? 1 : 1e-4;
1683 OCL_EXPECT_MATS_NEAR(dst, eps)
1687 typedef Reduce ReduceMax;
1689 OCL_TEST_P(ReduceMax, Mat)
1691 for (int j = 0; j < test_loop_times; j++)
1695 OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_MAX, dtype));
1696 OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_MAX, dtype));
1698 OCL_EXPECT_MATS_NEAR(dst, 0)
1702 typedef Reduce ReduceMin;
1704 OCL_TEST_P(ReduceMin, Mat)
1706 for (int j = 0; j < test_loop_times; j++)
1710 OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_MIN, dtype));
1711 OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_MIN, dtype));
1713 OCL_EXPECT_MATS_NEAR(dst, 0)
1717 typedef Reduce ReduceAvg;
1719 OCL_TEST_P(ReduceAvg, Mat)
1721 for (int j = 0; j < test_loop_times; j++)
1725 OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_AVG, dtype));
1726 OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_AVG, dtype));
1728 double eps = ddepth <= CV_32S ? 1 : 5e-6;
1729 OCL_EXPECT_MATS_NEAR(dst, eps)
1733 //////////////////////////////////////// Instantiation /////////////////////////////////////////
1735 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Lut, Combine(::testing::Values(CV_8U, CV_8S), OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool(), Bool()));
1736 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Add, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1737 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Subtract, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1738 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Mul, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1739 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Div, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1740 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Min, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1741 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Max, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1742 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Absdiff, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1743 OCL_INSTANTIATE_TEST_CASE_P(Arithm, CartToPolar, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1744 OCL_INSTANTIATE_TEST_CASE_P(Arithm, PolarToCart, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1745 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Transpose, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1746 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_and, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1747 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_not, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1748 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_xor, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1749 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_or, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1750 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Pow, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1751 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Compare, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1752 OCL_INSTANTIATE_TEST_CASE_P(Arithm, AddWeighted, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1753 OCL_INSTANTIATE_TEST_CASE_P(Arithm, SetIdentity, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1754 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Repeat, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1755 OCL_INSTANTIATE_TEST_CASE_P(Arithm, CountNonZero, Combine(OCL_ALL_DEPTHS, testing::Values(Channels(1)), Bool()));
1756 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Sum, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1757 OCL_INSTANTIATE_TEST_CASE_P(Arithm, MeanStdDev, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1758 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Log, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1759 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Exp, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1760 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Phase, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1761 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Magnitude, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1762 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Flip, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1763 OCL_INSTANTIATE_TEST_CASE_P(Arithm, MinMaxIdx, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1764 OCL_INSTANTIATE_TEST_CASE_P(Arithm, MinMaxIdx_Mask, Combine(OCL_ALL_DEPTHS, ::testing::Values(Channels(1)), Bool()));
1765 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Norm, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1766 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Sqrt, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1767 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Normalize, Combine(OCL_ALL_DEPTHS, Values(Channels(1)), Bool()));
1768 OCL_INSTANTIATE_TEST_CASE_P(Arithm, InRange, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool(), Bool()));
1769 OCL_INSTANTIATE_TEST_CASE_P(Arithm, ConvertScaleAbs, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1770 OCL_INSTANTIATE_TEST_CASE_P(Arithm, ScaleAdd, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1771 OCL_INSTANTIATE_TEST_CASE_P(Arithm, PatchNaNs, Combine(OCL_ALL_CHANNELS, Bool()));
1772 OCL_INSTANTIATE_TEST_CASE_P(Arithm, Psnr, Combine(::testing::Values((MatDepth)CV_8U), OCL_ALL_CHANNELS, Bool()));
1773 OCL_INSTANTIATE_TEST_CASE_P(Arithm, UMatDot, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1775 OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceSum, Combine(testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32S),
1776 std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F),
1777 std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F),
1778 std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F),
1779 std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F),
1780 std::make_pair<MatDepth, MatDepth>(CV_16S, CV_32F),
1781 std::make_pair<MatDepth, MatDepth>(CV_16S, CV_64F),
1782 std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F),
1783 std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F),
1784 std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F)),
1785 OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
1786 OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceAvg, Combine(testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32S),
1787 std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F),
1788 std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F),
1789 std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F),
1790 std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F),
1791 std::make_pair<MatDepth, MatDepth>(CV_16S, CV_32F),
1792 std::make_pair<MatDepth, MatDepth>(CV_16S, CV_64F),
1793 std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F),
1794 std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F),
1795 std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F)),
1796 OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
1797 OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceMax, Combine(testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_8U),
1798 std::make_pair<MatDepth, MatDepth>(CV_16U, CV_16U),
1799 std::make_pair<MatDepth, MatDepth>(CV_16S, CV_16S),
1800 std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F),
1801 std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F)),
1802 OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
1803 OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceMin, Combine(testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_8U),
1804 std::make_pair<MatDepth, MatDepth>(CV_16U, CV_16U),
1805 std::make_pair<MatDepth, MatDepth>(CV_16S, CV_16S),
1806 std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F),
1807 std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F)),
1808 OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
1811 } } // namespace cvtest::ocl
1813 #endif // HAVE_OPENCL