diff --git a/modules/core/src/minmax.cpp b/modules/core/src/minmax.cpp index b5aa4c8462..8d4d185a54 100644 --- a/modules/core/src/minmax.cpp +++ b/modules/core/src/minmax.cpp @@ -1510,18 +1510,29 @@ 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*cn, src.rows, src.depth(), - minVal, maxVal, min_offset, max_offset, mask.data); + CALL_HAL(minMaxIdx, cv_hal_minMaxIdx, src.data, src.step, src.cols*cn, src.rows, + src.depth(), minVal, maxVal, minIdx, maxIdx, 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); + int res = cv_hal_minMaxIdx(src.data, 0, (int)src.total()*cn, 1, src.depth(), + minVal, maxVal, minIdx, maxIdx, mask.data); + + if (res == CV_HAL_ERROR_OK) + { + if (minIdx) + ofs2idx(src, minIdx[0], minIdx); + if (maxIdx) + ofs2idx(src, maxIdx[0], maxIdx); + return; + } + else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED) + { + CV_Error_(cv::Error::StsInternal, + ("HAL implementation minMaxIdx ==> " CVAUX_STR(cv_hal_minMaxIdx) " returned %d (0x%08x)", res, res)); + } } CV_OVX_RUN(!ovx::skipSmallImages(src.cols, src.rows), diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 73c755b0fa..7733d33519 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -2446,6 +2446,32 @@ TEST(Core_minMaxIdx, regression_9207_2) EXPECT_EQ(14, maxIdx[1]); } +TEST(Core_MinMaxIdx, MatND) +{ + const int shape[3] = {5,5,3}; + cv::Mat src = cv::Mat(3, shape, CV_8UC1); + src.setTo(1); + src.data[1] = 0; + src.data[5*5*3-2] = 2; + + int minIdx[3]; + int maxIdx[3]; + double minVal, maxVal; + + cv::minMaxIdx(src, &minVal, &maxVal, minIdx, maxIdx); + + EXPECT_EQ(0, minVal); + EXPECT_EQ(2, maxVal); + + EXPECT_EQ(0, minIdx[0]); + EXPECT_EQ(0, minIdx[1]); + EXPECT_EQ(1, minIdx[2]); + + EXPECT_EQ(4, maxIdx[0]); + EXPECT_EQ(4, maxIdx[1]); + EXPECT_EQ(1, maxIdx[2]); +} + TEST(Core_Set, regression_11044) { Mat testFloat(Size(3, 3), CV_32FC1); @@ -2807,7 +2833,6 @@ TEST(Core_MinMaxIdx, rows_overflow) } } - TEST(Core_Magnitude, regression_19506) { for (int N = 1; N <= 64; ++N)