brush up by following the comments
authorTomoaki Teshima <tomoaki.teshima@gmail.com>
Fri, 25 Sep 2020 14:57:15 +0000 (23:57 +0900)
committerTomoaki Teshima <tomoaki.teshima@gmail.com>
Fri, 25 Sep 2020 14:57:15 +0000 (23:57 +0900)
modules/cudaarithm/src/core.cpp
modules/cudaarithm/test/test_core.cpp

index aefcfc5..368c2fc 100644 (file)
@@ -163,10 +163,12 @@ 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))
+    bool isInplace = (src.data == dst.data) || (src.refcount == dst.refcount);
+    bool isSizeOdd = (src.cols & 1) == 1 || (src.rows & 1) == 1;
+    if (isInplace && isSizeOdd)
         CV_Error(Error::BadROISize, "In-place version of flip only accepts even width/height");
 
-    if (src.data != dst.data)
+    if (isInplace == false)
         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 04b144f..728ee12 100644 (file)
@@ -281,11 +281,14 @@ 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);
-
+    bool isSizeOdd = ((size.width & 1) == 1) || ((size.height & 1) == 1);
     cv::cuda::GpuMat srcDst = loadMat(src, useRoi);
+    if(isSizeOdd)
+    {
+        EXPECT_THROW(cv::cuda::flip(srcDst, srcDst, flip_code), cv::Exception);
+        return;
+    }
     cv::cuda::flip(srcDst, srcDst, flip_code);
 
     cv::Mat dst_gold;