📄 cxminmaxloc.cpp
字号:
\
CV_MINMAXLOC_EXIT( _fin_cast_macro_ ); \
}
#define ICV_DEF_MINMAXLOC_MASK_FUNC_2D_COI( _toggle_, _fin_cast_macro_, \
flavor, srctype, temptype, extrtype ) \
static CvStatus CV_STDCALL \
icvMinMaxIndx_##flavor##_CnCMR( const srctype* src, int step, \
const uchar* mask, int maskStep, CvSize size, int cn, int coi, \
extrtype* minVal, extrtype* maxVal, CvPoint* minLoc, CvPoint* maxLoc ) \
{ \
(src) += coi - 1; \
CV_MINMAXLOC_MASK_ENTRY( _toggle_, srctype, temptype, cn ); \
\
for( ; y < size.height; y++, src += step, mask += maskStep ) \
{ \
ICV_DEF_MINMAXLOC_1D_MASK_CASE_COI( _toggle_, temptype, cn ) \
x = 0; \
} \
\
CV_MINMAXLOC_EXIT( _fin_cast_macro_ ); \
}
#define ICV_DEF_MINMAXLOC_MASK_ALL_INT( flavor, srctype, \
_fin_cast_macro_, extrtype ) \
ICV_DEF_MINMAXLOC_MASK_FUNC_2D( CV_NOP, _fin_cast_macro_, flavor, \
srctype, int, extrtype ) \
ICV_DEF_MINMAXLOC_MASK_FUNC_2D_COI( CV_NOP, _fin_cast_macro_, flavor, \
srctype, int, extrtype )
#define ICV_DEF_MINMAXLOC_MASK_ALL_FLT( flavor, srctype, _toggle_, \
_fin_cast_macro_, extrtype ) \
ICV_DEF_MINMAXLOC_MASK_FUNC_2D( _toggle_, _fin_cast_macro_, flavor, \
srctype, srctype, extrtype ) \
ICV_DEF_MINMAXLOC_MASK_FUNC_2D_COI( _toggle_, _fin_cast_macro_, flavor, \
srctype, srctype, extrtype )
ICV_DEF_MINMAXLOC_MASK_ALL_INT( 8u, uchar, CV_CAST_32F, float )
ICV_DEF_MINMAXLOC_MASK_ALL_INT( 16u, ushort, CV_CAST_32F, float )
ICV_DEF_MINMAXLOC_MASK_ALL_INT( 16s, short, CV_CAST_32F, float )
ICV_DEF_MINMAXLOC_MASK_ALL_INT( 32s, int, CV_CAST_64F, double )
ICV_DEF_MINMAXLOC_MASK_ALL_FLT( 32f, int, CV_TOGGLE_FLT, minmax_to_float, float )
ICV_DEF_MINMAXLOC_MASK_ALL_FLT( 64f, int64, CV_TOGGLE_DBL, minmax_to_double, double )
#define icvMinMaxIndx_8s_C1R 0
#define icvMinMaxIndx_8s_CnCR 0
#define icvMinMaxIndx_8s_C1MR 0
#define icvMinMaxIndx_8s_CnCMR 0
CV_DEF_INIT_FUNC_TAB_2D( MinMaxIndx, C1R )
CV_DEF_INIT_FUNC_TAB_2D( MinMaxIndx, CnCR )
CV_DEF_INIT_FUNC_TAB_2D( MinMaxIndx, C1MR )
CV_DEF_INIT_FUNC_TAB_2D( MinMaxIndx, CnCMR )
CV_IMPL void
cvMinMaxLoc( const void* img, double* _minVal, double* _maxVal,
CvPoint* _minLoc, CvPoint* _maxLoc, const void* mask )
{
static CvFuncTable minmax_tab, minmaxcoi_tab;
static CvFuncTable minmaxmask_tab, minmaxmaskcoi_tab;
static int inittab = 0;
CV_FUNCNAME("cvMinMaxLoc");
__BEGIN__;
int type, depth, cn, coi = 0;
int mat_step, mask_step = 0, cont_flag;
CvSize size;
CvMat stub, maskstub, *mat = (CvMat*)img, *matmask = (CvMat*)mask;
CvPoint minloc, maxloc;
double minv = 0, maxv = 0;
float minvf = 0.f, maxvf = 0.f;
void *pmin = &minvf, *pmax = &maxvf;
if( !inittab )
{
icvInitMinMaxIndxC1RTable( &minmax_tab );
icvInitMinMaxIndxCnCRTable( &minmaxcoi_tab );
icvInitMinMaxIndxC1MRTable( &minmaxmask_tab );
icvInitMinMaxIndxCnCMRTable( &minmaxmaskcoi_tab );
inittab = 1;
}
if( !CV_IS_MAT(mat) )
CV_CALL( mat = cvGetMat( mat, &stub, &coi ));
type = CV_MAT_TYPE( mat->type );
depth = CV_MAT_DEPTH( type );
cn = CV_MAT_CN( type );
size = cvGetMatSize( mat );
if( cn > 1 && coi == 0 )
CV_ERROR( CV_StsBadArg, "" );
if( depth == CV_32S || depth == CV_64F )
pmin = &minv, pmax = &maxv;
mat_step = mat->step;
cont_flag = mat->type;
if( mask )
{
CV_CALL( matmask = cvGetMat( matmask, &maskstub ));
if( !CV_IS_MASK_ARR( matmask ))
CV_ERROR( CV_StsBadMask, "" );
if( !CV_ARE_SIZES_EQ( mat, matmask ))
CV_ERROR( CV_StsUnmatchedSizes, "" );
mask_step = matmask->step;
cont_flag &= matmask->type;
}
if( CV_IS_MAT_CONT(cont_flag) )
{
size.width *= size.height;
size.height = 1;
}
if( size.height == 1 )
mat_step = mask_step = CV_STUB_STEP;
if( !mask )
{
if( CV_MAT_CN(type) == 1 || coi == 0 )
{
CvFunc2D_1A4P func = (CvFunc2D_1A4P)(minmax_tab.fn_2d[depth]);
if( !func )
CV_ERROR( CV_StsBadArg, cvUnsupportedFormat );
IPPI_CALL( func( mat->data.ptr, mat_step, size,
pmin, pmax, &minloc, &maxloc ));
}
else
{
CvFunc2DnC_1A4P func = (CvFunc2DnC_1A4P)(minmaxcoi_tab.fn_2d[depth]);
if( !func )
CV_ERROR( CV_StsBadArg, cvUnsupportedFormat );
IPPI_CALL( func( mat->data.ptr, mat_step, size, cn, coi,
pmin, pmax, &minloc, &maxloc ));
}
}
else
{
if( CV_MAT_CN(type) == 1 || coi == 0 )
{
CvFunc2D_2A4P func = (CvFunc2D_2A4P)(minmaxmask_tab.fn_2d[depth]);
if( !func )
CV_ERROR( CV_StsBadArg, cvUnsupportedFormat );
IPPI_CALL( func( mat->data.ptr, mat_step, matmask->data.ptr,
mask_step, size,
pmin, pmax, &minloc, &maxloc ));
}
else
{
CvFunc2DnC_2A4P func = (CvFunc2DnC_2A4P)(minmaxmaskcoi_tab.fn_2d[depth]);
if( !func )
CV_ERROR( CV_StsBadArg, cvUnsupportedFormat );
IPPI_CALL( func( mat->data.ptr, mat_step,
matmask->data.ptr, mask_step, size, cn, coi,
pmin, pmax, &minloc, &maxloc ));
}
}
if( matmask || _minLoc || _maxLoc )
{
if( minloc.x >= mat->cols )
{
minloc.y = minloc.x / mat->cols;
minloc.x -= minloc.y * mat->cols;
}
if( maxloc.x >= mat->cols )
{
maxloc.y = maxloc.x / mat->cols;
maxloc.x -= maxloc.y * mat->cols;
}
if( matmask && ((unsigned)minloc.x >= (unsigned)mat->cols ||
(unsigned)minloc.y >= (unsigned)mat->rows ||
matmask->data.ptr[minloc.y*matmask->step + minloc.x] == 0 ||
(unsigned)maxloc.x >= (unsigned)mat->cols ||
(unsigned)maxloc.y >= (unsigned)mat->rows ||
matmask->data.ptr[maxloc.y*matmask->step + maxloc.x] == 0) )
{
minloc.x = minloc.y = maxloc.x = maxloc.y = -1;
minv = maxv = minvf = maxvf = 0;
}
if( _minLoc )
*_minLoc = minloc;
if( _maxLoc )
*_maxLoc = maxloc;
}
if( depth != CV_32S && depth != CV_64F )
{
minv = minvf;
maxv = maxvf;
}
if( _minVal )
*_minVal = minv;
if( _maxVal )
*_maxVal = maxv;
__END__;
}
/* End of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -