Skip to content

Commit 32683ee

Browse files
committed
Merge pull request opencv#9208 from alalek:ipp_minmaxidx
2 parents 9313978 + 544eb4b commit 32683ee

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed

modules/core/src/stat.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,12 @@ static bool ipp_minMaxIdx(Mat &src, double* _minVal, double* _maxVal, int* _minI
25302530
return false;
25312531
#endif
25322532

2533+
// cv::minMaxIdx problem with index positions on AVX
2534+
#if IPP_VERSION_X100 < 201810
2535+
if(!mask.empty() && _maxIdx && ipp::getIppFeatures()&ippCPUID_AVX)
2536+
return false;
2537+
#endif
2538+
25332539
IppStatus status;
25342540
IppDataType dataType = ippiGetDataType(src.depth());
25352541
float minVal = 0;
@@ -2561,15 +2567,16 @@ static bool ipp_minMaxIdx(Mat &src, double* _minVal, double* _maxVal, int* _minI
25612567
size.width *= src.channels();
25622568

25632569
status = ippMinMaxFun(src.ptr(), (int)src.step, size, dataType, pMinVal, pMaxVal, pMinIdx, pMaxIdx, (Ipp8u*)mask.ptr(), (int)mask.step);
2564-
if(status < 0 || status == ippStsNoOperation)
2570+
if(status < 0)
25652571
return false;
25662572
if(_minVal)
25672573
*_minVal = minVal;
25682574
if(_maxVal)
25692575
*_maxVal = maxVal;
25702576
if(_minIdx)
25712577
{
2572-
if(!mask.empty() && !minIdx.y && !minIdx.x)
2578+
// Should be just ippStsNoOperation check, but there is a bug in the function so we need additional checks
2579+
if(status == ippStsNoOperation && !mask.empty() && !pMinIdx->x && !pMinIdx->y)
25732580
{
25742581
_minIdx[0] = -1;
25752582
_minIdx[1] = -1;
@@ -2582,7 +2589,8 @@ static bool ipp_minMaxIdx(Mat &src, double* _minVal, double* _maxVal, int* _minI
25822589
}
25832590
if(_maxIdx)
25842591
{
2585-
if(!mask.empty() && !maxIdx.y && !maxIdx.x)
2592+
// Should be just ippStsNoOperation check, but there is a bug in the function so we need additional checks
2593+
if(status == ippStsNoOperation && !mask.empty() && !pMaxIdx->x && !pMaxIdx->y)
25862594
{
25872595
_maxIdx[0] = -1;
25882596
_maxIdx[1] = -1;

modules/core/test/test_arithm.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,3 +1932,77 @@ TEST(Compare, regression_8999)
19321932
compare(A, B, C, CMP_LT);
19331933
});
19341934
}
1935+
1936+
1937+
TEST(Core_minMaxIdx, regression_9207_1)
1938+
{
1939+
const int rows = 4;
1940+
const int cols = 3;
1941+
uchar mask_[rows*cols] = {
1942+
255, 255, 255,
1943+
255, 0, 255,
1944+
0, 255, 255,
1945+
0, 0, 255
1946+
};
1947+
uchar src_[rows*cols] = {
1948+
1, 1, 1,
1949+
1, 1, 1,
1950+
2, 1, 1,
1951+
2, 2, 1
1952+
};
1953+
Mat mask(Size(cols, rows), CV_8UC1, mask_);
1954+
Mat src(Size(cols, rows), CV_8UC1, src_);
1955+
double minVal = -0.0, maxVal = -0.0;
1956+
int minIdx[2] = { -2, -2 }, maxIdx[2] = { -2, -2 };
1957+
minMaxIdx(src, &minVal, &maxVal, minIdx, maxIdx, mask);
1958+
EXPECT_EQ(0, minIdx[0]);
1959+
EXPECT_EQ(0, minIdx[1]);
1960+
EXPECT_EQ(0, maxIdx[0]);
1961+
EXPECT_EQ(0, maxIdx[1]);
1962+
}
1963+
1964+
1965+
TEST(Core_minMaxIdx, regression_9207_2)
1966+
{
1967+
const int rows = 13;
1968+
const int cols = 15;
1969+
uchar mask_[rows*cols] = {
1970+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,
1971+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,
1972+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,
1973+
0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,
1974+
255, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255,
1975+
255, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 255, 255,
1976+
255, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 255, 255, 255, 0,
1977+
255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 0,
1978+
255, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 255, 255, 0,
1979+
255, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 255, 0,
1980+
255, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1981+
0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1982+
0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1983+
};
1984+
uchar src_[15*13] = {
1985+
5, 5, 5, 5, 5, 6, 5, 2, 0, 4, 6, 6, 4, 1, 0,
1986+
6, 5, 4, 4, 5, 6, 6, 5, 2, 0, 4, 6, 5, 2, 0,
1987+
3, 2, 1, 1, 2, 4, 6, 6, 4, 2, 3, 4, 4, 2, 0,
1988+
1, 0, 0, 0, 0, 1, 4, 5, 4, 4, 4, 4, 3, 2, 0,
1989+
0, 0, 0, 0, 0, 0, 2, 3, 4, 4, 4, 3, 2, 1, 0,
1990+
0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 3, 2, 1, 0, 0,
1991+
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1,
1992+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1993+
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1,
1994+
0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 3, 3, 1, 0, 1,
1995+
0, 0, 0, 0, 0, 0, 1, 4, 5, 6, 5, 4, 3, 2, 0,
1996+
1, 0, 0, 0, 0, 0, 3, 5, 5, 4, 3, 4, 4, 3, 0,
1997+
2, 0, 0, 0, 0, 2, 5, 6, 5, 2, 2, 5, 4, 3, 0
1998+
};
1999+
Mat mask(Size(cols, rows), CV_8UC1, mask_);
2000+
Mat src(Size(cols, rows), CV_8UC1, src_);
2001+
double minVal = -0.0, maxVal = -0.0;
2002+
int minIdx[2] = { -2, -2 }, maxIdx[2] = { -2, -2 };
2003+
minMaxIdx(src, &minVal, &maxVal, minIdx, maxIdx, mask);
2004+
EXPECT_EQ(0, minIdx[0]);
2005+
EXPECT_EQ(14, minIdx[1]);
2006+
EXPECT_EQ(0, maxIdx[0]);
2007+
EXPECT_EQ(14, maxIdx[1]);
2008+
}

0 commit comments

Comments
 (0)