📄 cxmean.cpp
字号:
( const arrtype* src, int step, \
const uchar* mask, int maskstep, \
CvSize size, double* mean ), \
(src, step, mask, maskstep, size, mean)) \
{ \
ICV_MEAN_ENTRY_BLOCK_C##cn( sumtype, worktype, block_size );\
\
for( ; size.height--; src += step, mask += maskstep ) \
{ \
int x = 0; \
while( x < size.width ) \
{ \
int limit = MIN( remaining, size.width - x ); \
remaining -= limit; \
limit += x; \
ICV_MEAN_CASE_C##cn( limit ); \
if( remaining == 0 ) \
{ \
ICV_MEAN_UPDATE_C##cn( block_size ); \
} \
} \
} \
\
{ ICV_MEAN_EXIT_BLOCK_C##cn(); } \
return CV_OK; \
}
#define ICV_IMPL_MEAN_FUNC_2D( flavor, cn, \
arrtype, sumtype, worktype ) \
IPCVAPI_IMPL( CvStatus, icvMean_##flavor##_C##cn##MR, \
( const arrtype* src, int step, \
const uchar* mask, int maskstep, \
CvSize size, double* mean), \
(src, step, mask, maskstep, size, mean)) \
{ \
ICV_MEAN_ENTRY_C##cn( sumtype ); \
\
for( ; size.height--; src += step, mask += maskstep ) \
{ \
int x = 0; \
ICV_MEAN_CASE_C##cn( size.width ); \
} \
\
{ ICV_MEAN_EXIT_C##cn( s ); } \
return CV_OK; \
}
#define ICV_IMPL_MEAN_BLOCK_FUNC_2D_COI( flavor, \
arrtype, sumtype, worktype, block_size ) \
static CvStatus CV_STDCALL \
icvMean_##flavor##_CnCMR( const arrtype* src, int step, \
const uchar* mask, int maskstep, \
CvSize size, int cn, \
int coi, double* mean ) \
{ \
ICV_MEAN_ENTRY_BLOCK_C1( sumtype, worktype, block_size ); \
src += coi - 1; \
\
for( ; size.height--; src += step, mask += maskstep ) \
{ \
int x = 0; \
while( x < size.width ) \
{ \
int limit = MIN( remaining, size.width - x ); \
remaining -= limit; \
limit += x; \
ICV_MEAN_COI_CASE( limit, cn ); \
if( remaining == 0 ) \
{ \
ICV_MEAN_UPDATE_C1( block_size ); \
} \
} \
} \
\
{ ICV_MEAN_EXIT_BLOCK_C1(); } \
return CV_OK; \
}
#define ICV_IMPL_MEAN_FUNC_2D_COI( flavor, \
arrtype, sumtype, worktype ) \
static CvStatus CV_STDCALL \
icvMean_##flavor##_CnCMR( const arrtype* src, int step, \
const uchar* mask, int maskstep, \
CvSize size, int cn, \
int coi, double* mean ) \
{ \
ICV_MEAN_ENTRY_C1( sumtype ); \
src += coi - 1; \
\
for( ; size.height--; src += step, mask += maskstep ) \
{ \
int x = 0; \
ICV_MEAN_COI_CASE( size.width, cn ); \
} \
\
{ ICV_MEAN_EXIT_C1( s ); } \
return CV_OK; \
}
#define ICV_IMPL_MEAN_BLOCK_ALL( flavor, arrtype, sumtype, \
worktype, block_size ) \
ICV_IMPL_MEAN_BLOCK_FUNC_2D( flavor, 1, arrtype, sumtype, \
worktype, block_size ) \
ICV_IMPL_MEAN_BLOCK_FUNC_2D( flavor, 2, arrtype, sumtype, \
worktype, block_size ) \
ICV_IMPL_MEAN_BLOCK_FUNC_2D( flavor, 3, arrtype, sumtype, \
worktype, block_size ) \
ICV_IMPL_MEAN_BLOCK_FUNC_2D( flavor, 4, arrtype, sumtype, \
worktype, block_size ) \
ICV_IMPL_MEAN_BLOCK_FUNC_2D_COI( flavor, arrtype, sumtype, \
worktype, block_size )
#define ICV_IMPL_MEAN_ALL( flavor, arrtype, sumtype, worktype ) \
ICV_IMPL_MEAN_FUNC_2D( flavor, 1, arrtype, sumtype, worktype ) \
ICV_IMPL_MEAN_FUNC_2D( flavor, 2, arrtype, sumtype, worktype ) \
ICV_IMPL_MEAN_FUNC_2D( flavor, 3, arrtype, sumtype, worktype ) \
ICV_IMPL_MEAN_FUNC_2D( flavor, 4, arrtype, sumtype, worktype ) \
ICV_IMPL_MEAN_FUNC_2D_COI( flavor, arrtype, sumtype, worktype )
ICV_IMPL_MEAN_BLOCK_ALL( 8u, uchar, int64, unsigned, 1 << 24 )
ICV_IMPL_MEAN_BLOCK_ALL( 16u, ushort, int64, unsigned, 1 << 16 )
ICV_IMPL_MEAN_BLOCK_ALL( 16s, short, int64, int, 1 << 16 )
ICV_IMPL_MEAN_ALL( 32s, int, double, double )
ICV_IMPL_MEAN_ALL( 32f, float, double, double )
ICV_IMPL_MEAN_ALL( 64f, double, double, double )
#define icvMean_8s_C1MR 0
#define icvMean_8s_C2MR 0
#define icvMean_8s_C3MR 0
#define icvMean_8s_C4MR 0
#define icvMean_8s_CnCMR 0
CV_DEF_INIT_BIG_FUNC_TAB_2D( Mean, MR )
CV_DEF_INIT_FUNC_TAB_2D( Mean, CnCMR )
CV_IMPL CvScalar
cvAvg( const void* img, const void* maskarr )
{
CvScalar mean = {{0,0,0,0}};
static CvBigFuncTable mean_tab;
static CvFuncTable meancoi_tab;
static int inittab = 0;
CV_FUNCNAME("cvAvg");
__BEGIN__;
CvSize size;
double scale;
if( !maskarr )
{
CV_CALL( mean = cvSum(img));
size = cvGetSize( img );
size.width *= size.height;
scale = size.width ? 1./size.width : 0;
mean.val[0] *= scale;
mean.val[1] *= scale;
mean.val[2] *= scale;
mean.val[3] *= scale;
}
else
{
int type, coi = 0;
int mat_step, mask_step;
CvMat stub, maskstub, *mat = (CvMat*)img, *mask = (CvMat*)maskarr;
if( !inittab )
{
icvInitMeanMRTable( &mean_tab );
icvInitMeanCnCMRTable( &meancoi_tab );
inittab = 1;
}
if( !CV_IS_MAT(mat) )
CV_CALL( mat = cvGetMat( mat, &stub, &coi ));
if( !CV_IS_MAT(mask) )
CV_CALL( mask = cvGetMat( mask, &maskstub ));
if( !CV_IS_MASK_ARR(mask) )
CV_ERROR( CV_StsBadMask, "" );
if( !CV_ARE_SIZES_EQ( mat, mask ) )
CV_ERROR( CV_StsUnmatchedSizes, "" );
type = CV_MAT_TYPE( mat->type );
size = cvGetMatSize( mat );
mat_step = mat->step;
mask_step = mask->step;
if( CV_IS_MAT_CONT( mat->type & mask->type ))
{
size.width *= size.height;
size.height = 1;
mat_step = mask_step = CV_STUB_STEP;
}
if( CV_MAT_CN(type) == 1 || coi == 0 )
{
CvFunc2D_2A1P func;
if( CV_MAT_CN(type) > 4 )
CV_ERROR( CV_StsOutOfRange, "The input array must have at most 4 channels unless COI is set" );
func = (CvFunc2D_2A1P)(mean_tab.fn_2d[type]);
if( !func )
CV_ERROR( CV_StsBadArg, cvUnsupportedFormat );
IPPI_CALL( func( mat->data.ptr, mat_step, mask->data.ptr,
mask_step, size, mean.val ));
}
else
{
CvFunc2DnC_2A1P func = (CvFunc2DnC_2A1P)(
meancoi_tab.fn_2d[CV_MAT_DEPTH(type)]);
if( !func )
CV_ERROR( CV_StsBadArg, cvUnsupportedFormat );
IPPI_CALL( func( mat->data.ptr, mat_step, mask->data.ptr,
mask_step, size, CV_MAT_CN(type), coi, mean.val ));
}
}
__END__;
return mean;
}
/* End of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -