您的位置:首页 > 运维架构

OpenCV InRange函数

2016-03-24 21:36 267 查看
原文地址: http://blog.csdn.net/wendychueng/article/details/7459390
CV_IMPL void

cvInRangeS( const void* srcarr, CvScalar lower, CvScalar upper, void* dstarr )

{

static CvBigFuncTable inrange_tab;

static int inittab = 0;

CV_FUNCNAME( "cvInRangeS" );

__BEGIN__;

int sctype, type, coi = 0;

int src1_step, dst_step;

CvMat srcstub1, *src1 = (CvMat*)srcarr; //矩阵

CvMat dststub, *dst = (CvMat*)dstarr;

CvSize size;

CvInRangeC Func func;

double buf[8];

if( !inittab ) //第一次调用inittab为0

{

icvInitInRangeCRTable( &inrange_tab ); //初始化Table

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_IS_MASK_ARR( dst ))

CV_ERROR( CV_StsUnsupportedFormat, "Destination image should be 8uC1 or 8sC1");

if( !CV_ARE_SIZES_EQ( src1, dst ))

CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );

sctype = type = CV_MAT_TYPE(src1->type); //给出矩阵的类型

if( CV_MAT_DEPTH(sctype) < CV_32S )

sctype = (type & CV_MAT_CN_MASK) | CV_32SC1;

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__;

}

InRangeS

检查数组元素是否在两个数量之间

void cvInRangeS( const CvArr* src, CvScalar lower, CvScalar upper, CvArr* dst );

src

第一个原数组

lower

包括进的下边界.

upper

不包括进的上边界

dst

输出数组必须是 8u 或 8s 类型.

函数 cvInRangeS 检查输入数组元素范围:对于单通道数组:

dst(I)=lower0 <= src(I)0 < upper0

对于双通道数组以此类推:

dst(I)=lower0 <= src(I)0 < upper0 &&

lower1 <= src(I)1 < upper1

如果 src(I) 在范围内dst(I)被设置为 0xff (每一位都是 '1')否则置0 。所有的数组必须有相同的大小(或ROI大小)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: