use only even number for inplace flip
authorTomoaki Teshima <tomoaki.teshima@gmail.com>
Wed, 16 Sep 2020 06:45:03 +0000 (15:45 +0900)
committerTomoaki Teshima <tomoaki.teshima@gmail.com>
Wed, 16 Sep 2020 06:45:03 +0000 (15:45 +0900)
modules/cudaarithm/src/core.cpp
modules/cudaarithm/test/test_core.cpp

index ac01afc7f086272b5caaa512aa39ebede9fd1d63..aefcfc5af274acee77b00bd92f72907dafc35ebf 100644 (file)
@@ -163,8 +163,10 @@ void cv::cuda::flip(InputArray _src, OutputArray _dst, int flipCode, Stream& str
 
     _dst.create(src.size(), src.type());
     GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
+    if (src.data == dst.data && ((src.cols & 1) == 1 || (src.rows & 1) == 1))
+        CV_Error(Error::BadROISize, "In-place version of flip only accepts even width/height");
 
-    if (src.refcount != dst.refcount)
+    if (src.data != dst.data)
         funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream));
     else // in-place
         ifuncs[src.depth()][src.channels() - 1](src, flipCode, StreamAccessor::getStream(stream));
index bc8f3737e53c9c8bb420e32e85bb64d7dcf85e81..04b144ff37bbef16f44d779ada5a1c0a2b4b0c14 100644 (file)
@@ -281,6 +281,8 @@ CUDA_TEST_P(Flip, Accuracy)
 
 CUDA_TEST_P(Flip, AccuracyInplace)
 {
+    size.width  = (size.width  >> 1) << 1; // in-place version only accepts even number
+    size.height = (size.height >> 1) << 1; // in-place version only accepts even number
     cv::Mat src = randomMat(size, type);
 
     cv::cuda::GpuMat srcDst = loadMat(src, useRoi);