cvarithm.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 1,439 行 · 第 1/5 页
SVN-BASE
1,439 行
{ \
tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u_##FLAG; \
tab->fn_2d[CV_8S] = 0; \
tab->fn_2d[CV_16S] = (void*)icv##FUNCNAME##_16s_##FLAG; \
tab->fn_2d[CV_32S] = (void*)icv##FUNCNAME##_32s_##FLAG; \
tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_##FLAG; \
tab->fn_2d[CV_64F] = (void*)icv##FUNCNAME##_64f_##FLAG; \
}
ICV_DEF_INIT_ARITHM_MASK_FUNC_TAB( Add, CnMR )
ICV_DEF_INIT_ARITHM_MASK_FUNC_TAB( AddC, CnMR )
ICV_DEF_INIT_ARITHM_MASK_FUNC_TAB( Sub, CnMR )
ICV_DEF_INIT_ARITHM_MASK_FUNC_TAB( SubR, CnMR )
ICV_DEF_INIT_ARITHM_MASK_FUNC_TAB( SubRC, CnMR )
/****************************************************************************************\
* External Functions for Arithmetic Operations *
\****************************************************************************************/
/*************************************** S U B ******************************************/
CV_IMPL void
cvSub( const void* srcarr1, const void* srcarr2,
void* dstarr, const void* maskarr )
{
static CvFuncTable submask_tab[2];
static CvFuncTable sub_tab;
static int inittab = 0, initmasktab = 0;
CV_FUNCNAME( "cvSub" );
__BEGIN__;
int type;
int src1_step, src2_step, dst_step;
CvMat srcstub1, *src1 = (CvMat*)srcarr1;
CvMat srcstub2, *src2 = (CvMat*)srcarr2;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize size;
if( !CV_IS_MAT(src1) || !CV_IS_MAT(src2) || !CV_IS_MAT(dst))
{
if( CV_IS_MATND(src1) || CV_IS_MATND(src2) || CV_IS_MATND(dst))
{
CvArr* arrs[] = { src1, src2, dst };
CvMatND stubs[3];
CvMatNDIterator iterator;
CvFunc2D_3A func;
if( maskarr )
CV_ERROR( CV_StsBadMask,
"This operation on multi-dimensional arrays does not support mask" );
CV_CALL( icvPrepareArrayOp( 3, arrs, 0, stubs, &iterator ));
type = iterator.hdr[0]->type;
iterator.size.width *= CV_MAT_CN(type);
if( !inittab )
{
icvInitSubC1RTable( &sub_tab );
inittab = 1;
}
func = (CvFunc2D_3A)(sub_tab.fn_2d[CV_MAT_DEPTH(type)]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
do
{
IPPI_CALL( func( iterator.ptr[0], CV_STUB_STEP,
iterator.ptr[1], CV_STUB_STEP,
iterator.ptr[2], CV_STUB_STEP,
iterator.size ));
}
while( icvNextMatNDSlice( &iterator ));
EXIT;
}
else
{
int coi1 = 0, coi2 = 0, coi3 = 0;
CV_CALL( src1 = cvGetMat( src1, &srcstub1, &coi1 ));
CV_CALL( src2 = cvGetMat( src2, &srcstub2, &coi2 ));
CV_CALL( dst = cvGetMat( dst, &dststub, &coi3 ));
if( coi1 + coi2 + coi3 != 0 )
CV_ERROR( CV_BadCOI, "" );
}
}
if( !CV_ARE_TYPES_EQ( src1, src2 ) || !CV_ARE_TYPES_EQ( src1, dst ))
CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );
if( !CV_ARE_SIZES_EQ( src1, src2 ) || !CV_ARE_SIZES_EQ( src1, dst ))
CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );
type = CV_MAT_TYPE(src1->type);
size = icvGetMatSize( src1 );
if( !maskarr )
{
int depth = CV_MAT_DEPTH(type);
size.width *= CV_MAT_CN( type );
if( CV_IS_MAT_CONT( src1->type & src2->type & dst->type ))
{
size.width *= size.height;
if( size.width <= CV_MAX_INLINE_MAT_OP_SIZE*
CV_MAX_INLINE_MAT_OP_SIZE )
{
if( depth == CV_32F )
{
const float* src1data = (const float*)(src1->data.ptr);
const float* src2data = (const float*)(src2->data.ptr);
float* dstdata = (float*)(dst->data.ptr);
do
{
dstdata[size.width-1] = (float)
(src1data[size.width-1] - src2data[size.width-1]);
}
while( --size.width );
EXIT;
}
if( depth == CV_64F )
{
const double* src1data = (const double*)(src1->data.ptr);
const double* src2data = (const double*)(src2->data.ptr);
double* dstdata = (double*)(dst->data.ptr);
do
{
dstdata[size.width-1] =
src1data[size.width-1] - src2data[size.width-1];
}
while( --size.width );
EXIT;
}
}
src1_step = src2_step = dst_step = CV_STUB_STEP;
size.height = 1;
}
else
{
src1_step = src1->step;
src2_step = src2->step;
dst_step = dst->step;
}
if( !inittab )
{
icvInitSubC1RTable( &sub_tab );
inittab = 1;
}
{
CvFunc2D_3A func = (CvFunc2D_3A)(sub_tab.fn_2d[depth]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
IPPI_CALL( func( src1->data.ptr, src1_step, src2->data.ptr, src2_step,
dst->data.ptr, dst_step, size ));
}
}
else
{
CvMat maskstub, *mask = (CvMat*)maskarr;
CvArithmBinMaskFunc2D func;
int inv = 0;
int mask_step;
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( mask, dst ))
CV_ERROR( CV_StsUnmatchedSizes, "" );
if( dst->data.ptr == src1->data.ptr )
;
else if( dst->data.ptr == src2->data.ptr )
{
inv = 1;
src2 = src1;
}
else
{
CV_CALL( cvCopy( src1, dst, mask ));
}
if( CV_IS_MAT_CONT( src2->type & dst->type & mask->type ))
{
size.width *= size.height;
src2_step = dst_step = mask_step = CV_STUB_STEP;
size.height = 1;
}
else
{
src2_step = src2->step;
dst_step = dst->step;
mask_step = mask->step;
}
if( !initmasktab )
{
icvInitSubCnMRTable( &submask_tab[0] );
icvInitSubRCnMRTable( &submask_tab[1] );
initmasktab = 1;
}
func = (CvArithmBinMaskFunc2D)
(submask_tab[inv].fn_2d[CV_MAT_DEPTH(type)]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
IPPI_CALL( func( src2->data.ptr, src2_step,
mask->data.ptr, mask_step,
dst->data.ptr, dst_step, size, CV_MAT_CN(type) ));
}
__END__;
}
CV_IMPL void
cvSubRS( const void* srcarr, CvScalar scalar, void* dstarr, const void* maskarr )
{
static CvFuncTable subrmask_tab;
static CvFuncTable subr_tab;
static int inittab = 0;
CV_FUNCNAME( "cvSubRS" );
__BEGIN__;
int sctype, type, coi = 0;
int src_step, dst_step;
CvMat srcstub, *src = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
double buf[12];
int is_nd = 0;
CvSize size;
if( !inittab )
{
icvInitSubRCC1RTable( &subr_tab );
icvInitSubRCCnMRTable( &subrmask_tab );
inittab = 1;
}
if( !CV_IS_MAT(src) )
{
if( CV_IS_MATND(src) )
is_nd = 1;
else
{
CV_CALL( src = cvGetMat( src, &srcstub, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
}
if( !CV_IS_MAT(dst) )
{
if( CV_IS_MATND(dst) )
is_nd = 1;
else
{
CV_CALL( dst = cvGetMat( dst, &dststub, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
}
if( is_nd )
{
CvArr* arrs[] = { src, dst };
CvMatND stubs[2];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?