Skip to content

Commit

Permalink
Merge pull request #25553 from asmorkalov:as/HAL_min_max_idx
Browse files Browse the repository at this point in the history
Fix HAL interface for hal_ni_minMaxIdx #25553

Fixes #25540

The original implementation call HAL with the same parameters independently from amount of channels. The patch uses HAL correctly for the case cn > 1.

### 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
- [ ] 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
  • Loading branch information
asmorkalov committed May 7, 2024
1 parent a9e489f commit faa259a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 2 additions & 5 deletions modules/core/include/opencv2/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,8 @@ CV_EXPORTS_W void reduceArgMax(InputArray src, OutputArray dst, int axis, bool l
The function cv::minMaxIdx finds the minimum and maximum element values and their positions. The
extremums are searched across the whole array or, if mask is not an empty array, in the specified
array region. The function does not work with multi-channel arrays. If you need to find minimum or
maximum elements across all the channels, use Mat::reshape first to reinterpret the array as
single-channel. Or you may extract the particular channel using either extractImageCOI, or
mixChannels, or split. In case of a sparse matrix, the minimum is found among non-zero elements
only.
array region. In case of a sparse matrix, the minimum is found among non-zero elements
only. Multi-channel input is supported without mask and extremums indexes (should be nullptr).
@note When minIdx is not NULL, it must have at least 2 elements (as well as maxIdx), even if src is
a single-row or single-column matrix. In OpenCV (following MATLAB) each array has at least 2
dimensions, i.e. single-column matrix is Mx1 matrix (and therefore minIdx/maxIdx will be
Expand Down
14 changes: 12 additions & 2 deletions modules/core/src/minmax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,9 +1510,19 @@ void cv::minMaxIdx(InputArray _src, double* minVal,

Mat src = _src.getMat(), mask = _mask.getMat();

int _minIdx, _maxIdx;
int* min_offset = (cn == 1) ? minIdx : &_minIdx;
int* max_offset = (cn == 1) ? maxIdx : &_maxIdx;
if (src.dims <= 2)
CALL_HAL(minMaxIdx, cv_hal_minMaxIdx, src.data, src.step, src.cols, src.rows, src.depth(), minVal, maxVal,
minIdx, maxIdx, mask.data);
{
CALL_HAL(minMaxIdx, cv_hal_minMaxIdx, src.data, src.step, src.cols*cn, src.rows, src.depth(),
minVal, maxVal, min_offset, max_offset, mask.data);
}
else if (src.isContinuous())
{
CALL_HAL(minMaxIdx, cv_hal_minMaxIdx, src.data, 0, (int)src.total()*cn, 1, src.depth(),
minVal, maxVal, min_offset, max_offset, mask.data);
}

CV_OVX_RUN(!ovx::skipSmallImages<VX_KERNEL_MINMAXLOC>(src.cols, src.rows),
openvx_minMaxIdx(src, minVal, maxVal, minIdx, maxIdx, mask))
Expand Down

0 comments on commit faa259a

Please sign in to comment.