Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/test/ocl/test_imgproc.cpp
16344 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-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
14
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
16
// Third party copyrights are property of their respective owners.
17
//
18
// @Authors
19
// Niko Li, [email protected]
20
// Jia Haipeng, [email protected]
21
// Shengen Yan, [email protected]
22
// Jiang Liyuan, [email protected]
23
// Rock Li, [email protected]
24
// Wu Zailong, [email protected]
25
// Xu Pang, [email protected]
26
// Sen Liu, [email protected]
27
//
28
// Redistribution and use in source and binary forms, with or without modification,
29
// are permitted provided that the following conditions are met:
30
//
31
// * Redistribution's of source code must retain the above copyright notice,
32
// this list of conditions and the following disclaimer.
33
//
34
// * Redistribution's in binary form must reproduce the above copyright notice,
35
// this list of conditions and the following disclaimer in the documentation
36
// and/or other materials provided with the distribution.
37
//
38
// * The name of the copyright holders may not be used to endorse or promote products
39
// derived from this software without specific prior written permission.
40
//
41
// This software is provided by the copyright holders and contributors "as is" and
42
// any express or implied warranties, including, but not limited to, the implied
43
// warranties of merchantability and fitness for a particular purpose are disclaimed.
44
// In no event shall the Intel Corporation or contributors be liable for any direct,
45
// indirect, incidental, special, exemplary, or consequential damages
46
// (including, but not limited to, procurement of substitute goods or services;
47
// loss of use, data, or profits; or business interruption) however caused
48
// and on any theory of liability, whether in contract, strict liability,
49
// or tort (including negligence or otherwise) arising in any way out of
50
// the use of this software, even if advised of the possibility of such damage.
51
//
52
//M*/
53
54
#include "../test_precomp.hpp"
55
#include "opencv2/ts/ocl_test.hpp"
56
57
#ifdef HAVE_OPENCL
58
59
namespace opencv_test {
60
namespace ocl {
61
62
///////////////////////////////////////////////////////////////////////////////
63
64
PARAM_TEST_CASE(ImgprocTestBase, MatType,
65
int, // blockSize
66
int, // border type
67
bool) // roi or not
68
{
69
int type, borderType, blockSize;
70
bool useRoi;
71
72
TEST_DECLARE_INPUT_PARAMETER(src);
73
TEST_DECLARE_OUTPUT_PARAMETER(dst);
74
75
virtual void SetUp()
76
{
77
type = GET_PARAM(0);
78
blockSize = GET_PARAM(1);
79
borderType = GET_PARAM(2);
80
useRoi = GET_PARAM(3);
81
}
82
83
void random_roi()
84
{
85
Size roiSize = randomSize(1, MAX_VALUE);
86
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
87
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
88
89
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
90
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);
91
92
UMAT_UPLOAD_INPUT_PARAMETER(src);
93
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
94
}
95
96
void Near(double threshold = 0.0, bool relative = false)
97
{
98
if (relative)
99
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
100
else
101
OCL_EXPECT_MATS_NEAR(dst, threshold);
102
}
103
};
104
105
//////////////////////////////// copyMakeBorder ////////////////////////////////////////////
106
107
PARAM_TEST_CASE(CopyMakeBorder, MatDepth, // depth
108
Channels, // channels
109
bool, // isolated or not
110
BorderType, // border type
111
bool) // roi or not
112
{
113
int type, borderType;
114
bool useRoi;
115
116
TestUtils::Border border;
117
Scalar val;
118
119
TEST_DECLARE_INPUT_PARAMETER(src);
120
TEST_DECLARE_OUTPUT_PARAMETER(dst);
121
122
virtual void SetUp()
123
{
124
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
125
borderType = GET_PARAM(3);
126
127
if (GET_PARAM(2))
128
borderType |= BORDER_ISOLATED;
129
130
useRoi = GET_PARAM(4);
131
}
132
133
void random_roi()
134
{
135
border = randomBorder(0, MAX_VALUE << 2);
136
val = randomScalar(-MAX_VALUE, MAX_VALUE);
137
138
Size roiSize = randomSize(1, MAX_VALUE);
139
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
140
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
141
142
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
143
dstBorder.top += border.top;
144
dstBorder.lef += border.lef;
145
dstBorder.rig += border.rig;
146
dstBorder.bot += border.bot;
147
148
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
149
150
UMAT_UPLOAD_INPUT_PARAMETER(src);
151
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
152
}
153
154
void Near()
155
{
156
OCL_EXPECT_MATS_NEAR(dst, 0);
157
}
158
};
159
160
OCL_TEST_P(CopyMakeBorder, Mat)
161
{
162
for (int i = 0; i < test_loop_times; ++i)
163
{
164
random_roi();
165
166
OCL_OFF(cv::copyMakeBorder(src_roi, dst_roi, border.top, border.bot, border.lef, border.rig, borderType, val));
167
OCL_ON(cv::copyMakeBorder(usrc_roi, udst_roi, border.top, border.bot, border.lef, border.rig, borderType, val));
168
169
Near();
170
}
171
}
172
173
//////////////////////////////// equalizeHist //////////////////////////////////////////////
174
175
typedef ImgprocTestBase EqualizeHist;
176
177
OCL_TEST_P(EqualizeHist, Mat)
178
{
179
for (int j = 0; j < test_loop_times; j++)
180
{
181
random_roi();
182
183
OCL_OFF(cv::equalizeHist(src_roi, dst_roi));
184
OCL_ON(cv::equalizeHist(usrc_roi, udst_roi));
185
186
Near(1);
187
}
188
}
189
190
//////////////////////////////// Corners test //////////////////////////////////////////
191
192
struct CornerTestBase :
193
public ImgprocTestBase
194
{
195
void random_roi()
196
{
197
Mat image = readImageType("../gpu/stereobm/aloe-L.png", type);
198
ASSERT_FALSE(image.empty());
199
200
bool isFP = CV_MAT_DEPTH(type) >= CV_32F;
201
float val = 255.0f;
202
if (isFP)
203
{
204
image.convertTo(image, -1, 1.0 / 255);
205
val /= 255.0f;
206
}
207
208
Size roiSize = image.size();
209
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
210
211
Size wholeSize = Size(roiSize.width + srcBorder.lef + srcBorder.rig, roiSize.height + srcBorder.top + srcBorder.bot);
212
src = randomMat(wholeSize, type, -val, val, false);
213
src_roi = src(Rect(srcBorder.lef, srcBorder.top, roiSize.width, roiSize.height));
214
image.copyTo(src_roi);
215
216
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
217
randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_32FC1, 5, 16);
218
219
UMAT_UPLOAD_INPUT_PARAMETER(src);
220
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
221
}
222
};
223
224
typedef CornerTestBase CornerMinEigenVal;
225
226
OCL_TEST_P(CornerMinEigenVal, Mat)
227
{
228
for (int j = 0; j < test_loop_times; j++)
229
{
230
random_roi();
231
232
int apertureSize = 3;
233
234
OCL_OFF(cv::cornerMinEigenVal(src_roi, dst_roi, blockSize, apertureSize, borderType));
235
OCL_ON(cv::cornerMinEigenVal(usrc_roi, udst_roi, blockSize, apertureSize, borderType));
236
237
Near(1e-5, true);
238
}
239
}
240
241
//////////////////////////////// cornerHarris //////////////////////////////////////////
242
243
typedef CornerTestBase CornerHarris;
244
245
OCL_TEST_P(CornerHarris, Mat)
246
{
247
for (int j = 0; j < test_loop_times; j++)
248
{
249
random_roi();
250
251
int apertureSize = 3;
252
double k = randomDouble(0.01, 0.9);
253
254
OCL_OFF(cv::cornerHarris(src_roi, dst_roi, blockSize, apertureSize, k, borderType));
255
OCL_ON(cv::cornerHarris(usrc_roi, udst_roi, blockSize, apertureSize, k, borderType));
256
257
Near(1e-6, true);
258
}
259
}
260
261
//////////////////////////////// preCornerDetect //////////////////////////////////////////
262
263
typedef ImgprocTestBase PreCornerDetect;
264
265
OCL_TEST_P(PreCornerDetect, Mat)
266
{
267
for (int j = 0; j < test_loop_times; j++)
268
{
269
random_roi();
270
271
const int apertureSize = blockSize;
272
273
OCL_OFF(cv::preCornerDetect(src_roi, dst_roi, apertureSize, borderType));
274
OCL_ON(cv::preCornerDetect(usrc_roi, udst_roi, apertureSize, borderType));
275
276
Near(1e-6, true);
277
}
278
}
279
280
281
////////////////////////////////// integral /////////////////////////////////////////////////
282
283
struct Integral :
284
public ImgprocTestBase
285
{
286
int sdepth, sqdepth;
287
288
TEST_DECLARE_OUTPUT_PARAMETER(dst2);
289
290
virtual void SetUp()
291
{
292
type = GET_PARAM(0);
293
sdepth = GET_PARAM(1);
294
sqdepth = GET_PARAM(2);
295
useRoi = GET_PARAM(3);
296
}
297
298
void random_roi()
299
{
300
ASSERT_EQ(CV_MAT_CN(type), 1);
301
302
Size roiSize = randomSize(1, MAX_VALUE), isize = Size(roiSize.width + 1, roiSize.height + 1);
303
Border srcBorder = randomBorder(0, useRoi ? 2 : 0);
304
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
305
306
Border dstBorder = randomBorder(0, useRoi ? 2 : 0);
307
randomSubMat(dst, dst_roi, isize, dstBorder, sdepth, 5, 16);
308
309
Border dst2Border = randomBorder(0, useRoi ? 2 : 0);
310
randomSubMat(dst2, dst2_roi, isize, dst2Border, sqdepth, 5, 16);
311
312
UMAT_UPLOAD_INPUT_PARAMETER(src);
313
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
314
UMAT_UPLOAD_OUTPUT_PARAMETER(dst2);
315
}
316
317
void Near2(double threshold = 0.0, bool relative = false)
318
{
319
if (relative)
320
OCL_EXPECT_MATS_NEAR_RELATIVE(dst2, threshold);
321
else
322
OCL_EXPECT_MATS_NEAR(dst2, threshold);
323
}
324
};
325
326
OCL_TEST_P(Integral, Mat1)
327
{
328
for (int j = 0; j < test_loop_times; j++)
329
{
330
random_roi();
331
332
OCL_OFF(cv::integral(src_roi, dst_roi, sdepth));
333
OCL_ON(cv::integral(usrc_roi, udst_roi, sdepth));
334
335
Near();
336
}
337
}
338
339
OCL_TEST_P(Integral, Mat2)
340
{
341
for (int j = 0; j < test_loop_times; j++)
342
{
343
random_roi();
344
345
OCL_OFF(cv::integral(src_roi, dst_roi, dst2_roi, sdepth, sqdepth));
346
OCL_ON(cv::integral(usrc_roi, udst_roi, udst2_roi, sdepth, sqdepth));
347
348
Near();
349
sqdepth == CV_32F ? Near2(1e-6, true) : Near2();
350
}
351
}
352
353
//////////////////////////////////////// threshold //////////////////////////////////////////////
354
355
struct Threshold :
356
public ImgprocTestBase
357
{
358
int thresholdType;
359
360
virtual void SetUp()
361
{
362
type = GET_PARAM(0);
363
thresholdType = GET_PARAM(2);
364
useRoi = GET_PARAM(3);
365
}
366
};
367
368
OCL_TEST_P(Threshold, Mat)
369
{
370
for (int j = 0; j < test_loop_times; j++)
371
{
372
random_roi();
373
374
double maxVal = randomDouble(20.0, 127.0);
375
double thresh = randomDouble(0.0, maxVal);
376
377
OCL_OFF(cv::threshold(src_roi, dst_roi, thresh, maxVal, thresholdType));
378
OCL_ON(cv::threshold(usrc_roi, udst_roi, thresh, maxVal, thresholdType));
379
380
Near(1);
381
}
382
}
383
384
/////////////////////////////////////////// CLAHE //////////////////////////////////////////////////
385
386
PARAM_TEST_CASE(CLAHETest, Size, double, bool)
387
{
388
Size gridSize;
389
double clipLimit;
390
bool useRoi;
391
392
TEST_DECLARE_INPUT_PARAMETER(src);
393
TEST_DECLARE_OUTPUT_PARAMETER(dst);
394
395
virtual void SetUp()
396
{
397
gridSize = GET_PARAM(0);
398
clipLimit = GET_PARAM(1);
399
useRoi = GET_PARAM(2);
400
}
401
402
void random_roi()
403
{
404
Size roiSize = randomSize(std::max(gridSize.height, gridSize.width), MAX_VALUE);
405
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
406
randomSubMat(src, src_roi, roiSize, srcBorder, CV_8UC1, 5, 256);
407
408
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
409
randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_8UC1, 5, 16);
410
411
UMAT_UPLOAD_INPUT_PARAMETER(src);
412
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
413
}
414
415
void Near(double threshold = 0.0)
416
{
417
OCL_EXPECT_MATS_NEAR(dst, threshold);
418
}
419
};
420
421
OCL_TEST_P(CLAHETest, Accuracy)
422
{
423
for (int i = 0; i < test_loop_times; ++i)
424
{
425
random_roi();
426
427
Ptr<CLAHE> clahe = cv::createCLAHE(clipLimit, gridSize);
428
429
OCL_OFF(clahe->apply(src_roi, dst_roi));
430
OCL_ON(clahe->apply(usrc_roi, udst_roi));
431
432
Near(1.0);
433
}
434
}
435
436
/////////////////////////////////////////////////////////////////////////////////////
437
438
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, EqualizeHist, Combine(
439
Values((MatType)CV_8UC1),
440
Values(0), // not used
441
Values(0), // not used
442
Bool()));
443
444
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerMinEigenVal, Combine(
445
Values((MatType)CV_8UC1, (MatType)CV_32FC1),
446
Values(3, 5),
447
Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
448
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT101),
449
Bool()));
450
451
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerHarris, Combine(
452
Values((MatType)CV_8UC1, CV_32FC1),
453
Values(3, 5),
454
Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
455
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
456
Bool()));
457
458
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, PreCornerDetect, Combine(
459
Values((MatType)CV_8UC1, CV_32FC1),
460
Values(3, 5),
461
Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
462
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
463
Bool()));
464
465
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Integral, Combine(
466
Values((MatType)CV_8UC1), // TODO does not work with CV_32F, CV_64F
467
Values(CV_32SC1, CV_32FC1), // desired sdepth
468
Values(CV_32FC1, CV_64FC1), // desired sqdepth
469
Bool()));
470
471
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(
472
Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4,
473
CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4,
474
CV_32FC1, CV_32FC2, CV_32FC3, CV_32FC4),
475
Values(0),
476
Values(ThreshOp(THRESH_BINARY),
477
ThreshOp(THRESH_BINARY_INV), ThreshOp(THRESH_TRUNC),
478
ThreshOp(THRESH_TOZERO), ThreshOp(THRESH_TOZERO_INV)),
479
Bool()));
480
481
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CLAHETest, Combine(
482
Values(Size(4, 4), Size(32, 8), Size(8, 64)),
483
Values(0.0, 10.0, 62.0, 300.0),
484
Bool()));
485
486
OCL_INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CopyMakeBorder, Combine(
487
testing::Values((MatDepth)CV_8U, (MatDepth)CV_16S, (MatDepth)CV_32S, (MatDepth)CV_32F),
488
testing::Values(Channels(1), Channels(3), (Channels)4),
489
Bool(), // border isolated or not
490
Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT,
491
(BorderType)BORDER_WRAP, (BorderType)BORDER_REFLECT_101),
492
Bool()));
493
494
} } // namespace opencv_test::ocl
495
496
#endif // HAVE_OPENCL
497
498