Skip to content

Commit e668cff

Browse files
committed
Merge pull request opencv#18348 from tomoaki0705:fixNppFlipInplace
2 parents fa953e4 + a615466 commit e668cff

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

modules/cudaarithm/src/core.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ 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))
167+
CV_Error(Error::BadROISize, "In-place version of flip only accepts even width/height");
166168

167-
if (src.refcount != dst.refcount)
169+
if (src.data != dst.data)
168170
funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream));
169171
else // in-place
170172
ifuncs[src.depth()][src.channels() - 1](src, flipCode, StreamAccessor::getStream(stream));

modules/cudaarithm/test/test_core.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ 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
284286
cv::Mat src = randomMat(size, type);
285287

286288
cv::cuda::GpuMat srcDst = loadMat(src, useRoi);

0 commit comments

Comments
 (0)