1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #include "test_precomp.hpp"
44 #if defined(HAVE_CUDA) && defined(HAVE_OPENGL)
46 /////////////////////////////////////////////
49 PARAM_TEST_CASE(GlBuffer, cv::Size, MatType)
51 static void SetUpTestCase()
53 cv::namedWindow("test", cv::WINDOW_OPENGL);
56 static void TearDownTestCase()
58 cv::destroyAllWindows();
71 GPU_TEST_P(GlBuffer, Constructor1)
73 cv::GlBuffer buf(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
75 EXPECT_EQ(size.height, buf.rows());
76 EXPECT_EQ(size.width, buf.cols());
77 EXPECT_EQ(type, buf.type());
80 GPU_TEST_P(GlBuffer, Constructor2)
82 cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
84 EXPECT_EQ(size.height, buf.rows());
85 EXPECT_EQ(size.width, buf.cols());
86 EXPECT_EQ(type, buf.type());
89 GPU_TEST_P(GlBuffer, ConstructorFromMat)
91 cv::Mat gold = randomMat(size, type);
93 cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
98 EXPECT_MAT_NEAR(gold, bufData, 0);
101 GPU_TEST_P(GlBuffer, ConstructorFromGpuMat)
103 cv::Mat gold = randomMat(size, type);
104 cv::gpu::GpuMat d_gold(gold);
106 cv::GlBuffer buf(d_gold, cv::GlBuffer::ARRAY_BUFFER);
111 EXPECT_MAT_NEAR(gold, bufData, 0);
114 GPU_TEST_P(GlBuffer, ConstructorFromGlBuffer)
116 cv::GlBuffer buf_gold(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
118 cv::GlBuffer buf(buf_gold);
120 EXPECT_EQ(buf_gold.bufId(), buf.bufId());
121 EXPECT_EQ(buf_gold.rows(), buf.rows());
122 EXPECT_EQ(buf_gold.cols(), buf.cols());
123 EXPECT_EQ(buf_gold.type(), buf.type());
126 GPU_TEST_P(GlBuffer, ConstructorFromGlTexture)
128 const int depth = CV_MAT_DEPTH(type);
129 const int cn = CV_MAT_CN(type);
131 if (depth != CV_32F || cn == 2)
134 cv::Mat gold = randomMat(size, type, 0, 1.0);
135 cv::GlTexture tex_gold(gold, true);
137 cv::GlBuffer buf(tex_gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
142 EXPECT_MAT_NEAR(gold, bufData, 1e-2);
145 GPU_TEST_P(GlBuffer, Create)
148 buf.create(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
150 EXPECT_EQ(size.height, buf.rows());
151 EXPECT_EQ(size.width, buf.cols());
152 EXPECT_EQ(type, buf.type());
155 GPU_TEST_P(GlBuffer, CopyFromMat)
157 cv::Mat gold = randomMat(size, type);
160 buf.copyFrom(gold, cv::GlBuffer::ARRAY_BUFFER, true);
165 EXPECT_MAT_NEAR(gold, bufData, 0);
168 GPU_TEST_P(GlBuffer, CopyFromGpuMat)
170 cv::Mat gold = randomMat(size, type);
171 cv::gpu::GpuMat d_gold(gold);
174 buf.copyFrom(d_gold, cv::GlBuffer::ARRAY_BUFFER, true);
179 EXPECT_MAT_NEAR(gold, bufData, 0);
182 GPU_TEST_P(GlBuffer, CopyFromGlBuffer)
184 cv::Mat gold = randomMat(size, type);
185 cv::GlBuffer buf_gold(gold, cv::GlBuffer::ARRAY_BUFFER, true);
188 buf.copyFrom(buf_gold, cv::GlBuffer::ARRAY_BUFFER, true);
190 EXPECT_NE(buf_gold.bufId(), buf.bufId());
195 EXPECT_MAT_NEAR(gold, bufData, 0);
198 GPU_TEST_P(GlBuffer, CopyFromGlTexture)
200 const int depth = CV_MAT_DEPTH(type);
201 const int cn = CV_MAT_CN(type);
203 if (depth != CV_32F || cn == 2)
206 cv::Mat gold = randomMat(size, type, 0, 1.0);
207 cv::GlTexture tex_gold(gold, true);
210 buf.copyFrom(tex_gold, cv::GlBuffer::ARRAY_BUFFER, true);
215 EXPECT_MAT_NEAR(gold, bufData, 1e-2);
218 GPU_TEST_P(GlBuffer, CopyToGpuMat)
220 cv::Mat gold = randomMat(size, type);
222 cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
227 EXPECT_MAT_NEAR(gold, dst, 0);
230 GPU_TEST_P(GlBuffer, CopyToGlBuffer)
232 cv::Mat gold = randomMat(size, type);
234 cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
237 buf.copyTo(dst, cv::GlBuffer::ARRAY_BUFFER, true);
239 EXPECT_NE(buf.bufId(), dst.bufId());
244 EXPECT_MAT_NEAR(gold, bufData, 0);
247 GPU_TEST_P(GlBuffer, CopyToGlTexture)
249 const int depth = CV_MAT_DEPTH(type);
250 const int cn = CV_MAT_CN(type);
252 if (depth != CV_32F || cn == 2)
255 cv::Mat gold = randomMat(size, type, 0, 1.0);
257 cv::GlBuffer buf(gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
260 buf.copyTo(tex, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
265 EXPECT_MAT_NEAR(gold, texData, 1e-2);
268 GPU_TEST_P(GlBuffer, Clone)
270 cv::Mat gold = randomMat(size, type);
272 cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
274 cv::GlBuffer dst = buf.clone(cv::GlBuffer::ARRAY_BUFFER, true);
276 EXPECT_NE(buf.bufId(), dst.bufId());
281 EXPECT_MAT_NEAR(gold, bufData, 0);
284 GPU_TEST_P(GlBuffer, MapHostRead)
286 cv::Mat gold = randomMat(size, type);
288 cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
290 cv::Mat dst = buf.mapHost(cv::GlBuffer::READ_ONLY);
292 EXPECT_MAT_NEAR(gold, dst, 0);
297 GPU_TEST_P(GlBuffer, MapHostWrite)
299 cv::Mat gold = randomMat(size, type);
301 cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
303 cv::Mat dst = buf.mapHost(cv::GlBuffer::WRITE_ONLY);
311 EXPECT_MAT_NEAR(gold, bufData, 0);
314 GPU_TEST_P(GlBuffer, MapDevice)
316 cv::Mat gold = randomMat(size, type);
318 cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
320 cv::gpu::GpuMat dst = buf.mapDevice();
322 EXPECT_MAT_NEAR(gold, dst, 0);
327 INSTANTIATE_TEST_CASE_P(OpenGL, GlBuffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES));
329 /////////////////////////////////////////////
332 PARAM_TEST_CASE(GlTexture, cv::Size, MatType)
334 static void SetUpTestCase()
336 cv::namedWindow("test", cv::WINDOW_OPENGL);
339 static void TearDownTestCase()
341 cv::destroyAllWindows();
348 cv::GlTexture::Format format;
355 depth = CV_MAT_DEPTH(type);
356 cn = CV_MAT_CN(type);
357 format = cn == 1 ? cv::GlTexture::DEPTH_COMPONENT : cn == 3 ? cv::GlTexture::RGB : cn == 4 ? cv::GlTexture::RGBA : cv::GlTexture::NONE;
361 GPU_TEST_P(GlTexture, Constructor1)
363 cv::GlTexture tex(size.height, size.width, format, true);
365 EXPECT_EQ(size.height, tex.rows());
366 EXPECT_EQ(size.width, tex.cols());
367 EXPECT_EQ(format, tex.format());
370 GPU_TEST_P(GlTexture, Constructor2)
372 cv::GlTexture tex(size, format, true);
374 EXPECT_EQ(size.height, tex.rows());
375 EXPECT_EQ(size.width, tex.cols());
376 EXPECT_EQ(format, tex.format());
379 GPU_TEST_P(GlTexture, ConstructorFromMat)
381 cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
383 cv::GlTexture tex(gold, true);
386 tex.copyTo(texData, depth);
388 EXPECT_MAT_NEAR(gold, texData, 1e-2);
391 GPU_TEST_P(GlTexture, ConstructorFromGpuMat)
393 cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
394 cv::gpu::GpuMat d_gold(gold);
396 cv::GlTexture tex(d_gold, true);
399 tex.copyTo(texData, depth);
401 EXPECT_MAT_NEAR(gold, texData, 1e-2);
404 GPU_TEST_P(GlTexture, ConstructorFromGlBuffer)
406 cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
407 cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
409 cv::GlTexture tex(buf_gold, true);
412 tex.copyTo(texData, depth);
414 EXPECT_MAT_NEAR(gold, texData, 1e-2);
417 GPU_TEST_P(GlTexture, ConstructorFromGlTexture)
419 cv::GlTexture tex_gold(size, format, true);
420 cv::GlTexture tex(tex_gold);
422 EXPECT_EQ(tex_gold.texId(), tex.texId());
423 EXPECT_EQ(tex_gold.rows(), tex.rows());
424 EXPECT_EQ(tex_gold.cols(), tex.cols());
425 EXPECT_EQ(tex_gold.format(), tex.format());
428 GPU_TEST_P(GlTexture, Create)
431 tex.create(size.height, size.width, format, true);
433 EXPECT_EQ(size.height, tex.rows());
434 EXPECT_EQ(size.width, tex.cols());
435 EXPECT_EQ(format, tex.format());
438 GPU_TEST_P(GlTexture, CopyFromMat)
440 cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
443 tex.copyFrom(gold, true);
446 tex.copyTo(texData, depth);
448 EXPECT_MAT_NEAR(gold, texData, 1e-2);
451 GPU_TEST_P(GlTexture, CopyFromGpuMat)
453 cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
454 cv::gpu::GpuMat d_gold(gold);
457 tex.copyFrom(d_gold, true);
460 tex.copyTo(texData, depth);
462 EXPECT_MAT_NEAR(gold, texData, 1e-2);
465 GPU_TEST_P(GlTexture, CopyFromGlBuffer)
467 cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
468 cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
471 tex.copyFrom(buf_gold, true);
474 tex.copyTo(texData, depth);
476 EXPECT_MAT_NEAR(gold, texData, 1e-2);
479 GPU_TEST_P(GlTexture, CopyToGpuMat)
481 cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
483 cv::GlTexture tex(gold, true);
486 tex.copyTo(dst, depth);
488 EXPECT_MAT_NEAR(gold, dst, 1e-2);
491 GPU_TEST_P(GlTexture, CopyToGlBuffer)
493 cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
495 cv::GlTexture tex(gold, true);
498 tex.copyTo(dst, depth, true);
503 EXPECT_MAT_NEAR(gold, bufData, 1e-2);
506 INSTANTIATE_TEST_CASE_P(OpenGL, GlTexture, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4)));