Fixed minMaxLoc and test functions

pull/4204/head
Gleb Gladilov 10 years ago
parent 67158b12cd
commit c467d0d553
  1. 12
      modules/core/src/stat.cpp
  2. 15
      modules/ts/src/ts_func.cpp

@ -1097,8 +1097,8 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
size_t minidx = 0, maxidx = 0; size_t minidx = 0, maxidx = 0;
int iminval = INT_MAX, imaxval = INT_MIN; int iminval = INT_MAX, imaxval = INT_MIN;
float fminval = FLT_MAX, fmaxval = -FLT_MAX; float fminval = std::numeric_limits<float>::infinity(), fmaxval = -fminval;
double dminval = DBL_MAX, dmaxval = -DBL_MAX; double dminval = std::numeric_limits<double>::infinity(), dmaxval = -dminval;
size_t startidx = 1; size_t startidx = 1;
int *minval = &iminval, *maxval = &imaxval; int *minval = &iminval, *maxval = &imaxval;
int planeSize = (int)it.size*cn; int planeSize = (int)it.size*cn;
@ -1111,6 +1111,14 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
for( size_t i = 0; i < it.nplanes; i++, ++it, startidx += planeSize ) for( size_t i = 0; i < it.nplanes; i++, ++it, startidx += planeSize )
func( ptrs[0], ptrs[1], minval, maxval, &minidx, &maxidx, planeSize, startidx ); func( ptrs[0], ptrs[1], minval, maxval, &minidx, &maxidx, planeSize, startidx );
if (!src.empty() && mask.empty())
{
if( minidx == 0 )
minidx = 1;
if( maxidx == 0 )
maxidx = 1;
}
if( minidx == 0 ) if( minidx == 0 )
dminval = dmaxval = 0; dminval = dmaxval = 0;
else if( depth == CV_32F ) else if( depth == CV_32F )

@ -977,12 +977,12 @@ minMaxLoc_(const _Tp* src, size_t total, size_t startidx,
for( size_t i = 0; i < total; i++ ) for( size_t i = 0; i < total; i++ )
{ {
_Tp val = src[i]; _Tp val = src[i];
if( minval > val ) if( minval > val || !minpos )
{ {
minval = val; minval = val;
minpos = startidx + i; minpos = startidx + i;
} }
if( maxval < val ) if( maxval < val || !maxpos )
{ {
maxval = val; maxval = val;
maxpos = startidx + i; maxpos = startidx + i;
@ -994,12 +994,12 @@ minMaxLoc_(const _Tp* src, size_t total, size_t startidx,
for( size_t i = 0; i < total; i++ ) for( size_t i = 0; i < total; i++ )
{ {
_Tp val = src[i]; _Tp val = src[i];
if( minval > val && mask[i] ) if( (minval > val || !minpos) && mask[i] )
{ {
minval = val; minval = val;
minpos = startidx + i; minpos = startidx + i;
} }
if( maxval < val && mask[i] ) if( (maxval < val || !maxpos) && mask[i] )
{ {
maxval = val; maxval = val;
maxpos = startidx + i; maxpos = startidx + i;
@ -1046,8 +1046,8 @@ void minMaxLoc(const Mat& src, double* _minval, double* _maxval,
size_t startidx = 1, total = planes[0].total(); size_t startidx = 1, total = planes[0].total();
size_t i, nplanes = it.nplanes; size_t i, nplanes = it.nplanes;
int depth = src.depth(); int depth = src.depth();
double maxval = depth < CV_32F ? INT_MIN : depth == CV_32F ? -FLT_MAX : -DBL_MAX; double minval = 0;
double minval = depth < CV_32F ? INT_MAX : depth == CV_32F ? FLT_MAX : DBL_MAX; double maxval = 0;
size_t maxidx = 0, minidx = 0; size_t maxidx = 0, minidx = 0;
for( i = 0; i < nplanes; i++, ++it, startidx += total ) for( i = 0; i < nplanes; i++, ++it, startidx += total )
@ -1090,9 +1090,6 @@ void minMaxLoc(const Mat& src, double* _minval, double* _maxval,
} }
} }
if( minidx == 0 )
minval = maxval = 0;
if( _maxval ) if( _maxval )
*_maxval = maxval; *_maxval = maxval;
if( _minval ) if( _minval )

Loading…
Cancel
Save