mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
457 lines
11 KiB
457 lines
11 KiB
12 years ago
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||
|
//
|
||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||
|
// If you do not agree to this license, do not download, install,
|
||
|
// copy or use the software.
|
||
|
//
|
||
|
//
|
||
12 years ago
|
// License Agreement
|
||
12 years ago
|
// For Open Source Computer Vision Library
|
||
|
//
|
||
12 years ago
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||
12 years ago
|
// Third party copyrights are property of their respective owners.
|
||
|
//
|
||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||
|
// are permitted provided that the following conditions are met:
|
||
|
//
|
||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||
|
// this list of conditions and the following disclaimer.
|
||
|
//
|
||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||
|
// this list of conditions and the following disclaimer in the documentation
|
||
|
// and/or other materials provided with the distribution.
|
||
|
//
|
||
12 years ago
|
// * The name of the copyright holders may not be used to endorse or promote products
|
||
12 years ago
|
// derived from this software without specific prior written permission.
|
||
|
//
|
||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||
|
// any express or implied warranties, including, but not limited to, the implied
|
||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||
|
// loss of use, data, or profits; or business interruption) however caused
|
||
|
// and on any theory of liability, whether in contract, strict liability,
|
||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||
|
// the use of this software, even if advised of the possibility of such damage.
|
||
|
//
|
||
|
//M*/
|
||
|
|
||
10 years ago
|
#include "test_precomp.hpp"
|
||
12 years ago
|
|
||
|
#if defined(HAVE_CUDA) && defined(HAVE_OPENGL)
|
||
|
|
||
10 years ago
|
#include "opencv2/core/cuda.hpp"
|
||
|
#include "opencv2/core/opengl.hpp"
|
||
|
#include "opencv2/ts/cuda_test.hpp"
|
||
|
|
||
12 years ago
|
using namespace cvtest;
|
||
|
|
||
12 years ago
|
/////////////////////////////////////////////
|
||
12 years ago
|
// Buffer
|
||
12 years ago
|
|
||
12 years ago
|
PARAM_TEST_CASE(Buffer, cv::Size, MatType)
|
||
12 years ago
|
{
|
||
|
static void SetUpTestCase()
|
||
|
{
|
||
|
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||
|
}
|
||
|
|
||
|
static void TearDownTestCase()
|
||
|
{
|
||
|
cv::destroyAllWindows();
|
||
|
}
|
||
|
|
||
|
cv::Size size;
|
||
|
int type;
|
||
|
|
||
|
virtual void SetUp()
|
||
|
{
|
||
|
size = GET_PARAM(0);
|
||
|
type = GET_PARAM(1);
|
||
|
}
|
||
|
};
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, Constructor1)
|
||
12 years ago
|
{
|
||
12 years ago
|
cv::ogl::Buffer buf(size.height, size.width, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
|
EXPECT_EQ(size.height, buf.rows());
|
||
|
EXPECT_EQ(size.width, buf.cols());
|
||
|
EXPECT_EQ(type, buf.type());
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, Constructor2)
|
||
12 years ago
|
{
|
||
12 years ago
|
cv::ogl::Buffer buf(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
|
EXPECT_EQ(size.height, buf.rows());
|
||
|
EXPECT_EQ(size.width, buf.cols());
|
||
|
EXPECT_EQ(type, buf.type());
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, ConstructorFromMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
|
|
||
12 years ago
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
|
cv::Mat bufData;
|
||
|
buf.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, ConstructorFromGpuMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
11 years ago
|
cv::cuda::GpuMat d_gold(gold);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Buffer buf(d_gold, cv::ogl::Buffer::ARRAY_BUFFER);
|
||
12 years ago
|
|
||
|
cv::Mat bufData;
|
||
|
buf.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, ConstructorFromBuffer)
|
||
12 years ago
|
{
|
||
12 years ago
|
cv::ogl::Buffer buf_gold(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Buffer buf(buf_gold);
|
||
12 years ago
|
|
||
|
EXPECT_EQ(buf_gold.bufId(), buf.bufId());
|
||
|
EXPECT_EQ(buf_gold.rows(), buf.rows());
|
||
|
EXPECT_EQ(buf_gold.cols(), buf.cols());
|
||
|
EXPECT_EQ(buf_gold.type(), buf.type());
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, Create)
|
||
12 years ago
|
{
|
||
12 years ago
|
cv::ogl::Buffer buf;
|
||
|
buf.create(size.height, size.width, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
|
EXPECT_EQ(size.height, buf.rows());
|
||
|
EXPECT_EQ(size.width, buf.cols());
|
||
|
EXPECT_EQ(type, buf.type());
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, CopyFromMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
|
|
||
12 years ago
|
cv::ogl::Buffer buf;
|
||
|
buf.copyFrom(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
|
cv::Mat bufData;
|
||
|
buf.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, CopyFromGpuMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
11 years ago
|
cv::cuda::GpuMat d_gold(gold);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Buffer buf;
|
||
|
buf.copyFrom(d_gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
|
cv::Mat bufData;
|
||
|
buf.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, CopyFromBuffer)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
12 years ago
|
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Buffer buf;
|
||
|
buf.copyFrom(buf_gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
|
EXPECT_NE(buf_gold.bufId(), buf.bufId());
|
||
|
|
||
|
cv::Mat bufData;
|
||
|
buf.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, CopyToGpuMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
|
|
||
12 years ago
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
11 years ago
|
cv::cuda::GpuMat dst;
|
||
12 years ago
|
buf.copyTo(dst);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, dst, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, CopyToBuffer)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
|
|
||
12 years ago
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Buffer dst;
|
||
12 years ago
|
buf.copyTo(dst);
|
||
|
dst.setAutoRelease(true);
|
||
12 years ago
|
|
||
|
EXPECT_NE(buf.bufId(), dst.bufId());
|
||
|
|
||
|
cv::Mat bufData;
|
||
|
dst.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, Clone)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
|
|
||
12 years ago
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Buffer dst = buf.clone(cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
|
EXPECT_NE(buf.bufId(), dst.bufId());
|
||
|
|
||
|
cv::Mat bufData;
|
||
|
dst.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, MapHostRead)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
|
|
||
12 years ago
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::Mat dst = buf.mapHost(cv::ogl::Buffer::READ_ONLY);
|
||
12 years ago
|
|
||
|
EXPECT_MAT_NEAR(gold, dst, 0);
|
||
|
|
||
|
buf.unmapHost();
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, MapHostWrite)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
|
|
||
12 years ago
|
cv::ogl::Buffer buf(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::Mat dst = buf.mapHost(cv::ogl::Buffer::WRITE_ONLY);
|
||
12 years ago
|
gold.copyTo(dst);
|
||
|
buf.unmapHost();
|
||
|
dst.release();
|
||
|
|
||
|
cv::Mat bufData;
|
||
|
buf.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Buffer, MapDevice)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type);
|
||
|
|
||
12 years ago
|
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||
12 years ago
|
|
||
11 years ago
|
cv::cuda::GpuMat dst = buf.mapDevice();
|
||
12 years ago
|
|
||
|
EXPECT_MAT_NEAR(gold, dst, 0);
|
||
|
|
||
|
buf.unmapDevice();
|
||
|
}
|
||
|
|
||
12 years ago
|
INSTANTIATE_TEST_CASE_P(OpenGL, Buffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES));
|
||
12 years ago
|
|
||
|
/////////////////////////////////////////////
|
||
12 years ago
|
// Texture2D
|
||
12 years ago
|
|
||
12 years ago
|
PARAM_TEST_CASE(Texture2D, cv::Size, MatType)
|
||
12 years ago
|
{
|
||
|
static void SetUpTestCase()
|
||
|
{
|
||
|
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||
|
}
|
||
|
|
||
|
static void TearDownTestCase()
|
||
|
{
|
||
|
cv::destroyAllWindows();
|
||
|
}
|
||
|
|
||
|
cv::Size size;
|
||
|
int type;
|
||
|
int depth;
|
||
|
int cn;
|
||
12 years ago
|
cv::ogl::Texture2D::Format format;
|
||
12 years ago
|
|
||
|
virtual void SetUp()
|
||
|
{
|
||
|
size = GET_PARAM(0);
|
||
|
type = GET_PARAM(1);
|
||
|
|
||
|
depth = CV_MAT_DEPTH(type);
|
||
|
cn = CV_MAT_CN(type);
|
||
12 years ago
|
format = cn == 1 ? cv::ogl::Texture2D::DEPTH_COMPONENT : cn == 3 ? cv::ogl::Texture2D::RGB : cn == 4 ? cv::ogl::Texture2D::RGBA : cv::ogl::Texture2D::NONE;
|
||
12 years ago
|
}
|
||
|
};
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, Constructor1)
|
||
12 years ago
|
{
|
||
12 years ago
|
cv::ogl::Texture2D tex(size.height, size.width, format, true);
|
||
12 years ago
|
|
||
|
EXPECT_EQ(size.height, tex.rows());
|
||
|
EXPECT_EQ(size.width, tex.cols());
|
||
|
EXPECT_EQ(format, tex.format());
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, Constructor2)
|
||
12 years ago
|
{
|
||
12 years ago
|
cv::ogl::Texture2D tex(size, format, true);
|
||
12 years ago
|
|
||
|
EXPECT_EQ(size.height, tex.rows());
|
||
|
EXPECT_EQ(size.width, tex.cols());
|
||
|
EXPECT_EQ(format, tex.format());
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, ConstructorFromMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||
|
|
||
12 years ago
|
cv::ogl::Texture2D tex(gold, true);
|
||
12 years ago
|
|
||
|
cv::Mat texData;
|
||
|
tex.copyTo(texData, depth);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, ConstructorFromGpuMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||
11 years ago
|
cv::cuda::GpuMat d_gold(gold);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Texture2D tex(d_gold, true);
|
||
12 years ago
|
|
||
|
cv::Mat texData;
|
||
|
tex.copyTo(texData, depth);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, ConstructorFromBuffer)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||
12 years ago
|
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Texture2D tex(buf_gold, true);
|
||
12 years ago
|
|
||
|
cv::Mat texData;
|
||
|
tex.copyTo(texData, depth);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, ConstructorFromTexture2D)
|
||
12 years ago
|
{
|
||
12 years ago
|
cv::ogl::Texture2D tex_gold(size, format, true);
|
||
|
cv::ogl::Texture2D tex(tex_gold);
|
||
12 years ago
|
|
||
|
EXPECT_EQ(tex_gold.texId(), tex.texId());
|
||
|
EXPECT_EQ(tex_gold.rows(), tex.rows());
|
||
|
EXPECT_EQ(tex_gold.cols(), tex.cols());
|
||
|
EXPECT_EQ(tex_gold.format(), tex.format());
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, Create)
|
||
12 years ago
|
{
|
||
12 years ago
|
cv::ogl::Texture2D tex;
|
||
12 years ago
|
tex.create(size.height, size.width, format, true);
|
||
|
|
||
|
EXPECT_EQ(size.height, tex.rows());
|
||
|
EXPECT_EQ(size.width, tex.cols());
|
||
|
EXPECT_EQ(format, tex.format());
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, CopyFromMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||
|
|
||
12 years ago
|
cv::ogl::Texture2D tex;
|
||
12 years ago
|
tex.copyFrom(gold, true);
|
||
|
|
||
|
cv::Mat texData;
|
||
|
tex.copyTo(texData, depth);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, CopyFromGpuMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||
11 years ago
|
cv::cuda::GpuMat d_gold(gold);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Texture2D tex;
|
||
12 years ago
|
tex.copyFrom(d_gold, true);
|
||
|
|
||
|
cv::Mat texData;
|
||
|
tex.copyTo(texData, depth);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, CopyFromBuffer)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||
12 years ago
|
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Texture2D tex;
|
||
12 years ago
|
tex.copyFrom(buf_gold, true);
|
||
|
|
||
|
cv::Mat texData;
|
||
|
tex.copyTo(texData, depth);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, CopyToGpuMat)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||
|
|
||
12 years ago
|
cv::ogl::Texture2D tex(gold, true);
|
||
12 years ago
|
|
||
11 years ago
|
cv::cuda::GpuMat dst;
|
||
12 years ago
|
tex.copyTo(dst, depth);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, dst, 1e-2);
|
||
|
}
|
||
|
|
||
11 years ago
|
CUDA_TEST_P(Texture2D, CopyToBuffer)
|
||
12 years ago
|
{
|
||
|
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||
|
|
||
12 years ago
|
cv::ogl::Texture2D tex(gold, true);
|
||
12 years ago
|
|
||
12 years ago
|
cv::ogl::Buffer dst;
|
||
12 years ago
|
tex.copyTo(dst, depth, true);
|
||
|
|
||
|
cv::Mat bufData;
|
||
|
dst.copyTo(bufData);
|
||
|
|
||
|
EXPECT_MAT_NEAR(gold, bufData, 1e-2);
|
||
|
}
|
||
|
|
||
12 years ago
|
INSTANTIATE_TEST_CASE_P(OpenGL, Texture2D, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4)));
|
||
12 years ago
|
|
||
|
#endif
|