vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,433 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// 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*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// GEMM
|
||||
|
||||
#ifdef HAVE_CUBLAS
|
||||
|
||||
CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T);
|
||||
#define ALL_GEMM_FLAGS testing::Values(GemmFlags(0), GemmFlags(cv::GEMM_1_T), GemmFlags(cv::GEMM_2_T), GemmFlags(cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T | cv::GEMM_3_T))
|
||||
|
||||
PARAM_TEST_CASE(GEMM, cv::cuda::DeviceInfo, cv::Size, MatType, GemmFlags, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int flags;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
flags = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GEMM, Accuracy)
|
||||
{
|
||||
cv::Mat src1 = randomMat(size, type, -10.0, 10.0);
|
||||
cv::Mat src2 = randomMat(size, type, -10.0, 10.0);
|
||||
cv::Mat src3 = randomMat(size, type, -10.0, 10.0);
|
||||
double alpha = randomDouble(-10.0, 10.0);
|
||||
double beta = randomDouble(-10.0, 10.0);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::gemm(loadMat(src1), loadMat(src2), alpha, loadMat(src3), beta, dst, flags);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else if (type == CV_64FC2 && flags != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::gemm(loadMat(src1), loadMat(src2), alpha, loadMat(src3), beta, dst, flags);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsNotImplemented, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::cuda::gemm(loadMat(src1, useRoi), loadMat(src2, useRoi), alpha, loadMat(src3, useRoi), beta, dst, flags);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::gemm(src1, src2, alpha, src3, beta, dst_gold, flags);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) == CV_32F ? 1e-1 : 1e-10);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, GEMM, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_32FC1), MatType(CV_32FC2), MatType(CV_64FC1), MatType(CV_64FC2)),
|
||||
ALL_GEMM_FLAGS,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// MulSpectrums
|
||||
|
||||
CV_FLAGS(DftFlags, 0, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT)
|
||||
|
||||
PARAM_TEST_CASE(MulSpectrums, cv::cuda::DeviceInfo, cv::Size, DftFlags)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int flag;
|
||||
|
||||
cv::Mat a, b;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
flag = GET_PARAM(2);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
a = randomMat(size, CV_32FC2);
|
||||
b = randomMat(size, CV_32FC2);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(MulSpectrums, Simple)
|
||||
{
|
||||
cv::cuda::GpuMat c;
|
||||
cv::cuda::mulSpectrums(loadMat(a), loadMat(b), c, flag, false);
|
||||
|
||||
cv::Mat c_gold;
|
||||
cv::mulSpectrums(a, b, c_gold, flag, false);
|
||||
|
||||
EXPECT_MAT_NEAR(c_gold, c, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(MulSpectrums, Scaled)
|
||||
{
|
||||
float scale = 1.f / size.area();
|
||||
|
||||
cv::cuda::GpuMat c;
|
||||
cv::cuda::mulAndScaleSpectrums(loadMat(a), loadMat(b), c, flag, scale, false);
|
||||
|
||||
cv::Mat c_gold;
|
||||
cv::mulSpectrums(a, b, c_gold, flag, false);
|
||||
c_gold.convertTo(c_gold, c_gold.type(), scale);
|
||||
|
||||
EXPECT_MAT_NEAR(c_gold, c, 1e-2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, MulSpectrums, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(DftFlags(0), DftFlags(cv::DFT_ROWS))));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Dft
|
||||
|
||||
struct Dft : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
void testC2C(const std::string& hint, int cols, int rows, int flags, bool inplace)
|
||||
{
|
||||
SCOPED_TRACE(hint);
|
||||
|
||||
cv::Mat a = randomMat(cv::Size(cols, rows), CV_32FC2, 0.0, 10.0);
|
||||
|
||||
cv::Mat b_gold;
|
||||
cv::dft(a, b_gold, flags);
|
||||
|
||||
cv::cuda::GpuMat d_b;
|
||||
cv::cuda::GpuMat d_b_data;
|
||||
if (inplace)
|
||||
{
|
||||
d_b_data.create(1, a.size().area(), CV_32FC2);
|
||||
d_b = cv::cuda::GpuMat(a.rows, a.cols, CV_32FC2, d_b_data.ptr(), a.cols * d_b_data.elemSize());
|
||||
}
|
||||
cv::cuda::dft(loadMat(a), d_b, cv::Size(cols, rows), flags);
|
||||
|
||||
EXPECT_TRUE(!inplace || d_b.ptr() == d_b_data.ptr());
|
||||
ASSERT_EQ(CV_32F, d_b.depth());
|
||||
ASSERT_EQ(2, d_b.channels());
|
||||
EXPECT_MAT_NEAR(b_gold, cv::Mat(d_b), rows * cols * 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Dft, C2C)
|
||||
{
|
||||
int cols = randomInt(2, 100);
|
||||
int rows = randomInt(2, 100);
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
bool inplace = i != 0;
|
||||
|
||||
testC2C("no flags", cols, rows, 0, inplace);
|
||||
testC2C("no flags 0 1", cols, rows + 1, 0, inplace);
|
||||
testC2C("no flags 1 0", cols, rows + 1, 0, inplace);
|
||||
testC2C("no flags 1 1", cols + 1, rows, 0, inplace);
|
||||
testC2C("DFT_INVERSE", cols, rows, cv::DFT_INVERSE, inplace);
|
||||
testC2C("DFT_ROWS", cols, rows, cv::DFT_ROWS, inplace);
|
||||
testC2C("single col", 1, rows, 0, inplace);
|
||||
testC2C("single row", cols, 1, 0, inplace);
|
||||
testC2C("single col inversed", 1, rows, cv::DFT_INVERSE, inplace);
|
||||
testC2C("single row inversed", cols, 1, cv::DFT_INVERSE, inplace);
|
||||
testC2C("single row DFT_ROWS", cols, 1, cv::DFT_ROWS, inplace);
|
||||
testC2C("size 1 2", 1, 2, 0, inplace);
|
||||
testC2C("size 2 1", 2, 1, 0, inplace);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Dft, Algorithm)
|
||||
{
|
||||
int cols = randomInt(2, 100);
|
||||
int rows = randomInt(2, 100);
|
||||
|
||||
int flags = 0 | DFT_COMPLEX_INPUT;
|
||||
cv::Ptr<cv::cuda::DFT> dft = cv::cuda::createDFT(cv::Size(cols, rows), flags);
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
SCOPED_TRACE("dft algorithm");
|
||||
|
||||
cv::Mat a = randomMat(cv::Size(cols, rows), CV_32FC2, 0.0, 10.0);
|
||||
|
||||
cv::cuda::GpuMat d_b;
|
||||
cv::cuda::GpuMat d_b_data;
|
||||
dft->compute(loadMat(a), d_b);
|
||||
|
||||
cv::Mat b_gold;
|
||||
cv::dft(a, b_gold, flags);
|
||||
|
||||
ASSERT_EQ(CV_32F, d_b.depth());
|
||||
ASSERT_EQ(2, d_b.channels());
|
||||
EXPECT_MAT_NEAR(b_gold, cv::Mat(d_b), rows * cols * 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void testR2CThenC2R(const std::string& hint, int cols, int rows, bool inplace)
|
||||
{
|
||||
SCOPED_TRACE(hint);
|
||||
|
||||
cv::Mat a = randomMat(cv::Size(cols, rows), CV_32FC1, 0.0, 10.0);
|
||||
|
||||
cv::cuda::GpuMat d_b, d_c;
|
||||
cv::cuda::GpuMat d_b_data, d_c_data;
|
||||
if (inplace)
|
||||
{
|
||||
if (a.cols == 1)
|
||||
{
|
||||
d_b_data.create(1, (a.rows / 2 + 1) * a.cols, CV_32FC2);
|
||||
d_b = cv::cuda::GpuMat(a.rows / 2 + 1, a.cols, CV_32FC2, d_b_data.ptr(), a.cols * d_b_data.elemSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
d_b_data.create(1, a.rows * (a.cols / 2 + 1), CV_32FC2);
|
||||
d_b = cv::cuda::GpuMat(a.rows, a.cols / 2 + 1, CV_32FC2, d_b_data.ptr(), (a.cols / 2 + 1) * d_b_data.elemSize());
|
||||
}
|
||||
d_c_data.create(1, a.size().area(), CV_32F);
|
||||
d_c = cv::cuda::GpuMat(a.rows, a.cols, CV_32F, d_c_data.ptr(), a.cols * d_c_data.elemSize());
|
||||
}
|
||||
|
||||
cv::cuda::dft(loadMat(a), d_b, cv::Size(cols, rows), 0);
|
||||
cv::cuda::dft(d_b, d_c, cv::Size(cols, rows), cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
|
||||
|
||||
EXPECT_TRUE(!inplace || d_b.ptr() == d_b_data.ptr());
|
||||
EXPECT_TRUE(!inplace || d_c.ptr() == d_c_data.ptr());
|
||||
ASSERT_EQ(CV_32F, d_c.depth());
|
||||
ASSERT_EQ(1, d_c.channels());
|
||||
|
||||
cv::Mat c(d_c);
|
||||
EXPECT_MAT_NEAR(a, c, rows * cols * 1e-5);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Dft, R2CThenC2R)
|
||||
{
|
||||
int cols = randomInt(2, 100);
|
||||
int rows = randomInt(2, 100);
|
||||
|
||||
testR2CThenC2R("sanity", cols, rows, false);
|
||||
testR2CThenC2R("sanity 0 1", cols, rows + 1, false);
|
||||
testR2CThenC2R("sanity 1 0", cols + 1, rows, false);
|
||||
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, false);
|
||||
testR2CThenC2R("single col", 1, rows, false);
|
||||
testR2CThenC2R("single col 1", 1, rows + 1, false);
|
||||
testR2CThenC2R("single row", cols, 1, false);
|
||||
testR2CThenC2R("single row 1", cols + 1, 1, false);
|
||||
|
||||
testR2CThenC2R("sanity", cols, rows, true);
|
||||
testR2CThenC2R("sanity 0 1", cols, rows + 1, true);
|
||||
testR2CThenC2R("sanity 1 0", cols + 1, rows, true);
|
||||
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, true);
|
||||
testR2CThenC2R("single row", cols, 1, true);
|
||||
testR2CThenC2R("single row 1", cols + 1, 1, true);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Dft, ALL_DEVICES);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Convolve
|
||||
|
||||
namespace
|
||||
{
|
||||
void convolveDFT(const cv::Mat& A, const cv::Mat& B, cv::Mat& C, bool ccorr = false)
|
||||
{
|
||||
// reallocate the output array if needed
|
||||
C.create(std::abs(A.rows - B.rows) + 1, std::abs(A.cols - B.cols) + 1, A.type());
|
||||
cv::Size dftSize;
|
||||
|
||||
// compute the size of DFT transform
|
||||
dftSize.width = cv::getOptimalDFTSize(A.cols + B.cols - 1);
|
||||
dftSize.height = cv::getOptimalDFTSize(A.rows + B.rows - 1);
|
||||
|
||||
// allocate temporary buffers and initialize them with 0s
|
||||
cv::Mat tempA(dftSize, A.type(), cv::Scalar::all(0));
|
||||
cv::Mat tempB(dftSize, B.type(), cv::Scalar::all(0));
|
||||
|
||||
// copy A and B to the top-left corners of tempA and tempB, respectively
|
||||
cv::Mat roiA(tempA, cv::Rect(0, 0, A.cols, A.rows));
|
||||
A.copyTo(roiA);
|
||||
cv::Mat roiB(tempB, cv::Rect(0, 0, B.cols, B.rows));
|
||||
B.copyTo(roiB);
|
||||
|
||||
// now transform the padded A & B in-place;
|
||||
// use "nonzeroRows" hint for faster processing
|
||||
cv::dft(tempA, tempA, 0, A.rows);
|
||||
cv::dft(tempB, tempB, 0, B.rows);
|
||||
|
||||
// multiply the spectrums;
|
||||
// the function handles packed spectrum representations well
|
||||
cv::mulSpectrums(tempA, tempB, tempA, 0, ccorr);
|
||||
|
||||
// transform the product back from the frequency domain.
|
||||
// Even though all the result rows will be non-zero,
|
||||
// you need only the first C.rows of them, and thus you
|
||||
// pass nonzeroRows == C.rows
|
||||
cv::dft(tempA, tempA, cv::DFT_INVERSE + cv::DFT_SCALE, C.rows);
|
||||
|
||||
// now copy the result back to C.
|
||||
tempA(cv::Rect(0, 0, C.cols, C.rows)).copyTo(C);
|
||||
}
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(KSize, int)
|
||||
IMPLEMENT_PARAM_CLASS(Ccorr, bool)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(Convolve, cv::cuda::DeviceInfo, cv::Size, KSize, Ccorr)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int ksize;
|
||||
bool ccorr;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
ksize = GET_PARAM(2);
|
||||
ccorr = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Convolve, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, CV_32FC1, 0.0, 100.0);
|
||||
cv::Mat kernel = randomMat(cv::Size(ksize, ksize), CV_32FC1, 0.0, 1.0);
|
||||
|
||||
cv::Ptr<cv::cuda::Convolution> conv = cv::cuda::createConvolution();
|
||||
|
||||
cv::cuda::GpuMat dst;
|
||||
conv->convolve(loadMat(src), loadMat(kernel), dst, ccorr);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
convolveDFT(src, kernel, dst_gold, ccorr);
|
||||
|
||||
EXPECT_MAT_NEAR(dst, dst_gold, 1e-1);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Convolve, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(KSize(3), KSize(7), KSize(11), KSize(17), KSize(19), KSize(23), KSize(45)),
|
||||
testing::Values(Ccorr(false), Ccorr(true))));
|
||||
|
||||
#endif // HAVE_CUBLAS
|
||||
|
||||
}} // namespace
|
||||
|
||||
#endif // HAVE_CUDA
|
||||
@@ -0,0 +1,120 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// 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*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
struct BufferPoolTest : TestWithParam<DeviceInfo>
|
||||
{
|
||||
void RunSimpleTest(Stream& stream, HostMem& dst_1, HostMem& dst_2)
|
||||
{
|
||||
BufferPool pool(stream);
|
||||
|
||||
{
|
||||
GpuMat buf0 = pool.getBuffer(Size(640, 480), CV_8UC1);
|
||||
EXPECT_FALSE( buf0.empty() );
|
||||
|
||||
buf0.setTo(Scalar::all(0), stream);
|
||||
|
||||
GpuMat buf1 = pool.getBuffer(Size(640, 480), CV_8UC1);
|
||||
EXPECT_FALSE( buf1.empty() );
|
||||
|
||||
buf0.convertTo(buf1, buf1.type(), 1.0, 1.0, stream);
|
||||
|
||||
buf1.download(dst_1, stream);
|
||||
}
|
||||
|
||||
{
|
||||
GpuMat buf2 = pool.getBuffer(Size(1280, 1024), CV_32SC1);
|
||||
EXPECT_FALSE( buf2.empty() );
|
||||
|
||||
buf2.setTo(Scalar::all(2), stream);
|
||||
|
||||
buf2.download(dst_2, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckSimpleTest(HostMem& dst_1, HostMem& dst_2)
|
||||
{
|
||||
EXPECT_MAT_NEAR(Mat(Size(640, 480), CV_8UC1, Scalar::all(1)), dst_1, 0.0);
|
||||
EXPECT_MAT_NEAR(Mat(Size(1280, 1024), CV_32SC1, Scalar::all(2)), dst_2, 0.0);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(BufferPoolTest, FromNullStream)
|
||||
{
|
||||
HostMem dst_1, dst_2;
|
||||
|
||||
RunSimpleTest(Stream::Null(), dst_1, dst_2);
|
||||
|
||||
cudaSafeCall(cudaDeviceSynchronize());
|
||||
|
||||
CheckSimpleTest(dst_1, dst_2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(BufferPoolTest, From2Streams)
|
||||
{
|
||||
HostMem dst1_1, dst1_2;
|
||||
HostMem dst2_1, dst2_2;
|
||||
|
||||
Stream stream1, stream2;
|
||||
RunSimpleTest(stream1, dst1_1, dst1_2);
|
||||
RunSimpleTest(stream2, dst2_1, dst2_2);
|
||||
|
||||
stream1.waitForCompletion();
|
||||
stream2.waitForCompletion();
|
||||
|
||||
CheckSimpleTest(dst1_1, dst1_2);
|
||||
CheckSimpleTest(dst2_1, dst2_2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Stream, BufferPoolTest, ALL_DEVICES);
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
@@ -0,0 +1,439 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// 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*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Merge
|
||||
|
||||
PARAM_TEST_CASE(Merge, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
int channels;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
channels = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Merge, Accuracy)
|
||||
{
|
||||
std::vector<cv::Mat> src;
|
||||
src.reserve(channels);
|
||||
for (int i = 0; i < channels; ++i)
|
||||
src.push_back(cv::Mat(size, depth, cv::Scalar::all(i)));
|
||||
|
||||
std::vector<cv::cuda::GpuMat> d_src;
|
||||
for (int i = 0; i < channels; ++i)
|
||||
d_src.push_back(loadMat(src[i], useRoi));
|
||||
|
||||
if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::merge(d_src, dst);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::merge(d_src, dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::merge(src, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Merge, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_DEPTH,
|
||||
testing::Values(1, 2, 3, 4),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Split
|
||||
|
||||
PARAM_TEST_CASE(Split, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
int channels;
|
||||
bool useRoi;
|
||||
|
||||
int type;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
channels = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
type = CV_MAKE_TYPE(depth, channels);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Split, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<cv::cuda::GpuMat> dst;
|
||||
cv::cuda::split(loadMat(src), dst);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<cv::cuda::GpuMat> dst;
|
||||
cv::cuda::split(loadMat(src, useRoi), dst);
|
||||
|
||||
std::vector<cv::Mat> dst_gold;
|
||||
cv::split(src, dst_gold);
|
||||
|
||||
ASSERT_EQ(dst_gold.size(), dst.size());
|
||||
|
||||
for (size_t i = 0; i < dst_gold.size(); ++i)
|
||||
{
|
||||
EXPECT_MAT_NEAR(dst_gold[i], dst[i], 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Split, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_DEPTH,
|
||||
testing::Values(1, 2, 3, 4),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Transpose
|
||||
|
||||
PARAM_TEST_CASE(Transpose, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Transpose, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::transpose(loadMat(src), dst);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat dst = createMat(cv::Size(size.height, size.width), type, useRoi);
|
||||
cv::cuda::transpose(loadMat(src, useRoi), dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::transpose(src, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Transpose, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1),
|
||||
MatType(CV_8UC4),
|
||||
MatType(CV_16UC2),
|
||||
MatType(CV_16SC2),
|
||||
MatType(CV_32SC1),
|
||||
MatType(CV_32SC2),
|
||||
MatType(CV_64FC1)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Flip
|
||||
|
||||
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
|
||||
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
|
||||
#define ALL_FLIP_CODES testing::Values(FlipCode(FLIP_BOTH), FlipCode(FLIP_X), FlipCode(FLIP_Y))
|
||||
|
||||
PARAM_TEST_CASE(Flip, cv::cuda::DeviceInfo, cv::Size, MatType, FlipCode, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int flip_code;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
flip_code = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Flip, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::cuda::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::cuda::flip(loadMat(src, useRoi), dst, flip_code);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::flip(src, dst_gold, flip_code);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Flip, AccuracyInplace)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
bool isSizeOdd = ((size.width & 1) == 1) || ((size.height & 1) == 1);
|
||||
cv::cuda::GpuMat srcDst = loadMat(src, useRoi);
|
||||
if(isSizeOdd)
|
||||
{
|
||||
EXPECT_THROW(cv::cuda::flip(srcDst, srcDst, flip_code), cv::Exception);
|
||||
return;
|
||||
}
|
||||
cv::cuda::flip(srcDst, srcDst, flip_code);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::flip(src, dst_gold, flip_code);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, srcDst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Flip, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1),
|
||||
MatType(CV_8UC3),
|
||||
MatType(CV_8UC4),
|
||||
MatType(CV_16UC1),
|
||||
MatType(CV_16UC3),
|
||||
MatType(CV_16UC4),
|
||||
MatType(CV_32SC1),
|
||||
MatType(CV_32SC3),
|
||||
MatType(CV_32SC4),
|
||||
MatType(CV_32FC1),
|
||||
MatType(CV_32FC3),
|
||||
MatType(CV_32FC4)),
|
||||
ALL_FLIP_CODES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// LUT
|
||||
|
||||
PARAM_TEST_CASE(LUT, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(LUT, OneChannel)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat lut = randomMat(cv::Size(256, 1), CV_8UC1);
|
||||
|
||||
cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
|
||||
|
||||
cv::cuda::GpuMat dst = createMat(size, CV_MAKE_TYPE(lut.depth(), src.channels()));
|
||||
lutAlg->transform(loadMat(src, useRoi), dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::LUT(src, lut, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(LUT, MultiChannel)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat lut = randomMat(cv::Size(256, 1), CV_MAKE_TYPE(CV_8U, src.channels()));
|
||||
|
||||
cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
|
||||
|
||||
cv::cuda::GpuMat dst = createMat(size, CV_MAKE_TYPE(lut.depth(), src.channels()), useRoi);
|
||||
lutAlg->transform(loadMat(src, useRoi), dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::LUT(src, lut, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, LUT, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// CopyMakeBorder
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(Border, int)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(CopyMakeBorder, cv::cuda::DeviceInfo, cv::Size, MatType, Border, BorderType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int border;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
border = GET_PARAM(3);
|
||||
borderType = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(CopyMakeBorder, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Scalar val = randomScalar(0, 255);
|
||||
|
||||
cv::cuda::GpuMat dst = createMat(cv::Size(size.width + 2 * border, size.height + 2 * border), type, useRoi);
|
||||
cv::cuda::copyMakeBorder(loadMat(src, useRoi), dst, border, border, border, border, borderType, val);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::copyMakeBorder(src, dst_gold, border, border, border, border, borderType, val);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, CopyMakeBorder, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1),
|
||||
MatType(CV_8UC3),
|
||||
MatType(CV_8UC4),
|
||||
MatType(CV_16UC1),
|
||||
MatType(CV_16UC3),
|
||||
MatType(CV_16UC4),
|
||||
MatType(CV_32FC1),
|
||||
MatType(CV_32FC3),
|
||||
MatType(CV_32FC4)),
|
||||
testing::Values(Border(1), Border(10), Border(50)),
|
||||
ALL_BORDER_TYPES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,104 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/core/cuda_stream_accessor.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
struct AsyncEvent : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
cv::cuda::HostMem src;
|
||||
cv::cuda::GpuMat d_src;
|
||||
|
||||
cv::cuda::HostMem dst;
|
||||
cv::cuda::GpuMat d_dst;
|
||||
|
||||
cv::cuda::Stream stream;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo = GetParam();
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
src = cv::cuda::HostMem(cv::cuda::HostMem::PAGE_LOCKED);
|
||||
|
||||
cv::Mat m = randomMat(cv::Size(128, 128), CV_8UC1);
|
||||
m.copyTo(src);
|
||||
}
|
||||
};
|
||||
|
||||
void deviceWork(void* userData)
|
||||
{
|
||||
AsyncEvent* test = reinterpret_cast<AsyncEvent*>(userData);
|
||||
test->d_src.upload(test->src, test->stream);
|
||||
test->d_src.convertTo(test->d_dst, CV_32S, test->stream);
|
||||
test->d_dst.download(test->dst, test->stream);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(AsyncEvent, WrapEvent)
|
||||
{
|
||||
cudaEvent_t cuda_event = NULL;
|
||||
ASSERT_EQ(cudaSuccess, cudaEventCreate(&cuda_event));
|
||||
{
|
||||
cv::cuda::Event cudaEvent = cv::cuda::EventAccessor::wrapEvent(cuda_event);
|
||||
deviceWork(this);
|
||||
cudaEvent.record(stream);
|
||||
cudaEvent.waitForCompletion();
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
}
|
||||
ASSERT_EQ(cudaSuccess, cudaEventDestroy(cuda_event));
|
||||
}
|
||||
|
||||
CUDA_TEST_P(AsyncEvent, WithFlags)
|
||||
{
|
||||
cv::cuda::Event cudaEvent = cv::cuda::Event(cv::cuda::Event::CreateFlags::BLOCKING_SYNC);
|
||||
deviceWork(this);
|
||||
cudaEvent.record(stream);
|
||||
cudaEvent.waitForCompletion();
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(AsyncEvent, Timing)
|
||||
{
|
||||
const std::vector<cv::cuda::Event::CreateFlags> eventFlags = { cv::cuda::Event::CreateFlags::BLOCKING_SYNC , cv::cuda::Event::CreateFlags::BLOCKING_SYNC | Event::CreateFlags::DISABLE_TIMING };
|
||||
const std::vector<bool> shouldFail = { false, true };
|
||||
for (size_t i = 0; i < eventFlags.size(); i++) {
|
||||
const auto& flags = eventFlags.at(i);
|
||||
cv::cuda::Event startEvent = cv::cuda::Event(flags);
|
||||
cv::cuda::Event stopEvent = cv::cuda::Event(flags);
|
||||
startEvent.record(stream);
|
||||
deviceWork(this);
|
||||
stopEvent.record(stream);
|
||||
stopEvent.waitForCompletion();
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
bool failed = false;
|
||||
try {
|
||||
const double elTimeMs = Event::elapsedTime(startEvent, stopEvent);
|
||||
ASSERT_GT(elTimeMs, 0);
|
||||
}
|
||||
catch (const cv::Exception& ex) {
|
||||
failed = true;
|
||||
}
|
||||
ASSERT_EQ(failed, shouldFail.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Event, AsyncEvent, ALL_DEVICES);
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
@@ -0,0 +1,514 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// 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*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// SetTo
|
||||
|
||||
PARAM_TEST_CASE(GpuMat_SetTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GpuMat_SetTo, Zero)
|
||||
{
|
||||
cv::Scalar zero = cv::Scalar::all(0);
|
||||
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(zero);
|
||||
|
||||
EXPECT_MAT_NEAR(cv::Mat::zeros(size, type), mat, 0.0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_SetTo, SameVal)
|
||||
{
|
||||
cv::Scalar val = cv::Scalar::all(randomDouble(0.0, 255.0));
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val);
|
||||
|
||||
EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_SetTo, DifferentVal)
|
||||
{
|
||||
cv::Scalar val = randomScalar(0.0, 255.0);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val);
|
||||
|
||||
EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_SetTo, Masked)
|
||||
{
|
||||
cv::Scalar val = randomScalar(0.0, 255.0);
|
||||
cv::Mat mat_gold = randomMat(size, type);
|
||||
cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val, loadMat(mask));
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat mat = loadMat(mat_gold, useRoi);
|
||||
mat.setTo(val, loadMat(mask, useRoi));
|
||||
|
||||
mat_gold.setTo(val, mask);
|
||||
|
||||
EXPECT_MAT_NEAR(mat_gold, mat, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_SetTo, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_TYPES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// CopyTo
|
||||
|
||||
PARAM_TEST_CASE(GpuMat_CopyTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GpuMat_CopyTo, WithOutMask)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::cuda::GpuMat d_src = loadMat(src, useRoi);
|
||||
cv::cuda::GpuMat dst = createMat(size, type, useRoi);
|
||||
d_src.copyTo(dst);
|
||||
|
||||
EXPECT_MAT_NEAR(src, dst, 0.0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_CopyTo, Masked)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
d_src.copyTo(dst, loadMat(mask, useRoi));
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src, useRoi);
|
||||
cv::cuda::GpuMat dst = loadMat(cv::Mat::zeros(size, type), useRoi);
|
||||
d_src.copyTo(dst, loadMat(mask, useRoi));
|
||||
|
||||
cv::Mat dst_gold = cv::Mat::zeros(size, type);
|
||||
src.copyTo(dst_gold, mask);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_CopyTo, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_TYPES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ConvertTo
|
||||
|
||||
PARAM_TEST_CASE(GpuMat_ConvertTo, cv::cuda::DeviceInfo, cv::Size, MatDepth, MatDepth, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth1;
|
||||
int depth2;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth1 = GET_PARAM(2);
|
||||
depth2 = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GpuMat_ConvertTo, WithOutScaling)
|
||||
{
|
||||
cv::Mat src = randomMat(size, depth1);
|
||||
|
||||
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
d_src.convertTo(dst, depth2);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src, useRoi);
|
||||
cv::cuda::GpuMat dst = createMat(size, depth2, useRoi);
|
||||
d_src.convertTo(dst, depth2);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.convertTo(dst_gold, depth2);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 1.0 : 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_ConvertTo, WithScaling)
|
||||
{
|
||||
cv::Mat src = randomMat(size, depth1);
|
||||
double a = randomDouble(0.0, 1.0);
|
||||
double b = randomDouble(-10.0, 10.0);
|
||||
|
||||
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
d_src.convertTo(dst, depth2, a, b);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src, useRoi);
|
||||
cv::cuda::GpuMat dst = createMat(size, depth2, useRoi);
|
||||
d_src.convertTo(dst, depth2, a, b);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.convertTo(dst_gold, depth2, a, b);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 1.0 : 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_ConvertTo, InplaceWithOutScaling)
|
||||
{
|
||||
cv::Mat src = randomMat(size, depth1);
|
||||
|
||||
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_srcDst = loadMat(src);
|
||||
d_srcDst.convertTo(d_srcDst, depth2);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_srcDst = loadMat(src, useRoi);
|
||||
d_srcDst.convertTo(d_srcDst, depth2);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.convertTo(dst_gold, depth2);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, d_srcDst, depth2 < CV_32F ? 1.0 : 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CUDA_TEST_P(GpuMat_ConvertTo, InplaceWithScaling)
|
||||
{
|
||||
cv::Mat src = randomMat(size, depth1);
|
||||
double a = randomDouble(0.0, 1.0);
|
||||
double b = randomDouble(-10.0, 10.0);
|
||||
|
||||
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_srcDst = loadMat(src);
|
||||
d_srcDst.convertTo(d_srcDst, depth2, a, b);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_srcDst = loadMat(src, useRoi);
|
||||
d_srcDst.convertTo(d_srcDst, depth2, a, b);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.convertTo(dst_gold, depth2, a, b);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, d_srcDst, depth2 < CV_32F ? 1.0 : 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_ConvertTo, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_DEPTH,
|
||||
ALL_DEPTH,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// locateROI
|
||||
|
||||
PARAM_TEST_CASE(GpuMat_LocateROI, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GpuMat_LocateROI, locateROI)
|
||||
{
|
||||
Point ofsGold;
|
||||
Size wholeSizeGold;
|
||||
GpuMat src = createMat(size, depth, wholeSizeGold, ofsGold, useRoi);
|
||||
|
||||
Point ofs;
|
||||
Size wholeSize;
|
||||
src.locateROI(wholeSize, ofs);
|
||||
ASSERT_TRUE(ofs == ofsGold && wholeSize == wholeSizeGold);
|
||||
|
||||
GpuMat srcPtr(src.size(), src.type(), src.data, src.step);
|
||||
src.locateROI(wholeSize, ofs);
|
||||
ASSERT_TRUE(ofs == ofsGold && wholeSize == wholeSizeGold);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_LocateROI, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_DEPTH,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ensureSizeIsEnough
|
||||
|
||||
struct EnsureSizeIsEnough : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
virtual void SetUp()
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo = GetParam();
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(EnsureSizeIsEnough, BufferReuse)
|
||||
{
|
||||
cv::cuda::GpuMat buffer(100, 100, CV_8U);
|
||||
cv::cuda::GpuMat old = buffer;
|
||||
|
||||
// don't reallocate memory
|
||||
cv::cuda::ensureSizeIsEnough(10, 20, CV_8U, buffer);
|
||||
EXPECT_EQ(10, buffer.rows);
|
||||
EXPECT_EQ(20, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_EQ(reinterpret_cast<intptr_t>(old.data), reinterpret_cast<intptr_t>(buffer.data));
|
||||
|
||||
// don't reallocate memory
|
||||
cv::cuda::ensureSizeIsEnough(20, 30, CV_8U, buffer);
|
||||
EXPECT_EQ(20, buffer.rows);
|
||||
EXPECT_EQ(30, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_EQ(reinterpret_cast<intptr_t>(old.data), reinterpret_cast<intptr_t>(buffer.data));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, EnsureSizeIsEnough, ALL_DEVICES);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// createContinuous
|
||||
|
||||
struct CreateContinuous : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
virtual void SetUp()
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo = GetParam();
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(CreateContinuous, BufferReuse)
|
||||
{
|
||||
cv::cuda::GpuMat buffer;
|
||||
|
||||
cv::cuda::createContinuous(100, 100, CV_8UC1, buffer);
|
||||
EXPECT_EQ(100, buffer.rows);
|
||||
EXPECT_EQ(100, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_TRUE(buffer.isContinuous());
|
||||
EXPECT_EQ(buffer.cols * sizeof(uchar), buffer.step);
|
||||
|
||||
cv::cuda::createContinuous(10, 1000, CV_8UC1, buffer);
|
||||
EXPECT_EQ(10, buffer.rows);
|
||||
EXPECT_EQ(1000, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_TRUE(buffer.isContinuous());
|
||||
EXPECT_EQ(buffer.cols * sizeof(uchar), buffer.step);
|
||||
|
||||
cv::cuda::createContinuous(10, 10, CV_8UC1, buffer);
|
||||
EXPECT_EQ(10, buffer.rows);
|
||||
EXPECT_EQ(10, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_TRUE(buffer.isContinuous());
|
||||
EXPECT_EQ(buffer.cols * sizeof(uchar), buffer.step);
|
||||
|
||||
cv::cuda::createContinuous(100, 100, CV_8UC1, buffer);
|
||||
EXPECT_EQ(100, buffer.rows);
|
||||
EXPECT_EQ(100, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_TRUE(buffer.isContinuous());
|
||||
EXPECT_EQ(buffer.cols * sizeof(uchar), buffer.step);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, CreateContinuous, ALL_DEVICES);
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
@@ -0,0 +1,45 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// 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*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
CV_CUDA_TEST_MAIN("gpu")
|
||||
@@ -0,0 +1,457 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// 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*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#if defined(HAVE_CUDA) && defined(HAVE_OPENGL)
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/core/opengl.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Buffer
|
||||
|
||||
PARAM_TEST_CASE(Buffer, cv::Size, MatType)
|
||||
{
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Buffer, Constructor1)
|
||||
{
|
||||
cv::ogl::Buffer buf(size.height, size.width, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_EQ(size.height, buf.rows());
|
||||
EXPECT_EQ(size.width, buf.cols());
|
||||
EXPECT_EQ(type, buf.type());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, Constructor2)
|
||||
{
|
||||
cv::ogl::Buffer buf(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_EQ(size.height, buf.rows());
|
||||
EXPECT_EQ(size.width, buf.cols());
|
||||
EXPECT_EQ(type, buf.type());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, ConstructorFromMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, ConstructorFromGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
cv::cuda::GpuMat d_gold(gold);
|
||||
|
||||
cv::ogl::Buffer buf(d_gold, cv::ogl::Buffer::ARRAY_BUFFER);
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, ConstructorFromBuffer)
|
||||
{
|
||||
cv::ogl::Buffer buf_gold(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::ogl::Buffer buf(buf_gold);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, Create)
|
||||
{
|
||||
cv::ogl::Buffer buf;
|
||||
buf.create(size.height, size.width, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_EQ(size.height, buf.rows());
|
||||
EXPECT_EQ(size.width, buf.cols());
|
||||
EXPECT_EQ(type, buf.type());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyFromMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf;
|
||||
buf.copyFrom(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyFromGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
cv::cuda::GpuMat d_gold(gold);
|
||||
|
||||
cv::ogl::Buffer buf;
|
||||
buf.copyFrom(d_gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyFromBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::ogl::Buffer buf;
|
||||
buf.copyFrom(buf_gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_NE(buf_gold.bufId(), buf.bufId());
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyToGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::cuda::GpuMat dst;
|
||||
buf.copyTo(dst);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyToBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::ogl::Buffer dst;
|
||||
buf.copyTo(dst);
|
||||
dst.setAutoRelease(true);
|
||||
|
||||
EXPECT_NE(buf.bufId(), dst.bufId());
|
||||
|
||||
cv::Mat bufData;
|
||||
dst.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, Clone)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::ogl::Buffer dst = buf.clone(cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_NE(buf.bufId(), dst.bufId());
|
||||
|
||||
cv::Mat bufData;
|
||||
dst.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, MapHostRead)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat dst = buf.mapHost(cv::ogl::Buffer::READ_ONLY);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||
|
||||
buf.unmapHost();
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, MapHostWrite)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat dst = buf.mapHost(cv::ogl::Buffer::WRITE_ONLY);
|
||||
gold.copyTo(dst);
|
||||
buf.unmapHost();
|
||||
dst.release();
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, MapDevice)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::cuda::GpuMat dst = buf.mapDevice();
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||
|
||||
buf.unmapDevice();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(OpenGL, Buffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES));
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Texture2D
|
||||
|
||||
PARAM_TEST_CASE(Texture2D, cv::Size, MatType)
|
||||
{
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
cv::Size size;
|
||||
int type;
|
||||
int depth;
|
||||
int cn;
|
||||
cv::ogl::Texture2D::Format format;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
size = GET_PARAM(0);
|
||||
type = GET_PARAM(1);
|
||||
|
||||
depth = CV_MAT_DEPTH(type);
|
||||
cn = CV_MAT_CN(type);
|
||||
format = cn == 1 ? cv::ogl::Texture2D::DEPTH_COMPONENT : cn == 3 ? cv::ogl::Texture2D::RGB : cn == 4 ? cv::ogl::Texture2D::RGBA : cv::ogl::Texture2D::NONE;
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Texture2D, Constructor1)
|
||||
{
|
||||
cv::ogl::Texture2D tex(size.height, size.width, format, true);
|
||||
|
||||
EXPECT_EQ(size.height, tex.rows());
|
||||
EXPECT_EQ(size.width, tex.cols());
|
||||
EXPECT_EQ(format, tex.format());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, Constructor2)
|
||||
{
|
||||
cv::ogl::Texture2D tex(size, format, true);
|
||||
|
||||
EXPECT_EQ(size.height, tex.rows());
|
||||
EXPECT_EQ(size.width, tex.cols());
|
||||
EXPECT_EQ(format, tex.format());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, ConstructorFromMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
|
||||
cv::ogl::Texture2D tex(gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, ConstructorFromGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
cv::cuda::GpuMat d_gold(gold);
|
||||
|
||||
cv::ogl::Texture2D tex(d_gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, ConstructorFromBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||||
|
||||
cv::ogl::Texture2D tex(buf_gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, ConstructorFromTexture2D)
|
||||
{
|
||||
cv::ogl::Texture2D tex_gold(size, format, true);
|
||||
cv::ogl::Texture2D tex(tex_gold);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, Create)
|
||||
{
|
||||
cv::ogl::Texture2D tex;
|
||||
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());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyFromMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
|
||||
cv::ogl::Texture2D tex;
|
||||
tex.copyFrom(gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyFromGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
cv::cuda::GpuMat d_gold(gold);
|
||||
|
||||
cv::ogl::Texture2D tex;
|
||||
tex.copyFrom(d_gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyFromBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||||
|
||||
cv::ogl::Texture2D tex;
|
||||
tex.copyFrom(buf_gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyToGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
|
||||
cv::ogl::Texture2D tex(gold, true);
|
||||
|
||||
cv::cuda::GpuMat dst;
|
||||
tex.copyTo(dst, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyToBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
|
||||
cv::ogl::Texture2D tex(gold, true);
|
||||
|
||||
cv::ogl::Buffer dst;
|
||||
tex.copyTo(dst, depth, true);
|
||||
|
||||
cv::Mat bufData;
|
||||
dst.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 1e-2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(OpenGL, Texture2D, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4)));
|
||||
|
||||
}} // namespace
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// 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*/
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
|
||||
#include "cvconfig.h"
|
||||
|
||||
namespace opencv_test {
|
||||
using namespace cv::cuda;
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,176 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// 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*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/core/cuda_stream_accessor.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
struct Async : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
cv::cuda::HostMem src;
|
||||
cv::cuda::GpuMat d_src;
|
||||
|
||||
cv::cuda::HostMem dst;
|
||||
cv::cuda::GpuMat d_dst;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo = GetParam();
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
src = cv::cuda::HostMem(cv::cuda::HostMem::PAGE_LOCKED);
|
||||
|
||||
cv::Mat m = randomMat(cv::Size(128, 128), CV_8UC1);
|
||||
m.copyTo(src);
|
||||
}
|
||||
};
|
||||
|
||||
void checkMemSet(int status, void* userData)
|
||||
{
|
||||
ASSERT_EQ(cudaSuccess, status);
|
||||
|
||||
Async* test = reinterpret_cast<Async*>(userData);
|
||||
|
||||
cv::cuda::HostMem src = test->src;
|
||||
cv::cuda::HostMem dst = test->dst;
|
||||
|
||||
cv::Mat dst_gold = cv::Mat::zeros(src.size(), src.type());
|
||||
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Async, MemSet)
|
||||
{
|
||||
cv::cuda::Stream stream;
|
||||
|
||||
d_dst.upload(src);
|
||||
|
||||
d_dst.setTo(cv::Scalar::all(0), stream);
|
||||
d_dst.download(dst, stream);
|
||||
|
||||
Async* test = this;
|
||||
stream.enqueueHostCallback(checkMemSet, test);
|
||||
|
||||
stream.waitForCompletion();
|
||||
}
|
||||
|
||||
void checkConvert(int status, void* userData)
|
||||
{
|
||||
ASSERT_EQ(cudaSuccess, status);
|
||||
|
||||
Async* test = reinterpret_cast<Async*>(userData);
|
||||
|
||||
cv::cuda::HostMem src = test->src;
|
||||
cv::cuda::HostMem dst = test->dst;
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Async, Convert)
|
||||
{
|
||||
cv::cuda::Stream stream;
|
||||
|
||||
d_src.upload(src, stream);
|
||||
d_src.convertTo(d_dst, CV_32S, stream);
|
||||
d_dst.download(dst, stream);
|
||||
|
||||
Async* test = this;
|
||||
stream.enqueueHostCallback(checkConvert, test);
|
||||
|
||||
stream.waitForCompletion();
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Async, WrapStream)
|
||||
{
|
||||
cudaStream_t cuda_stream = NULL;
|
||||
ASSERT_EQ(cudaSuccess, cudaStreamCreate(&cuda_stream));
|
||||
|
||||
{
|
||||
cv::cuda::Stream stream = cv::cuda::StreamAccessor::wrapStream(cuda_stream);
|
||||
|
||||
d_src.upload(src, stream);
|
||||
d_src.convertTo(d_dst, CV_32S, stream);
|
||||
d_dst.download(dst, stream);
|
||||
|
||||
Async* test = this;
|
||||
stream.enqueueHostCallback(checkConvert, test);
|
||||
|
||||
stream.waitForCompletion();
|
||||
}
|
||||
|
||||
ASSERT_EQ(cudaSuccess, cudaStreamDestroy(cuda_stream));
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Async, HostMemAllocator)
|
||||
{
|
||||
cv::cuda::Stream stream;
|
||||
|
||||
cv::Mat h_dst;
|
||||
h_dst.allocator = cv::cuda::HostMem::getAllocator();
|
||||
|
||||
d_src.upload(src, stream);
|
||||
d_src.convertTo(d_dst, CV_32S, stream);
|
||||
d_dst.download(h_dst, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
|
||||
ASSERT_MAT_NEAR(dst_gold, h_dst, 0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Stream, Async, ALL_DEVICES);
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
Reference in New Issue
Block a user