📄 cxcmp.cpp
字号:
if( type == CV_8U || type == CV_16S )
{
int minval = type == CV_8U ? 0 : -32768;
int maxval = type == CV_8U ? 255 : 32767;
int fillval = -1;
if( ival < minval )
fillval = cmp_op == CV_CMP_NE || cmp_op == CV_CMP_GE || cmp_op == CV_CMP_GT ? 255 : 0;
else if( ival > maxval )
fillval = cmp_op == CV_CMP_NE || cmp_op == CV_CMP_LE || cmp_op == CV_CMP_LT ? 255 : 0;
if( fillval >= 0 )
{
fillval ^= invflag ? 255 : 0;
for( y = 0; y < size.height; y++ )
memset( dst->data.ptr + y*dst_step, fillval, size.width );
EXIT;
}
}
}
ipp_cmp_op = cmp_op == CV_CMP_EQ ? cvCmpEq :
cmp_op == CV_CMP_GE ? cvCmpGreaterEq : cvCmpGreater;
if( type == CV_8U && icvCompare_8u_C1R_p )
{
IPPI_CALL( icvCompareC_8u_C1R_p( src1->data.ptr, src1_step, (uchar)ival,
dst->data.ptr, dst_step, size, ipp_cmp_op ));
}
else if( type == CV_16S && icvCompare_16s_C1R_p )
{
IPPI_CALL( icvCompareC_16s_C1R_p( src1->data.s, src1_step, (short)ival,
dst->data.s, dst_step, size, ipp_cmp_op ));
}
else if( type == CV_32F && icvCompare_32f_C1R_p )
{
IPPI_CALL( icvCompareC_32f_C1R_p( src1->data.fl, src1_step, (float)value,
dst->data.fl, dst_step, size, ipp_cmp_op ));
}
else
{
CvFunc2D_2A1P func = (CvFunc2D_2A1P)(cmps_tab[cmp_op].fn_2d[type]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
if( type <= CV_32S )
{
IPPI_CALL( func( src1->data.ptr, src1_step, dst->data.ptr,
dst_step, size, &ival ));
}
else
{
IPPI_CALL( func( src1->data.ptr, src1_step, dst->data.ptr,
dst_step, size, &value ));
}
}
if( invflag )
IPPI_CALL( icvNot_8u_C1R( dst->data.ptr, dst_step,
dst->data.ptr, dst_step, size ));
__END__;
}
/****************************************************************************************\
* Min/Max *
\****************************************************************************************/
#define ICV_DEF_MINMAX_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, \
arrtype* 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; \
for( x = 0; x <= size.width - 4; x += 4 ) \
{ \
worktype a0 = _toggle_macro_(src1[x]); \
worktype b0 = _toggle_macro_(src2[x]); \
worktype a1 = _toggle_macro_(src1[x+1]); \
worktype b1 = _toggle_macro_(src2[x+1]); \
a0 = __op__( a0, b0 ); \
a1 = __op__( a1, b1 ); \
dst[x] = (arrtype)_toggle_macro_(a0); \
dst[x+1] = (arrtype)_toggle_macro_(a1); \
a0 = _toggle_macro_(src1[x+2]); \
b0 = _toggle_macro_(src2[x+2]); \
a1 = _toggle_macro_(src1[x+3]); \
b1 = _toggle_macro_(src2[x+3]); \
a0 = __op__( a0, b0 ); \
a1 = __op__( a1, b1 ); \
dst[x+2] = (arrtype)_toggle_macro_(a0); \
dst[x+3] = (arrtype)_toggle_macro_(a1); \
} \
\
for( ; x < size.width; x++ ) \
{ \
worktype a0 = _toggle_macro_(src1[x]); \
worktype b0 = _toggle_macro_(src2[x]); \
a0 = __op__( a0, b0 ); \
dst[x] = (arrtype)_toggle_macro_(a0); \
} \
} \
\
return CV_OK; \
}
#define ICV_DEF_MINMAX_CONST_FUNC( __op__, name, \
flavor, arrtype, worktype, _toggle_macro_) \
static CvStatus CV_STDCALL \
icv##name##C_##flavor##_C1R( const arrtype* src1, int step1,\
arrtype* dst, int step, \
CvSize size, worktype* pScalar)\
{ \
worktype scalar = _toggle_macro_(*pScalar); \
step1 /= sizeof(src1[0]); step /= sizeof(dst[0]); \
\
for( ; size.height--; src1 += step1, dst += step ) \
{ \
int x; \
for( x = 0; x <= size.width - 4; x += 4 ) \
{ \
worktype a0 = _toggle_macro_(src1[x]); \
worktype a1 = _toggle_macro_(src1[x+1]); \
a0 = __op__( a0, scalar ); \
a1 = __op__( a1, scalar ); \
dst[x] = (arrtype)_toggle_macro_(a0); \
dst[x+1] = (arrtype)_toggle_macro_(a1); \
a0 = _toggle_macro_(src1[x+2]); \
a1 = _toggle_macro_(src1[x+3]); \
a0 = __op__( a0, scalar ); \
a1 = __op__( a1, scalar ); \
dst[x+2] = (arrtype)_toggle_macro_(a0); \
dst[x+3] = (arrtype)_toggle_macro_(a1); \
} \
\
for( ; x < size.width; x++ ) \
{ \
worktype a0 = _toggle_macro_(src1[x]); \
a0 = __op__( a0, scalar ); \
dst[x] = (arrtype)_toggle_macro_(a0); \
} \
} \
\
return CV_OK; \
}
#define ICV_DEF_MINMAX_ALL( flavor, arrtype, worktype, \
_toggle_macro_, _min_op_, _max_op_ ) \
ICV_DEF_MINMAX_FUNC( _min_op_, Min, flavor, arrtype, worktype, _toggle_macro_ ) \
ICV_DEF_MINMAX_FUNC( _max_op_, Max, flavor, arrtype, worktype, _toggle_macro_ ) \
ICV_DEF_MINMAX_CONST_FUNC(_min_op_, Min, flavor, arrtype, worktype, _toggle_macro_)\
ICV_DEF_MINMAX_CONST_FUNC(_max_op_, Max, flavor, arrtype, worktype, _toggle_macro_)
ICV_DEF_MINMAX_ALL( 8u, uchar, int, CV_NOP, CV_MIN_8U, CV_MAX_8U )
ICV_DEF_MINMAX_ALL( 16u, ushort, int, CV_NOP, CV_IMIN, CV_IMAX )
ICV_DEF_MINMAX_ALL( 16s, short, int, CV_NOP, CV_IMIN, CV_IMAX )
ICV_DEF_MINMAX_ALL( 32s, int, int, CV_NOP, CV_IMIN, CV_IMAX )
ICV_DEF_MINMAX_ALL( 32f, int, int, CV_TOGGLE_FLT, CV_IMIN, CV_IMAX )
ICV_DEF_MINMAX_ALL( 64f, double, double, CV_NOP, MIN, MAX )
#define icvMin_8s_C1R 0
#define icvMax_8s_C1R 0
#define icvMinC_8s_C1R 0
#define icvMaxC_8s_C1R 0
CV_DEF_INIT_FUNC_TAB_2D( Min, C1R )
CV_DEF_INIT_FUNC_TAB_2D( Max, C1R )
CV_DEF_INIT_FUNC_TAB_2D( MinC, C1R )
CV_DEF_INIT_FUNC_TAB_2D( MaxC, C1R )
/*********************************** cvMin & cvMax **************************************/
static void
icvMinMax( const void* srcarr1, const void* srcarr2,
void* dstarr, int is_max )
{
static CvFuncTable minmax_tab[2];
static int inittab = 0;
CV_FUNCNAME( "icvMinMax" );
__BEGIN__;
int type, coi = 0;
int src1_step, src2_step, dst_step;
CvMat srcstub1, *src1 = (CvMat*)srcarr1;
CvMat srcstub2, *src2 = (CvMat*)srcarr2;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize size;
CvFunc2D_3A func;
if( !inittab )
{
icvInitMinC1RTable( &minmax_tab[0] );
icvInitMaxC1RTable( &minmax_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, "" );
}
if( !CV_ARE_TYPES_EQ( src1, src2 ) ||
!CV_ARE_TYPES_EQ( src1, dst ))
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_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)(minmax_tab[is_max != 0].fn_2d[type]);
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 ));
__END__;
}
CV_IMPL void
cvMin( const void* srcarr1, const void* srcarr2, void* dstarr )
{
icvMinMax( srcarr1, srcarr2, dstarr, 0 );
}
CV_IMPL void
cvMax( const void* srcarr1, const void* srcarr2, void* dstarr )
{
icvMinMax( srcarr1, srcarr2, dstarr, 1 );
}
/********************************* cvMinS / cvMaxS **************************************/
static void
icvMinMaxS( const void* srcarr, double value, void* dstarr, int is_max )
{
static CvFuncTable minmaxs_tab[2];
static int inittab = 0;
CV_FUNCNAME( "icvMinMaxS" );
__BEGIN__;
int type, coi = 0;
int src1_step, dst_step;
CvMat srcstub1, *src1 = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize size;
CvFunc2D_2A1P func;
union
{
int i;
float f;
double d;
}
buf;
if( !inittab )
{
icvInitMinCC1RTable( &minmaxs_tab[0] );
icvInitMaxCC1RTable( &minmaxs_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(dst) )
{
CV_CALL( dst = cvGetMat( dst, &dststub, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
if( !CV_ARE_TYPES_EQ( src1, dst ))
CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );
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);
if( CV_MAT_DEPTH(type) <= CV_32S )
{
buf.i = cvRound(value);
if( CV_MAT_DEPTH(type) == CV_8U )
buf.i = CV_CAST_8U(buf.i);
else if( CV_MAT_DEPTH(type) == CV_8S )
buf.i = CV_CAST_8S(buf.i);
else if( CV_MAT_DEPTH(type) == CV_16U )
buf.i = CV_CAST_16U(buf.i);
else if( CV_MAT_DEPTH(type) == CV_16S )
buf.i = CV_CAST_16S(buf.i);
}
else if( CV_MAT_DEPTH(type) == CV_32F )
buf.f = (float)value;
else
buf.d = value;
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;
}
func = (CvFunc2D_2A1P)(minmaxs_tab[is_max].fn_2d[type]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
if( is_max )
{
if( type == CV_8U && icvThreshold_LT_8u_C1R_p )
{
IPPI_CALL( icvThreshold_LT_8u_C1R_p( src1->data.ptr, src1_step, dst->data.ptr,
dst_step, size, (uchar)buf.i ));
EXIT;
}
else if( type == CV_16S && icvThreshold_LT_16s_C1R_p )
{
IPPI_CALL( icvThreshold_LT_16s_C1R_p( src1->data.s, src1_step, dst->data.s,
dst_step, size, (short)buf.i ));
EXIT;
}
else if( type == CV_32F && icvThreshold_LT_32f_C1R_p )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -