From 5b4d1ce6a09747c9bcaeab97f11aa410e9bcd398 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov <2536374+asmorkalov@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:10:24 +0300 Subject: [PATCH] Merge pull request #26080 from asmorkalov:as/HAL_minMaxIdx_ND_offset Added offset for HAL as ofs2idx expects 1-based index #26080 ### 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 - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] 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/minmax.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/core/src/minmax.cpp b/modules/core/src/minmax.cpp index 8c6d8ad9a9..8a4a54522f 100644 --- a/modules/core/src/minmax.cpp +++ b/modules/core/src/minmax.cpp @@ -846,6 +846,8 @@ static MinMaxIdxFunc getMinmaxTab(int depth) return minmaxTab[depth]; } +// The function expects 1-based indexing for ofs +// Zero is treated as invalid offset (not found) static void ofs2idx(const Mat& a, size_t ofs, int* idx) { int i, d = a.dims; @@ -1524,9 +1526,9 @@ void cv::minMaxIdx(InputArray _src, double* minVal, { // minIdx[0] and minIdx[0] are always 0 for "flatten" version if (minIdx) - ofs2idx(src, minIdx[1], minIdx); + ofs2idx(src, minIdx[1]+1, minIdx); if (maxIdx) - ofs2idx(src, maxIdx[1], maxIdx); + ofs2idx(src, maxIdx[1]+1, maxIdx); return; } else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED)