From 446787ab486742d942acace677c1cc6999b620da Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 5 Dec 2024 09:03:51 +0300 Subject: [PATCH] Merge pull request #26571 from vpisarev:fix_26497 Fixed issue when std::vector is wrapped into Mat with explicit step. #26571 Hopefully, fixes #26497 - [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. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/core/src/matrix.cpp | 2 +- modules/imgproc/test/test_imgwarp.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 7b6c3f497f..5f4f91dc43 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -895,7 +895,7 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step) size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); size_t minstep = cols*esz; - if( _step == AUTO_STEP ) + if( _step == AUTO_STEP || (_step < minstep && rows == 1)) { _step = minstep; } diff --git a/modules/imgproc/test/test_imgwarp.cpp b/modules/imgproc/test/test_imgwarp.cpp index deb5791f29..aded7bb74e 100644 --- a/modules/imgproc/test/test_imgwarp.cpp +++ b/modules/imgproc/test/test_imgwarp.cpp @@ -1200,5 +1200,17 @@ TEST(Imgproc_Remap, issue_23562) } } +TEST(Imgproc_Resize, issue_26497) +{ + std::vector vec = {0.f, 1.f, 2.f, 3.f}; + Mat A(vec), B; + resize(A, B, Size(2,2), 0, 0, INTER_LINEAR); + double minv = 0, maxv = 0; + cvtest::minMaxIdx(B, &minv, &maxv, nullptr, nullptr, noArray()); + EXPECT_EQ(B.size(), Size(2, 2)); + EXPECT_LE(0., minv); + EXPECT_LE(maxv, 3.); +} + }} // namespace /* End of file. */