diff --git a/modules/cudaarithm/src/core.cpp b/modules/cudaarithm/src/core.cpp index aefcfc5af27..368c2fcc419 100644 --- a/modules/cudaarithm/src/core.cpp +++ b/modules/cudaarithm/src/core.cpp @@ -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)); diff --git a/modules/cudaarithm/test/test_core.cpp b/modules/cudaarithm/test/test_core.cpp index 04b144ff37b..728ee12b164 100644 --- a/modules/cudaarithm/test/test_core.cpp +++ b/modules/cudaarithm/test/test_core.cpp @@ -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; diff --git a/modules/xfeatures2d/src/stardetector.cpp b/modules/xfeatures2d/src/stardetector.cpp index b15ccc3ce5f..bcd4cccb618 100644 --- a/modules/xfeatures2d/src/stardetector.cpp +++ b/modules/xfeatures2d/src/stardetector.cpp @@ -227,7 +227,12 @@ StarDetectorComputeResponses( const Mat& img, Mat& responses, Mat& sizes, for(int i = 0; i < npatterns; i++ ) { int innerArea = f[pairs[i][1]].area; +#if 0 // workaround MSVS2019 bug: error C2109: subscript requires array or pointer type int outerArea = f[pairs[i][0]].area - innerArea; +#else + int outerArea = f[pairs[i][0]].area; + outerArea -= innerArea; +#endif invSizes[i][0] = 1.f/outerArea; invSizes[i][1] = 1.f/innerArea; } @@ -283,7 +288,7 @@ StarDetectorComputeResponses( const Mat& img, Mat& responses, Mat& sizes, for(int i = 0; i <= maxIdx; i++ ) { - const iiMatType** p = (const iiMatType**)&f[i].p[0]; + const iiMatType** p = (const iiMatType**)f[i].p; __m128i r0 = _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(p[0]+ofs)), _mm_loadu_si128((const __m128i*)(p[1]+ofs))); __m128i r1 = _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(p[3]+ofs)), @@ -325,7 +330,7 @@ StarDetectorComputeResponses( const Mat& img, Mat& responses, Mat& sizes, for(int i = 0; i <= maxIdx; i++ ) { - const iiMatType** p = (const iiMatType**)&f[i].p[0]; + const iiMatType** p = (const iiMatType**)f[i].p; vals[i] = (int)(p[0][ofs] - p[1][ofs] - p[2][ofs] + p[3][ofs] + p[4][ofs] - p[5][ofs] - p[6][ofs] + p[7][ofs]); }