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) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #include "test_precomp.hpp"
44
45 #ifdef HAVE_CUDA
46
47 using namespace cvtest;
48
49 ////////////////////////////////////////////////////////////////////////////////
50 // Merge
51
PARAM_TEST_CASE(Merge,cv::cuda::DeviceInfo,cv::Size,MatDepth,Channels,UseRoi)52 PARAM_TEST_CASE(Merge, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
53 {
54 cv::cuda::DeviceInfo devInfo;
55 cv::Size size;
56 int depth;
57 int channels;
58 bool useRoi;
59
60 virtual void SetUp()
61 {
62 devInfo = GET_PARAM(0);
63 size = GET_PARAM(1);
64 depth = GET_PARAM(2);
65 channels = GET_PARAM(3);
66 useRoi = GET_PARAM(4);
67
68 cv::cuda::setDevice(devInfo.deviceID());
69 }
70 };
71
CUDA_TEST_P(Merge,Accuracy)72 CUDA_TEST_P(Merge, Accuracy)
73 {
74 std::vector<cv::Mat> src;
75 src.reserve(channels);
76 for (int i = 0; i < channels; ++i)
77 src.push_back(cv::Mat(size, depth, cv::Scalar::all(i)));
78
79 std::vector<cv::cuda::GpuMat> d_src;
80 for (int i = 0; i < channels; ++i)
81 d_src.push_back(loadMat(src[i], useRoi));
82
83 if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
84 {
85 try
86 {
87 cv::cuda::GpuMat dst;
88 cv::cuda::merge(d_src, dst);
89 }
90 catch (const cv::Exception& e)
91 {
92 ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
93 }
94 }
95 else
96 {
97 cv::cuda::GpuMat dst;
98 cv::cuda::merge(d_src, dst);
99
100 cv::Mat dst_gold;
101 cv::merge(src, dst_gold);
102
103 EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
104 }
105 }
106
107 INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Merge, testing::Combine(
108 ALL_DEVICES,
109 DIFFERENT_SIZES,
110 ALL_DEPTH,
111 testing::Values(1, 2, 3, 4),
112 WHOLE_SUBMAT));
113
114 ////////////////////////////////////////////////////////////////////////////////
115 // Split
116
PARAM_TEST_CASE(Split,cv::cuda::DeviceInfo,cv::Size,MatDepth,Channels,UseRoi)117 PARAM_TEST_CASE(Split, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
118 {
119 cv::cuda::DeviceInfo devInfo;
120 cv::Size size;
121 int depth;
122 int channels;
123 bool useRoi;
124
125 int type;
126
127 virtual void SetUp()
128 {
129 devInfo = GET_PARAM(0);
130 size = GET_PARAM(1);
131 depth = GET_PARAM(2);
132 channels = GET_PARAM(3);
133 useRoi = GET_PARAM(4);
134
135 cv::cuda::setDevice(devInfo.deviceID());
136
137 type = CV_MAKE_TYPE(depth, channels);
138 }
139 };
140
CUDA_TEST_P(Split,Accuracy)141 CUDA_TEST_P(Split, Accuracy)
142 {
143 cv::Mat src = randomMat(size, type);
144
145 if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
146 {
147 try
148 {
149 std::vector<cv::cuda::GpuMat> dst;
150 cv::cuda::split(loadMat(src), dst);
151 }
152 catch (const cv::Exception& e)
153 {
154 ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
155 }
156 }
157 else
158 {
159 std::vector<cv::cuda::GpuMat> dst;
160 cv::cuda::split(loadMat(src, useRoi), dst);
161
162 std::vector<cv::Mat> dst_gold;
163 cv::split(src, dst_gold);
164
165 ASSERT_EQ(dst_gold.size(), dst.size());
166
167 for (size_t i = 0; i < dst_gold.size(); ++i)
168 {
169 EXPECT_MAT_NEAR(dst_gold[i], dst[i], 0.0);
170 }
171 }
172 }
173
174 INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Split, testing::Combine(
175 ALL_DEVICES,
176 DIFFERENT_SIZES,
177 ALL_DEPTH,
178 testing::Values(1, 2, 3, 4),
179 WHOLE_SUBMAT));
180
181 ////////////////////////////////////////////////////////////////////////////////
182 // Transpose
183
PARAM_TEST_CASE(Transpose,cv::cuda::DeviceInfo,cv::Size,MatType,UseRoi)184 PARAM_TEST_CASE(Transpose, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
185 {
186 cv::cuda::DeviceInfo devInfo;
187 cv::Size size;
188 int type;
189 bool useRoi;
190
191 virtual void SetUp()
192 {
193 devInfo = GET_PARAM(0);
194 size = GET_PARAM(1);
195 type = GET_PARAM(2);
196 useRoi = GET_PARAM(3);
197
198 cv::cuda::setDevice(devInfo.deviceID());
199 }
200 };
201
CUDA_TEST_P(Transpose,Accuracy)202 CUDA_TEST_P(Transpose, Accuracy)
203 {
204 cv::Mat src = randomMat(size, type);
205
206 if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
207 {
208 try
209 {
210 cv::cuda::GpuMat dst;
211 cv::cuda::transpose(loadMat(src), dst);
212 }
213 catch (const cv::Exception& e)
214 {
215 ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
216 }
217 }
218 else
219 {
220 cv::cuda::GpuMat dst = createMat(cv::Size(size.height, size.width), type, useRoi);
221 cv::cuda::transpose(loadMat(src, useRoi), dst);
222
223 cv::Mat dst_gold;
224 cv::transpose(src, dst_gold);
225
226 EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
227 }
228 }
229
230 INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Transpose, testing::Combine(
231 ALL_DEVICES,
232 DIFFERENT_SIZES,
233 testing::Values(MatType(CV_8UC1),
234 MatType(CV_8UC4),
235 MatType(CV_16UC2),
236 MatType(CV_16SC2),
237 MatType(CV_32SC1),
238 MatType(CV_32SC2),
239 MatType(CV_64FC1)),
240 WHOLE_SUBMAT));
241
242 ////////////////////////////////////////////////////////////////////////////////
243 // Flip
244
245 enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
CV_ENUM(FlipCode,FLIP_BOTH,FLIP_X,FLIP_Y)246 CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
247 #define ALL_FLIP_CODES testing::Values(FlipCode(FLIP_BOTH), FlipCode(FLIP_X), FlipCode(FLIP_Y))
248
249 PARAM_TEST_CASE(Flip, cv::cuda::DeviceInfo, cv::Size, MatType, FlipCode, UseRoi)
250 {
251 cv::cuda::DeviceInfo devInfo;
252 cv::Size size;
253 int type;
254 int flip_code;
255 bool useRoi;
256
257 virtual void SetUp()
258 {
259 devInfo = GET_PARAM(0);
260 size = GET_PARAM(1);
261 type = GET_PARAM(2);
262 flip_code = GET_PARAM(3);
263 useRoi = GET_PARAM(4);
264
265 cv::cuda::setDevice(devInfo.deviceID());
266 }
267 };
268
CUDA_TEST_P(Flip,Accuracy)269 CUDA_TEST_P(Flip, Accuracy)
270 {
271 cv::Mat src = randomMat(size, type);
272
273 cv::cuda::GpuMat dst = createMat(size, type, useRoi);
274 cv::cuda::flip(loadMat(src, useRoi), dst, flip_code);
275
276 cv::Mat dst_gold;
277 cv::flip(src, dst_gold, flip_code);
278
279 EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
280 }
281
282 INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Flip, testing::Combine(
283 ALL_DEVICES,
284 DIFFERENT_SIZES,
285 testing::Values(MatType(CV_8UC1),
286 MatType(CV_8UC3),
287 MatType(CV_8UC4),
288 MatType(CV_16UC1),
289 MatType(CV_16UC3),
290 MatType(CV_16UC4),
291 MatType(CV_32SC1),
292 MatType(CV_32SC3),
293 MatType(CV_32SC4),
294 MatType(CV_32FC1),
295 MatType(CV_32FC3),
296 MatType(CV_32FC4)),
297 ALL_FLIP_CODES,
298 WHOLE_SUBMAT));
299
300 ////////////////////////////////////////////////////////////////////////////////
301 // LUT
302
PARAM_TEST_CASE(LUT,cv::cuda::DeviceInfo,cv::Size,MatType,UseRoi)303 PARAM_TEST_CASE(LUT, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
304 {
305 cv::cuda::DeviceInfo devInfo;
306 cv::Size size;
307 int type;
308 bool useRoi;
309
310 virtual void SetUp()
311 {
312 devInfo = GET_PARAM(0);
313 size = GET_PARAM(1);
314 type = GET_PARAM(2);
315 useRoi = GET_PARAM(3);
316
317 cv::cuda::setDevice(devInfo.deviceID());
318 }
319 };
320
CUDA_TEST_P(LUT,OneChannel)321 CUDA_TEST_P(LUT, OneChannel)
322 {
323 cv::Mat src = randomMat(size, type);
324 cv::Mat lut = randomMat(cv::Size(256, 1), CV_8UC1);
325
326 cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
327
328 cv::cuda::GpuMat dst = createMat(size, CV_MAKE_TYPE(lut.depth(), src.channels()));
329 lutAlg->transform(loadMat(src, useRoi), dst);
330
331 cv::Mat dst_gold;
332 cv::LUT(src, lut, dst_gold);
333
334 EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
335 }
336
CUDA_TEST_P(LUT,MultiChannel)337 CUDA_TEST_P(LUT, MultiChannel)
338 {
339 cv::Mat src = randomMat(size, type);
340 cv::Mat lut = randomMat(cv::Size(256, 1), CV_MAKE_TYPE(CV_8U, src.channels()));
341
342 cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
343
344 cv::cuda::GpuMat dst = createMat(size, CV_MAKE_TYPE(lut.depth(), src.channels()), useRoi);
345 lutAlg->transform(loadMat(src, useRoi), dst);
346
347 cv::Mat dst_gold;
348 cv::LUT(src, lut, dst_gold);
349
350 EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
351 }
352
353 INSTANTIATE_TEST_CASE_P(CUDA_Arithm, LUT, testing::Combine(
354 ALL_DEVICES,
355 DIFFERENT_SIZES,
356 testing::Values(MatType(CV_8UC1), MatType(CV_8UC3)),
357 WHOLE_SUBMAT));
358
359 //////////////////////////////////////////////////////////////////////////////
360 // CopyMakeBorder
361
362 namespace
363 {
364 IMPLEMENT_PARAM_CLASS(Border, int)
365 }
366
PARAM_TEST_CASE(CopyMakeBorder,cv::cuda::DeviceInfo,cv::Size,MatType,Border,BorderType,UseRoi)367 PARAM_TEST_CASE(CopyMakeBorder, cv::cuda::DeviceInfo, cv::Size, MatType, Border, BorderType, UseRoi)
368 {
369 cv::cuda::DeviceInfo devInfo;
370 cv::Size size;
371 int type;
372 int border;
373 int borderType;
374 bool useRoi;
375
376 virtual void SetUp()
377 {
378 devInfo = GET_PARAM(0);
379 size = GET_PARAM(1);
380 type = GET_PARAM(2);
381 border = GET_PARAM(3);
382 borderType = GET_PARAM(4);
383 useRoi = GET_PARAM(5);
384
385 cv::cuda::setDevice(devInfo.deviceID());
386 }
387 };
388
CUDA_TEST_P(CopyMakeBorder,Accuracy)389 CUDA_TEST_P(CopyMakeBorder, Accuracy)
390 {
391 cv::Mat src = randomMat(size, type);
392 cv::Scalar val = randomScalar(0, 255);
393
394 cv::cuda::GpuMat dst = createMat(cv::Size(size.width + 2 * border, size.height + 2 * border), type, useRoi);
395 cv::cuda::copyMakeBorder(loadMat(src, useRoi), dst, border, border, border, border, borderType, val);
396
397 cv::Mat dst_gold;
398 cv::copyMakeBorder(src, dst_gold, border, border, border, border, borderType, val);
399
400 EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
401 }
402
403 INSTANTIATE_TEST_CASE_P(CUDA_Arithm, CopyMakeBorder, testing::Combine(
404 ALL_DEVICES,
405 DIFFERENT_SIZES,
406 testing::Values(MatType(CV_8UC1),
407 MatType(CV_8UC3),
408 MatType(CV_8UC4),
409 MatType(CV_16UC1),
410 MatType(CV_16UC3),
411 MatType(CV_16UC4),
412 MatType(CV_32FC1),
413 MatType(CV_32FC3),
414 MatType(CV_32FC4)),
415 testing::Values(Border(1), Border(10), Border(50)),
416 ALL_BORDER_TYPES,
417 WHOLE_SUBMAT));
418
419 #endif // HAVE_CUDA
420