From cc293eaff62cd4f072ca808962a0e279221c13f3 Mon Sep 17 00:00:00 2001 From: Dharshika Pugalenthi Date: Tue, 18 Aug 2026 10:57:04 +0530 Subject: [PATCH] Merge pull request #29691 from DPug888:fix-resize-area-channel-limit allow cv::resize to support more than 4 channels in AREA path - #29691 Fixes #29651 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake --- modules/imgproc/src/resize.cpp | 2 +- modules/imgproc/test/test_imgwarp.cpp | 39 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/resize.cpp b/modules/imgproc/src/resize.cpp index 4dd08a0cbc..f0ae36e87e 100644 --- a/modules/imgproc/src/resize.cpp +++ b/modules/imgproc/src/resize.cpp @@ -3848,7 +3848,7 @@ void resize(int src_type, } ResizeAreaFunc func = area_tab[depth]; - CV_Assert( func != 0 && cn <= 4 ); + CV_Assert( func != 0 ); AutoBuffer _xytab((src_width + src_height)*2); DecimateAlpha* xtab = _xytab.data(), *ytab = xtab + src_width*2; diff --git a/modules/imgproc/test/test_imgwarp.cpp b/modules/imgproc/test/test_imgwarp.cpp index 9e5e2b3448..d92e4c8362 100644 --- a/modules/imgproc/test/test_imgwarp.cpp +++ b/modules/imgproc/test/test_imgwarp.cpp @@ -1275,6 +1275,45 @@ TEST(Imgproc_resize_area, regression) check_resize_area(expected, actual, 1.0); } +CV_ENUM(MultiChannelResizeInter, cv::INTER_LINEAR, cv::INTER_AREA); +typedef testing::TestWithParam> Imgproc_ResizeMultiChannel; + +TEST_P(Imgproc_ResizeMultiChannel, smoke) +{ + int mode = get<0>(GetParam()); + int cn = get<1>(GetParam()); + + cv::Mat src(64, 64, CV_8UC(cn)); + cv::randu(src, 0, 255); + + std::vector srcChannels; + cv::split(src, srcChannels); + + cv::Size dsize = (mode == cv::INTER_LINEAR) ? cv::Size(32, 32) : cv::Size(31, 31); + + cv::Mat dstMulti; + ASSERT_NO_THROW(cv::resize(src, dstMulti, dsize, 0, 0, mode)); + EXPECT_EQ(dstMulti.channels(), cn); + EXPECT_EQ(dstMulti.size(), dsize); + + std::vector dstChannels(cn); + for (int i = 0; i < cn; i++) + cv::resize(srcChannels[i], dstChannels[i], dsize, 0, 0, mode); + + cv::Mat dstMerged; + cv::merge(dstChannels, dstMerged); + + EXPECT_LE(cv::norm(dstMulti, dstMerged, cv::NORM_INF), 1) + << "Multi-channel resize (cn=" << cn << ", mode=" << mode + << ") does not match per-channel resize"; +} + +INSTANTIATE_TEST_CASE_P(/**/, + Imgproc_ResizeMultiChannel, + testing::Combine( + testing::Values(cv::INTER_LINEAR, cv::INTER_AREA), + testing::Values(5, 8))); + TEST(Imgproc_resize_area, regression_half_round) { static uchar input_data[32 * 32];