Merge pull request #25553 from asmorkalov:as/HAL_min_max_idx

Fix HAL interface for hal_ni_minMaxIdx #25553

Fixes https://github.com/opencv/opencv/issues/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
pull/25583/head
Alexander Smorkalov 9 months ago committed by GitHub
parent a9e489f149
commit faa259ab34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      modules/core/include/opencv2/core.hpp
  2. 14
      modules/core/src/minmax.cpp

@ -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

@ -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))

Loading…
Cancel
Save