From 5576c0866a267990817acb1fb0ae1e8ac35c4b6c Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 10 Dec 2015 14:20:28 +0300 Subject: [PATCH] fix #5780 : `cv::cuda::createContinuous`effectively ignores its `cols` argument --- modules/core/src/cuda_gpu_mat.cpp | 2 +- modules/cudaarithm/test/test_gpumat.cpp | 47 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/modules/core/src/cuda_gpu_mat.cpp b/modules/core/src/cuda_gpu_mat.cpp index 9a17ddd85d..0d1e3ba330 100644 --- a/modules/core/src/cuda_gpu_mat.cpp +++ b/modules/core/src/cuda_gpu_mat.cpp @@ -260,7 +260,7 @@ namespace { const int area = rows * cols; - if (obj.empty() || obj.type() != type || !obj.isContinuous() || obj.size().area() < area) + if (obj.empty() || obj.type() != type || !obj.isContinuous() || obj.size().area() != area) obj.create(1, area, type); obj = obj.reshape(obj.channels(), rows); diff --git a/modules/cudaarithm/test/test_gpumat.cpp b/modules/cudaarithm/test/test_gpumat.cpp index 3f63352b86..d3c4bbbad7 100644 --- a/modules/cudaarithm/test/test_gpumat.cpp +++ b/modules/cudaarithm/test/test_gpumat.cpp @@ -361,4 +361,51 @@ CUDA_TEST_P(EnsureSizeIsEnough, BufferReuse) INSTANTIATE_TEST_CASE_P(CUDA, EnsureSizeIsEnough, ALL_DEVICES); +//////////////////////////////////////////////////////////////////////////////// +// createContinuous + +struct CreateContinuous : testing::TestWithParam +{ + 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); + #endif // HAVE_CUDA