Skip to content

Commit 2341178

Browse files
committed
brush up by following the comments
1 parent 220b371 commit 2341178

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

modules/cudaarithm/src/core.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,12 @@ void cv::cuda::flip(InputArray _src, OutputArray _dst, int flipCode, Stream& str
163163

164164
_dst.create(src.size(), src.type());
165165
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
166-
if (src.data == dst.data && ((src.cols & 1) == 1 || (src.rows & 1) == 1))
166+
bool isInplace = (src.data == dst.data) || (src.refcount == dst.refcount);
167+
bool isSizeOdd = (src.cols & 1) == 1 || (src.rows & 1) == 1;
168+
if (isInplace && isSizeOdd)
167169
CV_Error(Error::BadROISize, "In-place version of flip only accepts even width/height");
168170

169-
if (src.data != dst.data)
171+
if (isInplace == false)
170172
funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream));
171173
else // in-place
172174
ifuncs[src.depth()][src.channels() - 1](src, flipCode, StreamAccessor::getStream(stream));

modules/cudaarithm/test/test_core.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,14 @@ CUDA_TEST_P(Flip, Accuracy)
281281

282282
CUDA_TEST_P(Flip, AccuracyInplace)
283283
{
284-
size.width = (size.width >> 1) << 1; // in-place version only accepts even number
285-
size.height = (size.height >> 1) << 1; // in-place version only accepts even number
286284
cv::Mat src = randomMat(size, type);
287-
285+
bool isSizeOdd = ((size.width & 1) == 1) || ((size.height & 1) == 1);
288286
cv::cuda::GpuMat srcDst = loadMat(src, useRoi);
287+
if(isSizeOdd)
288+
{
289+
EXPECT_THROW(cv::cuda::flip(srcDst, srcDst, flip_code), cv::Exception);
290+
return;
291+
}
289292
cv::cuda::flip(srcDst, srcDst, flip_code);
290293

291294
cv::Mat dst_gold;

0 commit comments

Comments
 (0)