diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index be39419ed1..268555bada 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -757,13 +757,6 @@ static void remapBilinear( const Mat& _src, Mat& _dst, const Mat& _xy, } else { - if( borderType == BORDER_TRANSPARENT && cn != 3 ) - { - D += (X1 - dx)*cn; - dx = X1; - continue; - } - if( cn == 1 ) for( ; dx < X1; dx++, D++ ) { @@ -774,6 +767,12 @@ static void remapBilinear( const Mat& _src, Mat& _dst, const Mat& _xy, { D[0] = cval[0]; } + else if (borderType == BORDER_TRANSPARENT) + { + if (sx < ssize.width && sx >= 0 && + sy < ssize.height && sy >= 0) + D[0] = S0[sy*sstep + sx]; + } else { int sx0, sx1, sy0, sy1; @@ -815,6 +814,13 @@ static void remapBilinear( const Mat& _src, Mat& _dst, const Mat& _xy, for(int k = 0; k < cn; k++ ) D[k] = cval[k]; } + else if (borderType == BORDER_TRANSPARENT) + { + if (sx < ssize.width && sx >= 0 && + sy < ssize.height && sy >= 0) + for(int k = 0; k < cn; k++ ) + D[k] = S0[sy*sstep + sx*cn + k]; + } else { int sx0, sx1, sy0, sy1; diff --git a/modules/imgproc/test/test_imgwarp.cpp b/modules/imgproc/test/test_imgwarp.cpp index c01bccf71e..68208caa04 100644 --- a/modules/imgproc/test/test_imgwarp.cpp +++ b/modules/imgproc/test/test_imgwarp.cpp @@ -1658,5 +1658,21 @@ TEST(Imgproc_warpPolar, identity) #endif } +TEST(Imgproc_Remap, issue_23562) +{ + cv::RNG rng(17); + Mat_ mapx({3, 3}, {0, 1, 2, 0, 1, 2, 0, 1, 2}); + Mat_ mapy({3, 3}, {0, 0, 0, 1, 1, 1, 2, 2, 2}); + for (int cn = 1; cn <= 4; ++cn) { + Mat src(3, 3, CV_32FC(cn)); + rng.fill(src, cv::RNG::UNIFORM, -1, 1); + Mat dst = Mat::zeros(3, 3, CV_32FC(cn)); + Mat ref = src.clone(); + + remap(src, dst, mapx, mapy, INTER_LINEAR, BORDER_TRANSPARENT); + ASSERT_EQ(0.0, cvtest::norm(ref, dst, NORM_INF)) << "channels=" << cn; + } +} + }} // namespace /* End of file. */