📄 cxcmp.cpp
字号:
size = cvGetMatSize( src1 );
if( CV_IS_MAT_CONT( src1->type & dst->type ))
{
size.width *= size.height;
src1_step = dst_step = CV_STUB_STEP;
size.height = 1;
}
else
{
src1_step = src1->step;
dst_step = dst->step;
}
if( CV_MAT_CN(type) > 4 )
CV_ERROR( CV_StsOutOfRange, "The number of channels must be 1, 2, 3 or 4" );
func = (CvInRangeCFunc)(inrange_tab.fn_2d[type]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
cvScalarToRawData( &lower, buf, sctype, 0 );
cvScalarToRawData( &upper, (char*)buf + CV_ELEM_SIZE(sctype), sctype, 0 );
IPPI_CALL( func( src1->data.ptr, src1_step, dst->data.ptr,
dst_step, size, buf ));
__END__;
}
/****************************************************************************************\
* Cmp *
\****************************************************************************************/
#define ICV_DEF_CMP_CASE_C1( __op__, _toggle_macro_ ) \
for( x = 0; x <= size.width - 4; x += 4 ) \
{ \
int f0 = __op__( _toggle_macro_(src1[x]), _toggle_macro_(src2[x])); \
int f1 = __op__( _toggle_macro_(src1[x+1]), _toggle_macro_(src2[x+1])); \
dst[x] = (uchar)-f0; \
dst[x+1] = (uchar)-f1; \
f0 = __op__( _toggle_macro_(src1[x+2]), _toggle_macro_(src2[x+2])); \
f1 = __op__( _toggle_macro_(src1[x+3]), _toggle_macro_(src2[x+3])); \
dst[x+2] = (uchar)-f0; \
dst[x+3] = (uchar)-f1; \
} \
\
for( ; x < size.width; x++ ) \
{ \
int f0 = __op__( _toggle_macro_(src1[x]), _toggle_macro_(src2[x])); \
dst[x] = (uchar)-f0; \
}
#define ICV_DEF_CMP_FUNC( __op__, name, flavor, arrtype, \
worktype, _toggle_macro_ ) \
static CvStatus CV_STDCALL \
icv##name##_##flavor##_C1R( const arrtype* src1, int step1, \
const arrtype* src2, int step2, \
uchar* dst, int step, CvSize size ) \
{ \
step1 /= sizeof(src1[0]); step2 /= sizeof(src2[0]); \
step /= sizeof(dst[0]); \
\
for( ; size.height--; src1 += step1, src2 += step2, \
dst += step ) \
{ \
int x; \
ICV_DEF_CMP_CASE_C1( __op__, _toggle_macro_ ) \
} \
\
return CV_OK; \
}
#define ICV_DEF_CMP_CONST_CASE_C1( __op__, _toggle_macro_ ) \
for( x = 0; x <= size.width - 4; x += 4 ) \
{ \
int f0 = __op__( _toggle_macro_(src1[x]), scalar ); \
int f1 = __op__( _toggle_macro_(src1[x+1]), scalar ); \
dst[x] = (uchar)-f0; \
dst[x+1] = (uchar)-f1; \
f0 = __op__( _toggle_macro_(src1[x+2]), scalar ); \
f1 = __op__( _toggle_macro_(src1[x+3]), scalar ); \
dst[x+2] = (uchar)-f0; \
dst[x+3] = (uchar)-f1; \
} \
\
for( ; x < size.width; x++ ) \
{ \
int f0 = __op__( _toggle_macro_(src1[x]), scalar ); \
dst[x] = (uchar)-f0; \
}
#define ICV_DEF_CMP_CONST_FUNC( __op__, name, flavor, arrtype, \
worktype, _toggle_macro_) \
static CvStatus CV_STDCALL \
icv##name##C_##flavor##_C1R( const arrtype* src1, int step1, \
uchar* dst, int step, \
CvSize size, worktype* pScalar ) \
{ \
worktype scalar = *pScalar; \
step1 /= sizeof(src1[0]); step /= sizeof(dst[0]); \
\
for( ; size.height--; src1 += step1, dst += step ) \
{ \
int x; \
ICV_DEF_CMP_CONST_CASE_C1( __op__, _toggle_macro_ ) \
} \
\
return CV_OK; \
}
#define ICV_DEF_CMP_ALL( flavor, arrtype, worktype, _toggle_macro_ ) \
ICV_DEF_CMP_FUNC( CV_GT, CmpGT, flavor, arrtype, worktype, _toggle_macro_ ) \
ICV_DEF_CMP_FUNC( CV_EQ, CmpEQ, flavor, arrtype, worktype, _toggle_macro_ ) \
ICV_DEF_CMP_CONST_FUNC( CV_GT, CmpGT, flavor, arrtype, worktype, _toggle_macro_)\
ICV_DEF_CMP_CONST_FUNC( CV_GE, CmpGE, flavor, arrtype, worktype, _toggle_macro_)\
ICV_DEF_CMP_CONST_FUNC( CV_EQ, CmpEQ, flavor, arrtype, worktype, _toggle_macro_)
ICV_DEF_CMP_ALL( 8u, uchar, int, CV_NOP )
ICV_DEF_CMP_ALL( 16u, ushort, int, CV_NOP )
ICV_DEF_CMP_ALL( 16s, short, int, CV_NOP )
ICV_DEF_CMP_ALL( 32s, int, int, CV_NOP )
ICV_DEF_CMP_ALL( 32f, float, double, CV_NOP )
ICV_DEF_CMP_ALL( 64f, double, double, CV_NOP )
#define icvCmpGT_8s_C1R 0
#define icvCmpEQ_8s_C1R 0
#define icvCmpGTC_8s_C1R 0
#define icvCmpGEC_8s_C1R 0
#define icvCmpEQC_8s_C1R 0
CV_DEF_INIT_FUNC_TAB_2D( CmpGT, C1R )
CV_DEF_INIT_FUNC_TAB_2D( CmpEQ, C1R )
CV_DEF_INIT_FUNC_TAB_2D( CmpGTC, C1R )
CV_DEF_INIT_FUNC_TAB_2D( CmpGEC, C1R )
CV_DEF_INIT_FUNC_TAB_2D( CmpEQC, C1R )
icvCompare_8u_C1R_t icvCompare_8u_C1R_p = 0;
icvCompare_16s_C1R_t icvCompare_16s_C1R_p = 0;
icvCompare_32f_C1R_t icvCompare_32f_C1R_p = 0;
icvCompareC_8u_C1R_t icvCompareC_8u_C1R_p = 0;
icvCompareC_16s_C1R_t icvCompareC_16s_C1R_p = 0;
icvCompareC_32f_C1R_t icvCompareC_32f_C1R_p = 0;
icvThreshold_GT_8u_C1R_t icvThreshold_GT_8u_C1R_p = 0;
icvThreshold_GT_16s_C1R_t icvThreshold_GT_16s_C1R_p = 0;
icvThreshold_GT_32f_C1R_t icvThreshold_GT_32f_C1R_p = 0;
icvThreshold_LT_8u_C1R_t icvThreshold_LT_8u_C1R_p = 0;
icvThreshold_LT_16s_C1R_t icvThreshold_LT_16s_C1R_p = 0;
icvThreshold_LT_32f_C1R_t icvThreshold_LT_32f_C1R_p = 0;
/***************************************** cvCmp ****************************************/
CV_IMPL void
cvCmp( const void* srcarr1, const void* srcarr2,
void* dstarr, int cmp_op )
{
static CvFuncTable cmp_tab[2];
static int inittab = 0;
CV_FUNCNAME( "cvCmp" );
__BEGIN__;
int type, coi = 0;
int invflag = 0;
CvCmpOp ipp_cmp_op;
int src1_step, src2_step, dst_step;
CvMat srcstub1, *src1 = (CvMat*)srcarr1;
CvMat srcstub2, *src2 = (CvMat*)srcarr2;
CvMat dststub, *dst = (CvMat*)dstarr;
CvMat *temp;
CvSize size;
CvFunc2D_3A func;
if( !inittab )
{
icvInitCmpGTC1RTable( &cmp_tab[0] );
icvInitCmpEQC1RTable( &cmp_tab[1] );
inittab = 1;
}
if( !CV_IS_MAT(src1) )
{
CV_CALL( src1 = cvGetMat( src1, &srcstub1, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
if( !CV_IS_MAT(src2) )
{
CV_CALL( src2 = cvGetMat( src2, &srcstub2, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
if( !CV_IS_MAT(dst) )
{
CV_CALL( dst = cvGetMat( dst, &dststub, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
switch( cmp_op )
{
case CV_CMP_GT:
case CV_CMP_EQ:
break;
case CV_CMP_GE:
CV_SWAP( src1, src2, temp );
invflag = 1;
break;
case CV_CMP_LT:
CV_SWAP( src1, src2, temp );
break;
case CV_CMP_LE:
invflag = 1;
break;
case CV_CMP_NE:
cmp_op = CV_CMP_EQ;
invflag = 1;
break;
default:
CV_ERROR( CV_StsBadArg, "Unknown comparison operation" );
}
if( !CV_ARE_TYPES_EQ( src1, src2 ) )
CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );
if( CV_MAT_CN( src1->type ) != 1 )
CV_ERROR( CV_StsUnsupportedFormat, "Input arrays must be single-channel");
if( !CV_IS_MASK_ARR( dst ))
CV_ERROR( CV_StsUnsupportedFormat, "Destination array should be 8uC1 or 8sC1");
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 = cvGetMatSize( src1 );
if( CV_IS_MAT_CONT( src1->type & src2->type & dst->type ))
{
size.width *= size.height;
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;
}
func = (CvFunc2D_3A)(cmp_tab[cmp_op == CV_CMP_EQ].fn_2d[type]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
ipp_cmp_op = cmp_op == CV_CMP_EQ ? cvCmpEq : cvCmpGreater;
if( type == CV_8U && icvCompare_8u_C1R_p )
{
IPPI_CALL( icvCompare_8u_C1R_p( src1->data.ptr, src1_step, src2->data.ptr,
src2_step, dst->data.ptr, dst_step, size, ipp_cmp_op ));
}
else if( type == CV_16S && icvCompare_16s_C1R_p )
{
IPPI_CALL( icvCompare_16s_C1R_p( src1->data.s, src1_step, src2->data.s,
src2_step, dst->data.s, dst_step, size, ipp_cmp_op ));
}
else if( type == CV_32F && icvCompare_32f_C1R_p )
{
IPPI_CALL( icvCompare_32f_C1R_p( src1->data.fl, src1_step, src2->data.fl,
src2_step, dst->data.fl, dst_step, size, ipp_cmp_op ));
}
else
{
IPPI_CALL( func( src1->data.ptr, src1_step, src2->data.ptr, src2_step,
dst->data.ptr, dst_step, size ));
}
if( invflag )
IPPI_CALL( icvNot_8u_C1R( dst->data.ptr, dst_step,
dst->data.ptr, dst_step, size ));
__END__;
}
/*************************************** cvCmpS *****************************************/
CV_IMPL void
cvCmpS( const void* srcarr, double value, void* dstarr, int cmp_op )
{
static CvFuncTable cmps_tab[3];
static int inittab = 0;
CV_FUNCNAME( "cvCmpS" );
__BEGIN__;
int y, type, coi = 0;
int invflag = 0, ipp_cmp_op;
int src1_step, dst_step;
CvMat srcstub1, *src1 = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize size;
int ival = 0;
if( !inittab )
{
icvInitCmpEQCC1RTable( &cmps_tab[CV_CMP_EQ] );
icvInitCmpGTCC1RTable( &cmps_tab[CV_CMP_GT] );
icvInitCmpGECC1RTable( &cmps_tab[CV_CMP_GE] );
inittab = 1;
}
if( !CV_IS_MAT(src1) )
{
CV_CALL( src1 = cvGetMat( src1, &srcstub1, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
if( !CV_IS_MAT(dst) )
{
CV_CALL( dst = cvGetMat( dst, &dststub, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
switch( cmp_op )
{
case CV_CMP_GT:
case CV_CMP_EQ:
case CV_CMP_GE:
break;
case CV_CMP_LT:
invflag = 1;
cmp_op = CV_CMP_GE;
break;
case CV_CMP_LE:
invflag = 1;
cmp_op = CV_CMP_GT;
break;
case CV_CMP_NE:
invflag = 1;
cmp_op = CV_CMP_EQ;
break;
default:
CV_ERROR( CV_StsBadArg, "Unknown comparison operation" );
}
if( !CV_IS_MASK_ARR( dst ))
CV_ERROR( CV_StsUnsupportedFormat, "Destination array should be 8uC1 or 8sC1");
if( CV_MAT_CN( src1->type ) != 1 )
CV_ERROR( CV_StsUnsupportedFormat, "Input array must be single-channel");
if( !CV_ARE_SIZES_EQ( src1, dst ))
CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );
type = CV_MAT_TYPE(src1->type);
size = cvGetMatSize( src1 );
if( CV_IS_MAT_CONT( src1->type & dst->type ))
{
size.width *= size.height;
src1_step = dst_step = CV_STUB_STEP;
size.height = 1;
}
else
{
src1_step = src1->step;
dst_step = dst->step;
}
if( CV_MAT_DEPTH(type) <= CV_32S )
{
ival = cvRound(value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -