mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 21:22:43 -06:00
Merge pull request #31318 from ChandraguptSharma07/fix-rvv-area-resize
this PR is related to issue #31308 The RVV INTER_AREA code uses a 2×2 average when the output dimensions are half the input dimensions. A fractional scale can round to those same dimensions, causing 2x2 average to produce incorrect pixel values. Now it uses the fast path only for exact halving. The fractional cases that caused the issue before now fall back to opencv's standard cpu resize. This also avoids an existing 16 bit table offset overflow in the general RVV area kernel for tall images.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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<Vec4b>(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<Vec4b>(0, 0)[1]);
|
||||
}
|
||||
|
||||
TEST(Resize, lanczos4_regression_16192)
|
||||
{
|
||||
Size src_size(11, 17);
|
||||
|
||||
Reference in New Issue
Block a user