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
This commit is contained in:
Dharshika Pugalenthi
2026-08-18 10:57:04 +05:30
committed by GitHub
parent 3621c83f2f
commit cc293eaff6
2 changed files with 40 additions and 1 deletions

View File

@@ -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<DecimateAlpha> _xytab((src_width + src_height)*2);
DecimateAlpha* xtab = _xytab.data(), *ytab = xtab + src_width*2;

View File

@@ -1275,6 +1275,45 @@ TEST(Imgproc_resize_area, regression)
check_resize_area<ushort>(expected, actual, 1.0);
}
CV_ENUM(MultiChannelResizeInter, cv::INTER_LINEAR, cv::INTER_AREA);
typedef testing::TestWithParam<testing::tuple<MultiChannelResizeInter, int>> 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<cv::Mat> 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<cv::Mat> 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];