From a153b0fc17bf3e50b4ae3dae427b6607893624c2 Mon Sep 17 00:00:00 2001 From: ChandraguptSharma07 Date: Wed, 2 Dec 2026 16:25:13 +0530 Subject: [PATCH] Fixed RVV INTER_AREA resizing for near-half scales --- hal/riscv-rvv/src/imgproc/resize.cpp | 4 ++++ modules/imgproc/test/test_imgwarp.cpp | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/hal/riscv-rvv/src/imgproc/resize.cpp b/hal/riscv-rvv/src/imgproc/resize.cpp index bc95d54310..8f1e52fca1 100644 --- a/hal/riscv-rvv/src/imgproc/resize.cpp +++ b/hal/riscv-rvv/src/imgproc/resize.cpp @@ -1035,6 +1035,10 @@ static inline int resizeArea(int src_type, const uchar *src_data, size_t src_ste if (dst_width * 2 == src_width && dst_height * 2 == src_height) { + // Fractional scales can round to the same dimensions as exact halving. + if (scale_x != 2.0 || scale_y != 2.0) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + switch (src_type) { case CV_8UC1: diff --git a/modules/imgproc/test/test_imgwarp.cpp b/modules/imgproc/test/test_imgwarp.cpp index 9a9e5610d6..ecf20a59bf 100644 --- a/modules/imgproc/test/test_imgwarp.cpp +++ b/modules/imgproc/test/test_imgwarp.cpp @@ -1556,6 +1556,23 @@ TEST(Resize, Area_half) } } +TEST(Resize, Area_fractional_rounds_to_half) +{ + Mat src = Mat::zeros(12, 12, CV_8UC4); + src.col(2).setTo(Scalar(0, 255, 0, 0)); + const double scale = 0.477582; + Mat dst; + + // The third column contributes round(255 * (1 - 2 * scale)) = 11. + cv::resize(src, dst, Size(), scale, 0.5, INTER_AREA); + ASSERT_EQ(Size(6, 6), dst.size()); + EXPECT_EQ(11, dst.at(0, 0)[1]); + + cv::resize(src.t(), dst, Size(), 0.5, scale, INTER_AREA); + ASSERT_EQ(Size(6, 6), dst.size()); + EXPECT_EQ(11, dst.at(0, 0)[1]); +} + TEST(Resize, lanczos4_regression_16192) { Size src_size(11, 17);