Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/core/test/ocl/test_arithm.cpp
16339 views
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-2013, Advanced Micro Devices, Inc., all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
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.
25
//
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.
28
//
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.
39
//
40
//M*/
41
42
#include "../test_precomp.hpp"
43
#include "opencv2/ts/ocl_test.hpp"
44
45
#ifdef HAVE_OPENCL
46
47
namespace opencv_test {
48
namespace ocl {
49
50
//////////////////////////////// LUT /////////////////////////////////////////////////
51
52
PARAM_TEST_CASE(Lut, MatDepth, MatDepth, Channels, bool, bool)
53
{
54
int src_depth, lut_depth;
55
int cn;
56
bool use_roi, same_cn;
57
58
TEST_DECLARE_INPUT_PARAMETER(src);
59
TEST_DECLARE_INPUT_PARAMETER(lut);
60
TEST_DECLARE_OUTPUT_PARAMETER(dst);
61
62
virtual void SetUp()
63
{
64
src_depth = GET_PARAM(0);
65
lut_depth = GET_PARAM(1);
66
cn = GET_PARAM(2);
67
same_cn = GET_PARAM(3);
68
use_roi = GET_PARAM(4);
69
}
70
71
void generateTestData()
72
{
73
const int src_type = CV_MAKE_TYPE(src_depth, cn);
74
const int lut_type = CV_MAKE_TYPE(lut_depth, same_cn ? cn : 1);
75
const int dst_type = CV_MAKE_TYPE(lut_depth, cn);
76
77
Size roiSize = randomSize(1, MAX_VALUE);
78
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
79
randomSubMat(src, src_roi, roiSize, srcBorder, src_type, 0, 256);
80
81
Size lutRoiSize = Size(256, 1);
82
Border lutBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
83
randomSubMat(lut, lut_roi, lutRoiSize, lutBorder, lut_type, 5, 16);
84
85
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
86
randomSubMat(dst, dst_roi, roiSize, dstBorder, dst_type, 5, 16);
87
88
UMAT_UPLOAD_INPUT_PARAMETER(src);
89
UMAT_UPLOAD_INPUT_PARAMETER(lut);
90
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
91
}
92
93
void Near(double threshold = 0.)
94
{
95
OCL_EXPECT_MATS_NEAR(dst, threshold);
96
}
97
};
98
99
OCL_TEST_P(Lut, Mat)
100
{
101
for (int j = 0; j < test_loop_times; j++)
102
{
103
generateTestData();
104
105
OCL_OFF(cv::LUT(src_roi, lut_roi, dst_roi));
106
OCL_ON(cv::LUT(usrc_roi, ulut_roi, udst_roi));
107
108
Near();
109
}
110
}
111
112
///////////////////////// ArithmTestBase ///////////////////////////
113
114
PARAM_TEST_CASE(ArithmTestBase, MatDepth, Channels, bool)
115
{
116
int depth;
117
int cn;
118
bool use_roi;
119
cv::Scalar val;
120
cv::Scalar val_in_range;
121
122
TEST_DECLARE_INPUT_PARAMETER(src1);
123
TEST_DECLARE_INPUT_PARAMETER(src2);
124
TEST_DECLARE_INPUT_PARAMETER(mask);
125
TEST_DECLARE_OUTPUT_PARAMETER(dst1);
126
TEST_DECLARE_OUTPUT_PARAMETER(dst2);
127
128
virtual void SetUp()
129
{
130
depth = GET_PARAM(0);
131
cn = GET_PARAM(1);
132
use_roi = GET_PARAM(2);
133
}
134
135
void generateTestData(bool with_val_in_range = false)
136
{
137
const int type = CV_MAKE_TYPE(depth, cn);
138
139
double minV = cvtest::getMinVal(type);
140
double maxV = cvtest::getMaxVal(type);
141
142
Size roiSize = randomSize(1, MAX_VALUE);
143
Border src1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
144
randomSubMat(src1, src1_roi, roiSize, src1Border, type, 2, 11); // FIXIT: Test with minV, maxV
145
146
Border src2Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
147
randomSubMat(src2, src2_roi, roiSize, src2Border, type, std::max(-1540., minV), std::min(1740., maxV));
148
149
Border dst1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
150
randomSubMat(dst1, dst1_roi, roiSize, dst1Border, type, 5, 16);
151
152
Border dst2Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
153
randomSubMat(dst2, dst2_roi, roiSize, dst2Border, type, 5, 16);
154
155
Border maskBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
156
randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, 0, 2);
157
cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
158
*mask.ptr(0) = 255; // prevent test case with mask filled 0 only
159
160
val = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0),
161
rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0));
162
163
if (with_val_in_range)
164
{
165
val_in_range = cv::Scalar(rng.uniform(minV, maxV), rng.uniform(minV, maxV),
166
rng.uniform(minV, maxV), rng.uniform(minV, maxV));
167
}
168
169
UMAT_UPLOAD_INPUT_PARAMETER(src1);
170
UMAT_UPLOAD_INPUT_PARAMETER(src2);
171
UMAT_UPLOAD_INPUT_PARAMETER(mask);
172
UMAT_UPLOAD_OUTPUT_PARAMETER(dst1);
173
UMAT_UPLOAD_OUTPUT_PARAMETER(dst2);
174
}
175
176
void Near(double threshold = 0., bool relative = false)
177
{
178
if (!relative)
179
OCL_EXPECT_MATS_NEAR(dst1, threshold);
180
else
181
OCL_EXPECT_MATS_NEAR_RELATIVE(dst1, threshold);
182
}
183
184
void Near1(double threshold = 0.)
185
{
186
OCL_EXPECT_MATS_NEAR(dst2, threshold);
187
}
188
};
189
190
//////////////////////////////// Add /////////////////////////////////////////////////
191
192
typedef ArithmTestBase Add;
193
194
OCL_TEST_P(Add, Mat)
195
{
196
for (int j = 0; j < test_loop_times; j++)
197
{
198
generateTestData();
199
200
OCL_OFF(cv::add(src1_roi, src2_roi, dst1_roi));
201
OCL_ON(cv::add(usrc1_roi, usrc2_roi, udst1_roi));
202
Near(0);
203
}
204
}
205
206
OCL_TEST_P(Add, Mat_Mask)
207
{
208
for (int j = 0; j < test_loop_times; j++)
209
{
210
generateTestData();
211
212
OCL_OFF(cv::add(src1_roi, src2_roi, dst1_roi, mask_roi));
213
OCL_ON(cv::add(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
214
Near(0);
215
}
216
}
217
218
OCL_TEST_P(Add, Scalar)
219
{
220
for (int j = 0; j < test_loop_times; j++)
221
{
222
generateTestData();
223
224
OCL_OFF(cv::add(src1_roi, val, dst1_roi));
225
OCL_ON(cv::add(val, usrc1_roi, udst1_roi));
226
Near(1e-5);
227
}
228
}
229
230
OCL_TEST_P(Add, Scalar_Mask)
231
{
232
for (int j = 0; j < test_loop_times; j++)
233
{
234
generateTestData();
235
236
OCL_OFF(cv::add(src1_roi, val, dst1_roi, mask_roi));
237
OCL_ON(cv::add(usrc1_roi, val, udst1_roi, umask_roi));
238
Near(1e-5);
239
}
240
}
241
242
//////////////////////////////////////// Subtract //////////////////////////////////////////////
243
244
typedef ArithmTestBase Subtract;
245
246
OCL_TEST_P(Subtract, Mat)
247
{
248
for (int j = 0; j < test_loop_times; j++)
249
{
250
generateTestData();
251
252
OCL_OFF(cv::subtract(src1_roi, src2_roi, dst1_roi));
253
OCL_ON(cv::subtract(usrc1_roi, usrc2_roi, udst1_roi));
254
Near(0);
255
}
256
}
257
258
OCL_TEST_P(Subtract, Mat_Mask)
259
{
260
for (int j = 0; j < test_loop_times; j++)
261
{
262
generateTestData();
263
264
OCL_OFF(cv::subtract(src1_roi, src2_roi, dst1_roi, mask_roi));
265
OCL_ON(cv::subtract(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
266
Near(0);
267
}
268
}
269
270
OCL_TEST_P(Subtract, Scalar)
271
{
272
for (int j = 0; j < test_loop_times; j++)
273
{
274
generateTestData();
275
276
OCL_OFF(cv::subtract(val, src1_roi, dst1_roi));
277
OCL_ON(cv::subtract(val, usrc1_roi, udst1_roi));
278
Near(1e-5);
279
}
280
}
281
282
OCL_TEST_P(Subtract, Scalar_Mask)
283
{
284
for (int j = 0; j < test_loop_times; j++)
285
{
286
generateTestData();
287
288
OCL_OFF(cv::subtract(src1_roi, val, dst1_roi, mask_roi));
289
OCL_ON(cv::subtract(usrc1_roi, val, udst1_roi, umask_roi));
290
Near(1e-5);
291
}
292
}
293
294
//////////////////////////////// Mul /////////////////////////////////////////////////
295
296
typedef ArithmTestBase Mul;
297
298
OCL_TEST_P(Mul, Mat)
299
{
300
for (int j = 0; j < test_loop_times; j++)
301
{
302
generateTestData();
303
304
OCL_OFF(cv::multiply(src1_roi, src2_roi, dst1_roi));
305
OCL_ON(cv::multiply(usrc1_roi, usrc2_roi, udst1_roi));
306
Near(0);
307
}
308
}
309
310
OCL_TEST_P(Mul, Scalar)
311
{
312
for (int j = 0; j < test_loop_times; j++)
313
{
314
generateTestData();
315
316
OCL_OFF(cv::multiply(src1_roi, val, dst1_roi));
317
OCL_ON(cv::multiply(val, usrc1_roi, udst1_roi));
318
319
Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
320
}
321
}
322
323
OCL_TEST_P(Mul, Mat_Scale)
324
{
325
for (int j = 0; j < test_loop_times; j++)
326
{
327
generateTestData();
328
329
OCL_OFF(cv::multiply(src1_roi, src2_roi, dst1_roi, val[0]));
330
OCL_ON(cv::multiply(usrc1_roi, usrc2_roi, udst1_roi, val[0]));
331
332
if (udst1_roi.depth() >= CV_32F)
333
#ifdef __ANDROID__
334
Near(2e-1, true);
335
#else
336
Near(1e-3, true);
337
#endif
338
else
339
Near(1);
340
}
341
}
342
343
OCL_TEST_P(Mul, Mat_Scalar_Scale)
344
{
345
for (int j = 0; j < test_loop_times; j++)
346
{
347
generateTestData();
348
349
OCL_OFF(cv::multiply(src1_roi, val, dst1_roi, val[0]));
350
OCL_ON(cv::multiply(usrc1_roi, val, udst1_roi, val[0]));
351
352
if (udst1_roi.depth() >= CV_32F)
353
Near(1e-6, true);
354
else
355
Near(1);
356
}
357
}
358
359
360
//////////////////////////////// Div /////////////////////////////////////////////////
361
362
typedef ArithmTestBase Div;
363
364
OCL_TEST_P(Div, Mat)
365
{
366
for (int j = 0; j < test_loop_times; j++)
367
{
368
generateTestData();
369
370
OCL_OFF(cv::divide(src1_roi, src2_roi, dst1_roi));
371
OCL_ON(cv::divide(usrc1_roi, usrc2_roi, udst1_roi));
372
Near(1);
373
}
374
}
375
376
OCL_TEST_P(Div, Scalar)
377
{
378
for (int j = 0; j < test_loop_times; j++)
379
{
380
generateTestData();
381
382
OCL_OFF(cv::divide(val, src1_roi, dst1_roi));
383
OCL_ON(cv::divide(val, usrc1_roi, udst1_roi));
384
385
Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
386
}
387
}
388
389
OCL_TEST_P(Div, Scalar2)
390
{
391
for (int j = 0; j < test_loop_times; j++)
392
{
393
generateTestData();
394
395
OCL_OFF(cv::divide(src1_roi, val, dst1_roi));
396
OCL_ON(cv::divide(usrc1_roi, val, udst1_roi));
397
398
Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
399
}
400
}
401
402
OCL_TEST_P(Div, Mat_Scale)
403
{
404
for (int j = 0; j < test_loop_times; j++)
405
{
406
generateTestData();
407
408
OCL_OFF(cv::divide(src1_roi, src2_roi, dst1_roi, val[0]));
409
OCL_ON(cv::divide(usrc1_roi, usrc2_roi, udst1_roi, val[0]));
410
411
Near(udst1_roi.depth() >= CV_32F ? 4e-3 : 1);
412
}
413
}
414
415
OCL_TEST_P(Div, Mat_Scalar_Scale)
416
{
417
for (int j = 0; j < test_loop_times; j++)
418
{
419
generateTestData();
420
421
OCL_OFF(cv::divide(src1_roi, val, dst1_roi, val[0]));
422
OCL_ON(cv::divide(usrc1_roi, val, udst1_roi, val[0]));
423
424
Near(udst1_roi.depth() >= CV_32F ? 4e-3 : 1);
425
}
426
}
427
428
OCL_TEST_P(Div, Recip)
429
{
430
for (int j = 0; j < test_loop_times; j++)
431
{
432
generateTestData();
433
434
OCL_OFF(cv::divide(val[0], src1_roi, dst1_roi));
435
OCL_ON(cv::divide(val[0], usrc1_roi, udst1_roi));
436
437
Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
438
}
439
}
440
441
//////////////////////////////// Min/Max /////////////////////////////////////////////////
442
443
typedef ArithmTestBase Min;
444
445
OCL_TEST_P(Min, Mat)
446
{
447
for (int j = 0; j < test_loop_times; j++)
448
{
449
generateTestData();
450
451
OCL_OFF(cv::min(src1_roi, src2_roi, dst1_roi));
452
OCL_ON(cv::min(usrc1_roi, usrc2_roi, udst1_roi));
453
Near(0);
454
}
455
}
456
457
typedef ArithmTestBase Max;
458
459
OCL_TEST_P(Max, Mat)
460
{
461
for (int j = 0; j < test_loop_times; j++)
462
{
463
generateTestData();
464
465
OCL_OFF(cv::max(src1_roi, src2_roi, dst1_roi));
466
OCL_ON(cv::max(usrc1_roi, usrc2_roi, udst1_roi));
467
Near(0);
468
}
469
}
470
471
//////////////////////////////// Absdiff /////////////////////////////////////////////////
472
473
typedef ArithmTestBase Absdiff;
474
475
OCL_TEST_P(Absdiff, Mat)
476
{
477
for (int j = 0; j < test_loop_times; j++)
478
{
479
generateTestData();
480
481
OCL_OFF(cv::absdiff(src1_roi, src2_roi, dst1_roi));
482
OCL_ON(cv::absdiff(usrc1_roi, usrc2_roi, udst1_roi));
483
Near(0);
484
}
485
}
486
487
OCL_TEST_P(Absdiff, Scalar)
488
{
489
for (int j = 0; j < test_loop_times; j++)
490
{
491
generateTestData();
492
493
OCL_OFF(cv::absdiff(src1_roi, val, dst1_roi));
494
OCL_ON(cv::absdiff(usrc1_roi, val, udst1_roi));
495
Near(1e-5);
496
}
497
}
498
499
//////////////////////////////// CartToPolar /////////////////////////////////////////////////
500
501
typedef ArithmTestBase CartToPolar;
502
503
OCL_TEST_P(CartToPolar, angleInDegree)
504
{
505
for (int j = 0; j < test_loop_times; j++)
506
{
507
generateTestData();
508
509
OCL_OFF(cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi, true));
510
OCL_ON(cv::cartToPolar(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi, true));
511
Near(0.5);
512
Near1(0.5);
513
}
514
}
515
516
OCL_TEST_P(CartToPolar, angleInRadians)
517
{
518
for (int j = 0; j < test_loop_times; j++)
519
{
520
generateTestData();
521
522
OCL_OFF(cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi));
523
OCL_ON(cv::cartToPolar(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi));
524
Near(0.5);
525
Near1(0.5);
526
}
527
}
528
529
//////////////////////////////// PolarToCart /////////////////////////////////////////////////
530
531
typedef ArithmTestBase PolarToCart;
532
533
OCL_TEST_P(PolarToCart, angleInDegree)
534
{
535
for (int j = 0; j < test_loop_times; j++)
536
{
537
generateTestData();
538
539
OCL_OFF(cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi, true));
540
OCL_ON(cv::polarToCart(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi, true));
541
542
Near(0.5);
543
Near1(0.5);
544
}
545
}
546
547
OCL_TEST_P(PolarToCart, angleInRadians)
548
{
549
for (int j = 0; j < test_loop_times; j++)
550
{
551
generateTestData();
552
553
OCL_OFF(cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi));
554
OCL_ON(cv::polarToCart(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi));
555
556
Near(0.5);
557
Near1(0.5);
558
}
559
}
560
561
//////////////////////////////// Transpose /////////////////////////////////////////////////
562
563
typedef ArithmTestBase Transpose;
564
565
OCL_TEST_P(Transpose, Mat)
566
{
567
for (int j = 0; j < test_loop_times; j++)
568
{
569
generateTestData();
570
571
Size roiSize = src1_roi.size();
572
Border dst1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
573
randomSubMat(dst1, dst1_roi, Size(roiSize.height, roiSize.width), dst1Border, src1.type(), 5, 16);
574
575
UMAT_UPLOAD_INPUT_PARAMETER(dst1);
576
577
OCL_OFF(cv::transpose(src1_roi, dst1_roi));
578
OCL_ON(cv::transpose(usrc1_roi, udst1_roi));
579
580
Near(1e-5);
581
}
582
}
583
584
OCL_TEST_P(Transpose, SquareInplace)
585
{
586
const int type = CV_MAKE_TYPE(depth, cn);
587
588
for (int j = 0; j < test_loop_times; j++)
589
{
590
Size roiSize = randomSize(1, MAX_VALUE);
591
roiSize.height = roiSize.width; // make it square
592
593
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
594
randomSubMat(src1, src1_roi, roiSize, srcBorder, type, 5, 16);
595
596
UMAT_UPLOAD_OUTPUT_PARAMETER(src1);
597
598
OCL_OFF(cv::transpose(src1_roi, src1_roi));
599
OCL_ON(cv::transpose(usrc1_roi, usrc1_roi));
600
601
OCL_EXPECT_MATS_NEAR(src1, 0);
602
}
603
}
604
605
//////////////////////////////// Bitwise_and /////////////////////////////////////////////////
606
607
typedef ArithmTestBase Bitwise_and;
608
609
OCL_TEST_P(Bitwise_and, Mat)
610
{
611
for (int j = 0; j < test_loop_times; j++)
612
{
613
generateTestData();
614
615
OCL_OFF(cv::bitwise_and(src1_roi, src2_roi, dst1_roi));
616
OCL_ON(cv::bitwise_and(usrc1_roi, usrc2_roi, udst1_roi));
617
Near(0);
618
}
619
}
620
621
OCL_TEST_P(Bitwise_and, Mat_Mask)
622
{
623
for (int j = 0; j < test_loop_times; j++)
624
{
625
generateTestData();
626
627
OCL_OFF(cv::bitwise_and(src1_roi, src2_roi, dst1_roi, mask_roi));
628
OCL_ON(cv::bitwise_and(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
629
Near(0);
630
}
631
}
632
633
OCL_TEST_P(Bitwise_and, Scalar)
634
{
635
for (int j = 0; j < test_loop_times; j++)
636
{
637
generateTestData();
638
639
OCL_OFF(cv::bitwise_and(src1_roi, val, dst1_roi));
640
OCL_ON(cv::bitwise_and(usrc1_roi, val, udst1_roi));
641
Near(1e-5);
642
}
643
}
644
645
OCL_TEST_P(Bitwise_and, Scalar_Mask)
646
{
647
for (int j = 0; j < test_loop_times; j++)
648
{
649
generateTestData();
650
651
OCL_OFF(cv::bitwise_and(src1_roi, val, dst1_roi, mask_roi));
652
OCL_ON(cv::bitwise_and(usrc1_roi, val, udst1_roi, umask_roi));
653
Near(1e-5);
654
}
655
}
656
657
//////////////////////////////// Bitwise_or /////////////////////////////////////////////////
658
659
typedef ArithmTestBase Bitwise_or;
660
661
OCL_TEST_P(Bitwise_or, Mat)
662
{
663
for (int j = 0; j < test_loop_times; j++)
664
{
665
generateTestData();
666
667
OCL_OFF(cv::bitwise_or(src1_roi, src2_roi, dst1_roi));
668
OCL_ON(cv::bitwise_or(usrc1_roi, usrc2_roi, udst1_roi));
669
Near(0);
670
}
671
}
672
673
OCL_TEST_P(Bitwise_or, Mat_Mask)
674
{
675
for (int j = 0; j < test_loop_times; j++)
676
{
677
generateTestData();
678
679
OCL_OFF(cv::bitwise_or(src1_roi, src2_roi, dst1_roi, mask_roi));
680
OCL_ON(cv::bitwise_or(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
681
Near(0);
682
}
683
}
684
685
OCL_TEST_P(Bitwise_or, Scalar)
686
{
687
for (int j = 0; j < test_loop_times; j++)
688
{
689
generateTestData();
690
691
OCL_OFF(cv::bitwise_or(src1_roi, val, dst1_roi));
692
OCL_ON(cv::bitwise_or(usrc1_roi, val, udst1_roi));
693
Near(1e-5);
694
}
695
}
696
697
OCL_TEST_P(Bitwise_or, Scalar_Mask)
698
{
699
for (int j = 0; j < test_loop_times; j++)
700
{
701
generateTestData();
702
703
OCL_OFF(cv::bitwise_or(src1_roi, val, dst1_roi, mask_roi));
704
OCL_ON(cv::bitwise_or(val, usrc1_roi, udst1_roi, umask_roi));
705
Near(1e-5);
706
}
707
}
708
709
//////////////////////////////// Bitwise_xor /////////////////////////////////////////////////
710
711
typedef ArithmTestBase Bitwise_xor;
712
713
OCL_TEST_P(Bitwise_xor, Mat)
714
{
715
for (int j = 0; j < test_loop_times; j++)
716
{
717
generateTestData();
718
719
OCL_OFF(cv::bitwise_xor(src1_roi, src2_roi, dst1_roi));
720
OCL_ON(cv::bitwise_xor(usrc1_roi, usrc2_roi, udst1_roi));
721
Near(0);
722
}
723
}
724
725
OCL_TEST_P(Bitwise_xor, Mat_Mask)
726
{
727
for (int j = 0; j < test_loop_times; j++)
728
{
729
generateTestData();
730
731
OCL_OFF(cv::bitwise_xor(src1_roi, src2_roi, dst1_roi, mask_roi));
732
OCL_ON(cv::bitwise_xor(usrc1_roi, usrc2_roi, udst1_roi, umask_roi));
733
Near(0);
734
}
735
}
736
737
OCL_TEST_P(Bitwise_xor, Scalar)
738
{
739
for (int j = 0; j < test_loop_times; j++)
740
{
741
generateTestData();
742
743
OCL_OFF(cv::bitwise_xor(src1_roi, val, dst1_roi));
744
OCL_ON(cv::bitwise_xor(usrc1_roi, val, udst1_roi));
745
Near(1e-5);
746
}
747
}
748
749
OCL_TEST_P(Bitwise_xor, Scalar_Mask)
750
{
751
for (int j = 0; j < test_loop_times; j++)
752
{
753
generateTestData();
754
755
OCL_OFF(cv::bitwise_xor(src1_roi, val, dst1_roi, mask_roi));
756
OCL_ON(cv::bitwise_xor(usrc1_roi, val, udst1_roi, umask_roi));
757
Near(1e-5);
758
}
759
}
760
761
//////////////////////////////// Bitwise_not /////////////////////////////////////////////////
762
763
typedef ArithmTestBase Bitwise_not;
764
765
OCL_TEST_P(Bitwise_not, Mat)
766
{
767
for (int j = 0; j < test_loop_times; j++)
768
{
769
generateTestData();
770
771
OCL_OFF(cv::bitwise_not(src1_roi, dst1_roi));
772
OCL_ON(cv::bitwise_not(usrc1_roi, udst1_roi));
773
Near(0);
774
}
775
}
776
777
//////////////////////////////// Compare /////////////////////////////////////////////////
778
779
typedef ArithmTestBase Compare;
780
781
static const int cmp_codes[] = { CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE };
782
static const char * cmp_strs[] = { "CMP_EQ", "CMP_GT", "CMP_GE", "CMP_LT", "CMP_LE", "CMP_NE" };
783
static const int cmp_num = sizeof(cmp_codes) / sizeof(int);
784
785
OCL_TEST_P(Compare, Mat)
786
{
787
for (int i = 0; i < cmp_num; ++i)
788
{
789
SCOPED_TRACE(cmp_strs[i]);
790
for (int j = 0; j < test_loop_times; j++)
791
{
792
generateTestData();
793
794
OCL_OFF(cv::compare(src1_roi, src2_roi, dst1_roi, cmp_codes[i]));
795
OCL_ON(cv::compare(usrc1_roi, usrc2_roi, udst1_roi, cmp_codes[i]));
796
797
Near(0);
798
}
799
}
800
}
801
802
OCL_TEST_P(Compare, Scalar)
803
{
804
for (int i = 0; i < cmp_num; ++i)
805
{
806
SCOPED_TRACE(cmp_strs[i]);
807
for (int j = 0; j < test_loop_times; j++)
808
{
809
generateTestData(true);
810
811
OCL_OFF(cv::compare(src1_roi, val_in_range, dst1_roi, cmp_codes[i]));
812
OCL_ON(cv::compare(usrc1_roi, val_in_range, udst1_roi, cmp_codes[i]));
813
814
Near(0);
815
}
816
}
817
}
818
819
OCL_TEST_P(Compare, Scalar2)
820
{
821
for (int i = 0; i < cmp_num; ++i)
822
{
823
SCOPED_TRACE(cmp_strs[i]);
824
for (int j = 0; j < test_loop_times; j++)
825
{
826
generateTestData(true);
827
828
OCL_OFF(cv::compare(val_in_range, src1_roi, dst1_roi, cmp_codes[i]));
829
OCL_ON(cv::compare(val_in_range, usrc1_roi, udst1_roi, cmp_codes[i]));
830
831
Near(0);
832
}
833
}
834
}
835
836
//////////////////////////////// Pow /////////////////////////////////////////////////
837
838
typedef ArithmTestBase Pow;
839
840
OCL_TEST_P(Pow, Mat)
841
{
842
static const double pows[] = { -4, -1, -2.5, 0, 1, 2, 3.7, 4 };
843
844
for (int j = 0; j < 1/*test_loop_times*/; j++)
845
for (int k = 0, size = sizeof(pows) / sizeof(double); k < size; ++k)
846
{
847
SCOPED_TRACE(pows[k]);
848
849
generateTestData();
850
851
OCL_OFF(cv::pow(src1_roi, pows[k], dst1_roi));
852
OCL_ON(cv::pow(usrc1_roi, pows[k], udst1_roi));
853
854
OCL_EXPECT_MATS_NEAR_RELATIVE(dst1, 1e-5);
855
}
856
}
857
858
//////////////////////////////// AddWeighted /////////////////////////////////////////////////
859
860
typedef ArithmTestBase AddWeighted;
861
862
OCL_TEST_P(AddWeighted, Mat)
863
{
864
for (int j = 0; j < test_loop_times; j++)
865
{
866
generateTestData();
867
868
const double alpha = 2.0, beta = 1.0, gama = 3.0;
869
870
OCL_OFF(cv::addWeighted(src1_roi, alpha, src2_roi, beta, gama, dst1_roi));
871
OCL_ON(cv::addWeighted(usrc1_roi, alpha, usrc2_roi, beta, gama, udst1_roi));
872
873
if(dst1_roi.depth() >= CV_32F)
874
Near(3e-4, true);
875
else
876
Near(1);
877
}
878
}
879
880
//////////////////////////////// setIdentity /////////////////////////////////////////////////
881
882
typedef ArithmTestBase SetIdentity;
883
884
OCL_TEST_P(SetIdentity, Mat)
885
{
886
for (int j = 0; j < test_loop_times; j++)
887
{
888
generateTestData();
889
890
OCL_OFF(cv::setIdentity(dst1_roi, val));
891
OCL_ON(cv::setIdentity(udst1_roi, val));
892
893
Near(0);
894
}
895
}
896
897
//// Repeat
898
899
struct RepeatTestCase :
900
public ArithmTestBase
901
{
902
int nx, ny;
903
904
void generateTestData()
905
{
906
const int type = CV_MAKE_TYPE(depth, cn);
907
908
nx = randomInt(1, 4);
909
ny = randomInt(1, 4);
910
911
Size srcRoiSize = randomSize(1, MAX_VALUE);
912
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
913
randomSubMat(src1, src1_roi, srcRoiSize, srcBorder, type, 2, 11);
914
915
Size dstRoiSize(srcRoiSize.width * nx, srcRoiSize.height * ny);
916
Border dst1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
917
randomSubMat(dst1, dst1_roi, dstRoiSize, dst1Border, type, 5, 16);
918
919
UMAT_UPLOAD_INPUT_PARAMETER(src1);
920
UMAT_UPLOAD_OUTPUT_PARAMETER(dst1);
921
}
922
};
923
924
typedef RepeatTestCase Repeat;
925
926
OCL_TEST_P(Repeat, Mat)
927
{
928
for (int i = 0; i < test_loop_times; ++i)
929
{
930
generateTestData();
931
932
OCL_OFF(cv::repeat(src1_roi, ny, nx, dst1_roi));
933
OCL_ON(cv::repeat(usrc1_roi, ny, nx, udst1_roi));
934
935
Near();
936
}
937
}
938
939
//////////////////////////////// CountNonZero /////////////////////////////////////////////////
940
941
typedef ArithmTestBase CountNonZero;
942
943
OCL_TEST_P(CountNonZero, MAT)
944
{
945
for (int j = 0; j < test_loop_times; j++)
946
{
947
generateTestData();
948
949
int cpures, gpures;
950
OCL_OFF(cpures = cv::countNonZero(src1_roi));
951
OCL_ON(gpures = cv::countNonZero(usrc1_roi));
952
953
EXPECT_EQ(cpures, gpures);
954
}
955
}
956
957
//////////////////////////////// Sum /////////////////////////////////////////////////
958
959
typedef ArithmTestBase Sum;
960
961
OCL_TEST_P(Sum, MAT)
962
{
963
for (int j = 0; j < test_loop_times; j++)
964
{
965
generateTestData();
966
967
Scalar cpures, gpures;
968
OCL_OFF(cpures = cv::sum(src1_roi));
969
OCL_ON(gpures = cv::sum(usrc1_roi));
970
971
for (int i = 0; i < cn; ++i)
972
EXPECT_NEAR(cpures[i], gpures[i], 0.1);
973
}
974
}
975
976
//////////////////////////////// meanStdDev /////////////////////////////////////////////////
977
978
typedef ArithmTestBase MeanStdDev;
979
980
OCL_TEST_P(MeanStdDev, Mat)
981
{
982
for (int j = 0; j < test_loop_times; j++)
983
{
984
generateTestData();
985
986
Scalar cpu_mean, cpu_stddev;
987
Scalar gpu_mean, gpu_stddev;
988
989
OCL_OFF(cv::meanStdDev(src1_roi, cpu_mean, cpu_stddev));
990
OCL_ON(cv::meanStdDev(usrc1_roi, gpu_mean, gpu_stddev));
991
992
for (int i = 0; i < cn; ++i)
993
{
994
EXPECT_NEAR(cpu_mean[i], gpu_mean[i], 0.1);
995
EXPECT_NEAR(cpu_stddev[i], gpu_stddev[i], 0.1);
996
}
997
}
998
}
999
1000
OCL_TEST_P(MeanStdDev, Mat_Mask)
1001
{
1002
for (int j = 0; j < test_loop_times; j++)
1003
{
1004
generateTestData();
1005
1006
Scalar cpu_mean, cpu_stddev;
1007
Scalar gpu_mean, gpu_stddev;
1008
1009
OCL_OFF(cv::meanStdDev(src1_roi, cpu_mean, cpu_stddev, mask_roi));
1010
OCL_ON(cv::meanStdDev(usrc1_roi, gpu_mean, gpu_stddev, umask_roi));
1011
1012
for (int i = 0; i < cn; ++i)
1013
{
1014
EXPECT_NEAR(cpu_mean[i], gpu_mean[i], 0.1);
1015
EXPECT_NEAR(cpu_stddev[i], gpu_stddev[i], 0.1);
1016
}
1017
}
1018
}
1019
1020
OCL_TEST(MeanStdDev_, ZeroMask)
1021
{
1022
Size size(5, 5);
1023
UMat um(size, CV_32SC1), umask(size, CV_8UC1, Scalar::all(0));
1024
Mat m(size, CV_32SC1), mask(size, CV_8UC1, Scalar::all(0));
1025
1026
Scalar cpu_mean, cpu_stddev;
1027
Scalar gpu_mean, gpu_stddev;
1028
1029
OCL_OFF(cv::meanStdDev(m, cpu_mean, cpu_stddev, mask));
1030
OCL_ON(cv::meanStdDev(um, gpu_mean, gpu_stddev, umask));
1031
1032
for (int i = 0; i < 4; ++i)
1033
{
1034
EXPECT_NEAR(cpu_mean[i], gpu_mean[i], 0.1);
1035
EXPECT_NEAR(cpu_stddev[i], gpu_stddev[i], 0.1);
1036
}
1037
}
1038
1039
//////////////////////////////////////// Log /////////////////////////////////////////
1040
1041
typedef ArithmTestBase Log;
1042
1043
OCL_TEST_P(Log, Mat)
1044
{
1045
for (int j = 0; j < test_loop_times; j++)
1046
{
1047
generateTestData();
1048
1049
OCL_OFF(cv::log(src1_roi, dst1_roi));
1050
OCL_ON(cv::log(usrc1_roi, udst1_roi));
1051
Near(1);
1052
}
1053
}
1054
1055
//////////////////////////////////////// Exp /////////////////////////////////////////
1056
1057
typedef ArithmTestBase Exp;
1058
1059
OCL_TEST_P(Exp, Mat)
1060
{
1061
for (int j = 0; j < test_loop_times; j++)
1062
{
1063
generateTestData();
1064
1065
OCL_OFF(cv::exp(src1_roi, dst1_roi));
1066
OCL_ON(cv::exp(usrc1_roi, udst1_roi));
1067
Near(2);
1068
}
1069
}
1070
1071
//////////////////////////////////////// Phase /////////////////////////////////////////
1072
1073
typedef ArithmTestBase Phase;
1074
1075
OCL_TEST_P(Phase, angleInDegree)
1076
{
1077
for (int j = 0; j < test_loop_times; j++)
1078
{
1079
generateTestData();
1080
1081
OCL_OFF(cv::phase(src1_roi, src2_roi, dst1_roi, true));
1082
OCL_ON(cv::phase(usrc1_roi, usrc2_roi, udst1_roi, true));
1083
Near(1e-2);
1084
}
1085
}
1086
1087
OCL_TEST_P(Phase, angleInRadians)
1088
{
1089
for (int j = 0; j < test_loop_times; j++)
1090
{
1091
generateTestData();
1092
1093
OCL_OFF(cv::phase(src1_roi, src2_roi, dst1_roi));
1094
OCL_ON(cv::phase(usrc1_roi, usrc2_roi, udst1_roi));
1095
Near(1e-2);
1096
}
1097
}
1098
1099
//////////////////////////////////////// Magnitude /////////////////////////////////////////
1100
1101
typedef ArithmTestBase Magnitude;
1102
1103
OCL_TEST_P(Magnitude, Mat)
1104
{
1105
for (int j = 0; j < test_loop_times; j++)
1106
{
1107
generateTestData();
1108
1109
OCL_OFF(cv::magnitude(src1_roi, src2_roi, dst1_roi));
1110
OCL_ON(cv::magnitude(usrc1_roi, usrc2_roi, udst1_roi));
1111
Near(depth == CV_64F ? 1e-5 : 1e-2);
1112
}
1113
}
1114
1115
//////////////////////////////// Flip /////////////////////////////////////////////////
1116
1117
typedef ArithmTestBase Flip;
1118
1119
OCL_TEST_P(Flip, X)
1120
{
1121
for (int j = 0; j < test_loop_times; j++)
1122
{
1123
generateTestData();
1124
1125
OCL_OFF(cv::flip(src1_roi, dst1_roi, 0));
1126
OCL_ON(cv::flip(usrc1_roi, udst1_roi, 0));
1127
Near(0);
1128
}
1129
}
1130
1131
OCL_TEST_P(Flip, Y)
1132
{
1133
for (int j = 0; j < test_loop_times; j++)
1134
{
1135
generateTestData();
1136
1137
OCL_OFF(cv::flip(src1_roi, dst1_roi, 1));
1138
OCL_ON(cv::flip(usrc1_roi, udst1_roi, 1));
1139
Near(0);
1140
}
1141
}
1142
1143
OCL_TEST_P(Flip, BOTH)
1144
{
1145
for (int j = 0; j < test_loop_times; j++)
1146
{
1147
generateTestData();
1148
1149
OCL_OFF(cv::flip(src1_roi, dst1_roi, -1));
1150
OCL_ON(cv::flip(usrc1_roi, udst1_roi, -1));
1151
Near(0);
1152
}
1153
}
1154
//////////////////////////////////////// minMaxIdx /////////////////////////////////////////
1155
1156
typedef ArithmTestBase MinMaxIdx;
1157
1158
OCL_TEST_P(MinMaxIdx, Mat)
1159
{
1160
for (int j = 0; j < test_loop_times; j++)
1161
{
1162
generateTestData();
1163
1164
int p1[2], p2[2], up1[2], up2[2];
1165
double minv, maxv, uminv, umaxv;
1166
1167
if (cn > 1)
1168
{
1169
OCL_OFF(cv::minMaxIdx(src2_roi, &minv, &maxv) );
1170
OCL_ON(cv::minMaxIdx(usrc2_roi, &uminv, &umaxv));
1171
1172
EXPECT_DOUBLE_EQ(minv, uminv);
1173
EXPECT_DOUBLE_EQ(maxv, umaxv);
1174
}
1175
else
1176
{
1177
OCL_OFF(cv::minMaxIdx(src2_roi, &minv, &maxv, p1, p2, noArray()));
1178
OCL_ON(cv::minMaxIdx(usrc2_roi, &uminv, &umaxv, up1, up2, noArray()));
1179
1180
EXPECT_DOUBLE_EQ(minv, uminv);
1181
EXPECT_DOUBLE_EQ(maxv, umaxv);
1182
1183
for (int i = 0; i < 2; i++)
1184
{
1185
EXPECT_EQ(p1[i], up1[i]);
1186
EXPECT_EQ(p2[i], up2[i]);
1187
}
1188
}
1189
}
1190
}
1191
1192
typedef ArithmTestBase MinMaxIdx_Mask;
1193
1194
OCL_TEST_P(MinMaxIdx_Mask, Mat)
1195
{
1196
for (int j = 0; j < test_loop_times; j++)
1197
{
1198
generateTestData();
1199
1200
int p1[2], p2[2], up1[2], up2[2];
1201
double minv, maxv, uminv, umaxv;
1202
1203
OCL_OFF(cv::minMaxIdx(src2_roi, &minv, &maxv, p1, p2, mask_roi));
1204
OCL_ON(cv::minMaxIdx(usrc2_roi, &uminv, &umaxv, up1, up2, umask_roi));
1205
1206
EXPECT_DOUBLE_EQ(minv, uminv);
1207
EXPECT_DOUBLE_EQ(maxv, umaxv);
1208
for( int i = 0; i < 2; i++)
1209
{
1210
EXPECT_EQ(p1[i], up1[i]);
1211
EXPECT_EQ(p2[i], up2[i]);
1212
}
1213
1214
}
1215
}
1216
1217
//////////////////////////////// Norm /////////////////////////////////////////////////
1218
1219
static bool relativeError(double actual, double expected, double eps)
1220
{
1221
return std::abs(actual - expected) < eps*(1 + std::abs(actual));
1222
}
1223
1224
typedef ArithmTestBase Norm;
1225
1226
OCL_TEST_P(Norm, NORM_INF_1arg)
1227
{
1228
for (int j = 0; j < test_loop_times; j++)
1229
{
1230
generateTestData();
1231
1232
OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_INF));
1233
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_INF));
1234
1235
EXPECT_NEAR(cpuRes, gpuRes, 0.1);
1236
}
1237
}
1238
1239
OCL_TEST_P(Norm, NORM_INF_1arg_mask)
1240
{
1241
for (int j = 0; j < test_loop_times; j++)
1242
{
1243
generateTestData();
1244
1245
OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_INF, mask_roi));
1246
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_INF, umask_roi));
1247
1248
EXPECT_NEAR(cpuRes, gpuRes, 0.2);
1249
}
1250
}
1251
1252
OCL_TEST_P(Norm, NORM_L1_1arg)
1253
{
1254
for (int j = 0; j < test_loop_times; j++)
1255
{
1256
generateTestData();
1257
1258
OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_L1));
1259
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_L1));
1260
1261
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1262
}
1263
}
1264
1265
OCL_TEST_P(Norm, NORM_L1_1arg_mask)
1266
{
1267
for (int j = 0; j < test_loop_times; j++)
1268
{
1269
generateTestData();
1270
1271
OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_L1, mask_roi));
1272
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_L1, umask_roi));
1273
1274
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1275
}
1276
}
1277
1278
OCL_TEST_P(Norm, NORM_L2_1arg)
1279
{
1280
for (int j = 0; j < test_loop_times; j++)
1281
{
1282
generateTestData();
1283
1284
OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_L2));
1285
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_L2));
1286
1287
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1288
}
1289
}
1290
1291
OCL_TEST_P(Norm, NORM_L2_1arg_mask)
1292
{
1293
for (int j = 0; j < test_loop_times; j++)
1294
{
1295
generateTestData();
1296
1297
OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_L2, mask_roi));
1298
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_L2, umask_roi));
1299
1300
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1301
}
1302
}
1303
1304
OCL_TEST_P(Norm, NORM_INF_2args)
1305
{
1306
for (int relative = 0; relative < 2; ++relative)
1307
for (int j = 0; j < test_loop_times; j++)
1308
{
1309
generateTestData();
1310
1311
SCOPED_TRACE(relative ? "NORM_RELATIVE" : "");
1312
1313
int type = NORM_INF;
1314
if (relative == 1)
1315
type |= NORM_RELATIVE;
1316
1317
OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type));
1318
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type));
1319
1320
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1321
}
1322
}
1323
1324
OCL_TEST_P(Norm, NORM_INF_2args_mask)
1325
{
1326
for (int relative = 0; relative < 2; ++relative)
1327
for (int j = 0; j < test_loop_times; j++)
1328
{
1329
generateTestData();
1330
1331
SCOPED_TRACE(relative ? "NORM_RELATIVE" : "");
1332
1333
int type = NORM_INF;
1334
if (relative == 1)
1335
type |= NORM_RELATIVE;
1336
1337
OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type, mask_roi));
1338
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type, umask_roi));
1339
1340
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1341
}
1342
}
1343
1344
OCL_TEST_P(Norm, NORM_L1_2args)
1345
{
1346
for (int relative = 0; relative < 2; ++relative)
1347
for (int j = 0; j < test_loop_times; j++)
1348
{
1349
generateTestData();
1350
1351
SCOPED_TRACE(relative ? "NORM_RELATIVE" : "");
1352
1353
int type = NORM_L1;
1354
if (relative == 1)
1355
type |= NORM_RELATIVE;
1356
1357
OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type));
1358
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type));
1359
1360
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1361
}
1362
}
1363
1364
OCL_TEST_P(Norm, NORM_L1_2args_mask)
1365
{
1366
for (int relative = 0; relative < 2; ++relative)
1367
for (int j = 0; j < test_loop_times; j++)
1368
{
1369
generateTestData();
1370
1371
SCOPED_TRACE(relative ? "NORM_RELATIVE" : "");
1372
1373
int type = NORM_L1;
1374
if (relative == 1)
1375
type |= NORM_RELATIVE;
1376
1377
OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type, mask_roi));
1378
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type, umask_roi));
1379
1380
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1381
}
1382
}
1383
1384
OCL_TEST_P(Norm, NORM_L2_2args)
1385
{
1386
for (int relative = 0; relative < 2; ++relative)
1387
for (int j = 0; j < test_loop_times; j++)
1388
{
1389
generateTestData();
1390
1391
SCOPED_TRACE(relative ? "NORM_RELATIVE" : "");
1392
1393
int type = NORM_L2;
1394
if (relative == 1)
1395
type |= NORM_RELATIVE;
1396
1397
OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type));
1398
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type));
1399
1400
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1401
}
1402
}
1403
1404
OCL_TEST_P(Norm, NORM_L2_2args_mask)
1405
{
1406
for (int relative = 0; relative < 2; ++relative)
1407
for (int j = 0; j < test_loop_times; j++)
1408
{
1409
generateTestData();
1410
1411
SCOPED_TRACE(relative ? "NORM_RELATIVE" : "");
1412
1413
int type = NORM_L2;
1414
if (relative == 1)
1415
type |= NORM_RELATIVE;
1416
1417
OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type, mask_roi));
1418
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type, umask_roi));
1419
1420
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1421
}
1422
}
1423
1424
//////////////////////////////// UMat::dot ////////////////////////////////////////////////
1425
1426
typedef ArithmTestBase UMatDot;
1427
1428
OCL_TEST_P(UMatDot, Mat)
1429
{
1430
for (int j = 0; j < test_loop_times; j++)
1431
{
1432
generateTestData();
1433
1434
OCL_OFF(const double cpuRes = src1_roi.dot(src2_roi));
1435
OCL_ON(const double gpuRes = usrc1_roi.dot(usrc2_roi));
1436
1437
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-5);
1438
}
1439
}
1440
1441
//////////////////////////////// Sqrt ////////////////////////////////////////////////
1442
1443
typedef ArithmTestBase Sqrt;
1444
1445
OCL_TEST_P(Sqrt, Mat)
1446
{
1447
for (int j = 0; j < test_loop_times; j++)
1448
{
1449
generateTestData();
1450
1451
OCL_OFF(cv::sqrt(src1_roi, dst1_roi));
1452
OCL_ON(cv::sqrt(usrc1_roi, udst1_roi));
1453
1454
Near(1);
1455
}
1456
}
1457
1458
//////////////////////////////// Normalize ////////////////////////////////////////////////
1459
1460
typedef ArithmTestBase Normalize;
1461
1462
OCL_TEST_P(Normalize, Mat)
1463
{
1464
static int modes[] = { CV_MINMAX, CV_L2, CV_L1, CV_C };
1465
1466
for (int j = 0; j < test_loop_times; j++)
1467
{
1468
generateTestData();
1469
1470
for (int i = 0, size = sizeof(modes) / sizeof(modes[0]); i < size; ++i)
1471
{
1472
OCL_OFF(cv::normalize(src1_roi, dst1_roi, 10, 110, modes[i], src1_roi.type(), mask_roi));
1473
OCL_ON(cv::normalize(usrc1_roi, udst1_roi, 10, 110, modes[i], src1_roi.type(), umask_roi));
1474
1475
Near(1);
1476
}
1477
}
1478
}
1479
1480
//////////////////////////////////////// InRange ///////////////////////////////////////////////
1481
1482
PARAM_TEST_CASE(InRange, MatDepth, Channels, bool /*Scalar or not*/, bool /*Roi*/)
1483
{
1484
int depth;
1485
int cn;
1486
bool scalars, use_roi;
1487
cv::Scalar val1, val2;
1488
1489
TEST_DECLARE_INPUT_PARAMETER(src1);
1490
TEST_DECLARE_INPUT_PARAMETER(src2);
1491
TEST_DECLARE_INPUT_PARAMETER(src3);
1492
TEST_DECLARE_OUTPUT_PARAMETER(dst);
1493
1494
virtual void SetUp()
1495
{
1496
depth = GET_PARAM(0);
1497
cn = GET_PARAM(1);
1498
scalars = GET_PARAM(2);
1499
use_roi = GET_PARAM(3);
1500
}
1501
1502
void generateTestData()
1503
{
1504
const int type = CV_MAKE_TYPE(depth, cn);
1505
1506
Size roiSize = randomSize(1, MAX_VALUE);
1507
Border src1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
1508
randomSubMat(src1, src1_roi, roiSize, src1Border, type, -40, 40);
1509
1510
Border src2Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
1511
randomSubMat(src2, src2_roi, roiSize, src2Border, type, -40, 40);
1512
1513
Border src3Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
1514
randomSubMat(src3, src3_roi, roiSize, src3Border, type, -40, 40);
1515
1516
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1517
randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_8UC1, 5, 16);
1518
1519
val1 = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0),
1520
rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0));
1521
val2 = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0),
1522
rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0));
1523
1524
UMAT_UPLOAD_INPUT_PARAMETER(src1);
1525
UMAT_UPLOAD_INPUT_PARAMETER(src2);
1526
UMAT_UPLOAD_INPUT_PARAMETER(src3);
1527
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
1528
}
1529
1530
void Near()
1531
{
1532
OCL_EXPECT_MATS_NEAR(dst, 0);
1533
}
1534
};
1535
1536
OCL_TEST_P(InRange, Mat)
1537
{
1538
for (int j = 0; j < test_loop_times; j++)
1539
{
1540
generateTestData();
1541
1542
OCL_OFF(cv::inRange(src1_roi, src2_roi, src3_roi, dst_roi));
1543
OCL_ON(cv::inRange(usrc1_roi, usrc2_roi, usrc3_roi, udst_roi));
1544
1545
Near();
1546
}
1547
}
1548
1549
OCL_TEST_P(InRange, Scalar)
1550
{
1551
for (int j = 0; j < test_loop_times; j++)
1552
{
1553
generateTestData();
1554
1555
OCL_OFF(cv::inRange(src1_roi, val1, val2, dst_roi));
1556
OCL_ON(cv::inRange(usrc1_roi, val1, val2, udst_roi));
1557
1558
Near();
1559
}
1560
}
1561
1562
//////////////////////////////// ConvertScaleAbs ////////////////////////////////////////////////
1563
1564
PARAM_TEST_CASE(ConvertScaleAbs, MatDepth, Channels, bool)
1565
{
1566
int depth;
1567
int cn;
1568
bool use_roi;
1569
cv::Scalar val;
1570
1571
TEST_DECLARE_INPUT_PARAMETER(src);
1572
TEST_DECLARE_OUTPUT_PARAMETER(dst);
1573
1574
virtual void SetUp()
1575
{
1576
depth = GET_PARAM(0);
1577
cn = GET_PARAM(1);
1578
use_roi = GET_PARAM(2);
1579
}
1580
1581
void generateTestData()
1582
{
1583
const int stype = CV_MAKE_TYPE(depth, cn);
1584
const int dtype = CV_MAKE_TYPE(CV_8U, cn);
1585
1586
Size roiSize = randomSize(1, MAX_VALUE);
1587
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1588
randomSubMat(src, src_roi, roiSize, srcBorder, stype, -11, 11); // FIXIT: Test with minV, maxV
1589
1590
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1591
randomSubMat(dst, dst_roi, roiSize, dstBorder, dtype, 5, 16);
1592
1593
val = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0),
1594
rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0));
1595
1596
UMAT_UPLOAD_INPUT_PARAMETER(src);
1597
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
1598
}
1599
1600
void Near(double threshold = 0.)
1601
{
1602
OCL_EXPECT_MATS_NEAR(dst, threshold);
1603
}
1604
1605
};
1606
1607
1608
OCL_TEST_P(ConvertScaleAbs, Mat)
1609
{
1610
for (int j = 0; j < test_loop_times; j++)
1611
{
1612
generateTestData();
1613
1614
OCL_OFF(cv::convertScaleAbs(src_roi, dst_roi, val[0], val[1]));
1615
OCL_ON(cv::convertScaleAbs(usrc_roi, udst_roi, val[0], val[1]));
1616
1617
Near(1);
1618
}
1619
}
1620
1621
//////////////////////////////// ConvertFp16 ////////////////////////////////////////////////
1622
1623
PARAM_TEST_CASE(ConvertFp16, Channels, bool)
1624
{
1625
int cn;
1626
bool fromHalf;
1627
cv::Scalar val;
1628
1629
TEST_DECLARE_INPUT_PARAMETER(src);
1630
TEST_DECLARE_OUTPUT_PARAMETER(dst);
1631
1632
virtual void SetUp()
1633
{
1634
cn = GET_PARAM(0);
1635
fromHalf = GET_PARAM(1);
1636
}
1637
1638
void generateTestData()
1639
{
1640
const int stype = CV_MAKE_TYPE(fromHalf ? CV_32F : CV_16S, cn);
1641
const int dtype = CV_MAKE_TYPE(fromHalf ? CV_16S : CV_32F, cn);
1642
1643
Size roiSize = randomSize(1, MAX_VALUE);
1644
Border srcBorder = randomBorder(0, 0);
1645
randomSubMat(src, src_roi, roiSize, srcBorder, stype, -11, 11); // FIXIT: Test with minV, maxV
1646
if (stype == CV_MAKE_TYPE(CV_16S, cn)) // eliminate NaN/Inf FP16 values
1647
{
1648
RNG dataRng(rng.next());
1649
Mat src_i32 = cvtest::randomMat(dataRng, roiSize, CV_MAKE_TYPE(CV_32S, cn), 0, 0x7c00, false);
1650
Mat shift_i32 = cvtest::randomMat(dataRng, roiSize, src_i32.type(), -1, 1, false); // values: -1, 0
1651
src_i32 = src_i32 + (shift_i32 * 0x8000);
1652
src_i32.convertTo(src_roi, stype);
1653
}
1654
1655
Border dstBorder = randomBorder(0, 0);
1656
randomSubMat(dst, dst_roi, roiSize, dstBorder, dtype, 5, 16);
1657
1658
UMAT_UPLOAD_INPUT_PARAMETER(src);
1659
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
1660
}
1661
1662
void Near(double threshold = 0.)
1663
{
1664
OCL_EXPECT_MATS_NEAR(dst, threshold);
1665
}
1666
1667
};
1668
1669
1670
OCL_TEST_P(ConvertFp16, Mat)
1671
{
1672
for (int j = 0; j < test_loop_times; j++)
1673
{
1674
generateTestData();
1675
1676
OCL_OFF(cv::convertFp16(src_roi, dst_roi));
1677
OCL_ON(cv::convertFp16(usrc_roi, udst_roi));
1678
1679
Near(1);
1680
}
1681
}
1682
1683
//////////////////////////////// ScaleAdd ////////////////////////////////////////////////
1684
1685
typedef ArithmTestBase ScaleAdd;
1686
1687
OCL_TEST_P(ScaleAdd, Mat)
1688
{
1689
for (int j = 0; j < test_loop_times; j++)
1690
{
1691
generateTestData();
1692
1693
OCL_OFF(cv::scaleAdd(src1_roi, val[0], src2_roi, dst1_roi));
1694
OCL_ON(cv::scaleAdd(usrc1_roi, val[0], usrc2_roi, udst1_roi));
1695
1696
Near(depth <= CV_32S ? 1 : 1e-3);
1697
}
1698
}
1699
1700
//////////////////////////////// PatchNans ////////////////////////////////////////////////
1701
1702
PARAM_TEST_CASE(PatchNaNs, Channels, bool)
1703
{
1704
int cn;
1705
bool use_roi;
1706
double value;
1707
1708
TEST_DECLARE_INPUT_PARAMETER(src);
1709
1710
virtual void SetUp()
1711
{
1712
cn = GET_PARAM(0);
1713
use_roi = GET_PARAM(1);
1714
}
1715
1716
void generateTestData()
1717
{
1718
const int type = CV_MAKE_TYPE(CV_32F, cn);
1719
1720
Size roiSize = randomSize(1, 10);
1721
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1722
randomSubMat(src, src_roi, roiSize, srcBorder, type, -40, 40);
1723
1724
// generating NaNs
1725
roiSize.width *= cn;
1726
for (int y = 0; y < roiSize.height; ++y)
1727
{
1728
float * const ptr = src_roi.ptr<float>(y);
1729
for (int x = 0; x < roiSize.width; ++x)
1730
ptr[x] = randomInt(-1, 1) == 0 ? std::numeric_limits<float>::quiet_NaN() : ptr[x];
1731
}
1732
1733
value = randomDouble(-100, 100);
1734
1735
UMAT_UPLOAD_INPUT_PARAMETER(src);
1736
}
1737
1738
void Near()
1739
{
1740
OCL_EXPECT_MATS_NEAR(src, 0);
1741
}
1742
};
1743
1744
OCL_TEST_P(PatchNaNs, Mat)
1745
{
1746
for (int j = 0; j < test_loop_times; j++)
1747
{
1748
generateTestData();
1749
1750
OCL_OFF(cv::patchNaNs(src_roi, value));
1751
OCL_ON(cv::patchNaNs(usrc_roi, value));
1752
1753
Near();
1754
}
1755
}
1756
1757
//////////////////////////////// Psnr ////////////////////////////////////////////////
1758
1759
typedef ArithmTestBase Psnr;
1760
1761
OCL_TEST_P(Psnr, Mat)
1762
{
1763
for (int j = 0; j < test_loop_times; j++)
1764
{
1765
generateTestData();
1766
1767
double cpuRes = 0, gpuRes = 0;
1768
1769
OCL_OFF(cpuRes = cv::PSNR(src1_roi, src2_roi));
1770
OCL_ON(gpuRes = cv::PSNR(usrc1_roi, usrc2_roi));
1771
1772
EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6);
1773
}
1774
}
1775
1776
//////////////////////////////////////// Reduce /////////////////////////////////////////////
1777
1778
PARAM_TEST_CASE(Reduce, std::pair<MatDepth, MatDepth>, Channels, int, bool)
1779
{
1780
int sdepth, ddepth, cn, dim, dtype;
1781
bool use_roi;
1782
1783
TEST_DECLARE_INPUT_PARAMETER(src);
1784
TEST_DECLARE_OUTPUT_PARAMETER(dst);
1785
1786
virtual void SetUp()
1787
{
1788
const std::pair<MatDepth, MatDepth> p = GET_PARAM(0);
1789
sdepth = p.first;
1790
ddepth = p.second;
1791
cn = GET_PARAM(1);
1792
dim = GET_PARAM(2);
1793
use_roi = GET_PARAM(3);
1794
}
1795
1796
void generateTestData()
1797
{
1798
const int stype = CV_MAKE_TYPE(sdepth, cn);
1799
dtype = CV_MAKE_TYPE(ddepth, cn);
1800
1801
Size roiSize = randomSize(1, MAX_VALUE);
1802
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1803
randomSubMat(src, src_roi, roiSize, srcBorder, stype, -40, 40);
1804
1805
Size dstRoiSize = Size(dim == 0 ? roiSize.width : 1, dim == 0 ? 1 : roiSize.height);
1806
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
1807
randomSubMat(dst, dst_roi, dstRoiSize, dstBorder, dtype, 5, 16);
1808
1809
UMAT_UPLOAD_INPUT_PARAMETER(src);
1810
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
1811
}
1812
};
1813
1814
typedef Reduce ReduceSum;
1815
1816
OCL_TEST_P(ReduceSum, Mat)
1817
{
1818
for (int j = 0; j < test_loop_times; j++)
1819
{
1820
generateTestData();
1821
1822
OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_SUM, dtype));
1823
OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_SUM, dtype));
1824
1825
double eps = ddepth <= CV_32S ? 1 : 7e-4;
1826
OCL_EXPECT_MATS_NEAR(dst, eps);
1827
}
1828
}
1829
1830
typedef Reduce ReduceMax;
1831
1832
OCL_TEST_P(ReduceMax, Mat)
1833
{
1834
for (int j = 0; j < test_loop_times; j++)
1835
{
1836
generateTestData();
1837
1838
OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_MAX, dtype));
1839
OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_MAX, dtype));
1840
1841
OCL_EXPECT_MATS_NEAR(dst, 0);
1842
}
1843
}
1844
1845
typedef Reduce ReduceMin;
1846
1847
OCL_TEST_P(ReduceMin, Mat)
1848
{
1849
for (int j = 0; j < test_loop_times; j++)
1850
{
1851
generateTestData();
1852
1853
OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_MIN, dtype));
1854
OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_MIN, dtype));
1855
1856
OCL_EXPECT_MATS_NEAR(dst, 0);
1857
}
1858
}
1859
1860
typedef Reduce ReduceAvg;
1861
1862
OCL_TEST_P(ReduceAvg, Mat)
1863
{
1864
for (int j = 0; j < test_loop_times; j++)
1865
{
1866
generateTestData();
1867
1868
OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_AVG, dtype));
1869
OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_AVG, dtype));
1870
1871
double eps = ddepth <= CV_32S ? 1 : 6e-6;
1872
OCL_EXPECT_MATS_NEAR(dst, eps);
1873
}
1874
}
1875
1876
//////////////////////////////////////// Instantiation /////////////////////////////////////////
1877
1878
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Lut, Combine(::testing::Values(CV_8U, CV_8S), OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool(), Bool()));
1879
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Add, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1880
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Subtract, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1881
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Mul, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1882
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Div, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1883
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Min, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1884
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Max, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1885
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Absdiff, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1886
OCL_INSTANTIATE_TEST_CASE_P(Arithm, CartToPolar, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1887
OCL_INSTANTIATE_TEST_CASE_P(Arithm, PolarToCart, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1888
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Transpose, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1889
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_and, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1890
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_not, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1891
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_xor, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1892
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_or, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1893
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Pow, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1894
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Compare, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1895
OCL_INSTANTIATE_TEST_CASE_P(Arithm, AddWeighted, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1896
OCL_INSTANTIATE_TEST_CASE_P(Arithm, SetIdentity, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1897
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Repeat, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1898
OCL_INSTANTIATE_TEST_CASE_P(Arithm, CountNonZero, Combine(OCL_ALL_DEPTHS, testing::Values(Channels(1)), Bool()));
1899
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Sum, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1900
OCL_INSTANTIATE_TEST_CASE_P(Arithm, MeanStdDev, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1901
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Log, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1902
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Exp, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1903
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Phase, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1904
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Magnitude, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1905
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Flip, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1906
OCL_INSTANTIATE_TEST_CASE_P(Arithm, MinMaxIdx, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1907
OCL_INSTANTIATE_TEST_CASE_P(Arithm, MinMaxIdx_Mask, Combine(OCL_ALL_DEPTHS, ::testing::Values(Channels(1)), Bool()));
1908
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Norm, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1909
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Sqrt, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool()));
1910
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Normalize, Combine(OCL_ALL_DEPTHS, Values(Channels(1)), Bool()));
1911
OCL_INSTANTIATE_TEST_CASE_P(Arithm, InRange, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool(), Bool()));
1912
OCL_INSTANTIATE_TEST_CASE_P(Arithm, ConvertScaleAbs, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1913
OCL_INSTANTIATE_TEST_CASE_P(Arithm, ConvertFp16, Combine(OCL_ALL_CHANNELS, Bool()));
1914
OCL_INSTANTIATE_TEST_CASE_P(Arithm, ScaleAdd, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1915
OCL_INSTANTIATE_TEST_CASE_P(Arithm, PatchNaNs, Combine(OCL_ALL_CHANNELS, Bool()));
1916
OCL_INSTANTIATE_TEST_CASE_P(Arithm, Psnr, Combine(::testing::Values((MatDepth)CV_8U), OCL_ALL_CHANNELS, Bool()));
1917
OCL_INSTANTIATE_TEST_CASE_P(Arithm, UMatDot, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool()));
1918
1919
OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceSum, Combine(testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32S),
1920
std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F),
1921
std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F),
1922
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F),
1923
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F),
1924
std::make_pair<MatDepth, MatDepth>(CV_16S, CV_32F),
1925
std::make_pair<MatDepth, MatDepth>(CV_16S, CV_64F),
1926
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F),
1927
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F),
1928
std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F)),
1929
OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
1930
OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceAvg, Combine(testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32S),
1931
std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F),
1932
std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F),
1933
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F),
1934
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F),
1935
std::make_pair<MatDepth, MatDepth>(CV_16S, CV_32F),
1936
std::make_pair<MatDepth, MatDepth>(CV_16S, CV_64F),
1937
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F),
1938
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F),
1939
std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F)),
1940
OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
1941
OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceMax, Combine(testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_8U),
1942
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_16U),
1943
std::make_pair<MatDepth, MatDepth>(CV_16S, CV_16S),
1944
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F),
1945
std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F)),
1946
OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
1947
OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceMin, Combine(testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_8U),
1948
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_16U),
1949
std::make_pair<MatDepth, MatDepth>(CV_16S, CV_16S),
1950
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F),
1951
std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F)),
1952
OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
1953
1954
1955
// T-API BUG (haveOpenCL() is false): modules/core/src/matrix.cpp:212: error: (-215) u->refcount == 0 in function deallocate
1956
OCL_TEST(Normalize, DISABLED_regression_5876_inplace_change_type)
1957
{
1958
double initial_values[] = {1, 2, 5, 4, 3};
1959
float result_values[] = {0, 0.25, 1, 0.75, 0.5};
1960
Mat m(Size(5, 1), CV_64FC1, initial_values);
1961
Mat result(Size(5, 1), CV_32FC1, result_values);
1962
1963
UMat um; m.copyTo(um);
1964
UMat uresult; result.copyTo(uresult);
1965
1966
OCL_ON(normalize(um, um, 1, 0, NORM_MINMAX, CV_32F));
1967
1968
EXPECT_EQ(0, cvtest::norm(um, uresult, NORM_INF));
1969
}
1970
1971
} } // namespace opencv_test::ocl
1972
1973
#endif // HAVE_OPENCL
1974
1975