Skip to content

Commit

Permalink
Merge pull request opencv#5781 from jet47:fix-cuda-createContinuous
Browse files Browse the repository at this point in the history
  • Loading branch information
vpisarev committed Dec 16, 2015
2 parents 3bbd22c + 5576c08 commit b2bb7d0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/core/src/cuda_gpu_mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions modules/cudaarithm/test/test_gpumat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,51 @@ CUDA_TEST_P(EnsureSizeIsEnough, BufferReuse)

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);

#endif // HAVE_CUDA

0 comments on commit b2bb7d0

Please sign in to comment.