cvAdaptiveThreshold源代码很奇怪
OpenCV beta 5中的cvAdaptiveThreshold源代码我粗略的看了一下,太简单.算法就是先图象的平滑,均值减去param1 ,static voidicvAdaptiveThreshold_MeanC( const CvMat* src, CvMat* dst, int method, int maxValue,
OpenCV beta 5中的cvAdaptiveThreshold源代码我粗略的看了一下,太简单.
算法就是先图象的平滑,均值减去param1 ,
static void
icvAdaptiveThreshold_MeanC( const CvMat* src, CvMat* dst, int method,
int maxValue, int type, int size, double delta )
{
CvMat* mean = 0;
CV_FUNCNAME( "icvAdaptiveThreshold_MeanC" );
__BEGIN__;
if( size <= 1 || (size&1) == 0 )
CV_ERROR( CV_StsOutOfRange, "Neighborhood size must be >=3 and odd (3, 5, 7, ...)" );
if( maxValue < 0 )
{
CV_CALL( cvSetZero( dst ));
EXIT;
}
CV_CALL( mean=cvCreateMat( src->rows, src->cols, CV_8UC1 ));
CV_CALL( cvSmooth( src, mean, method == CV_ADAPTIVE_THRESH_MEAN_C ?
CV_BLUR : CV_GAUSSIAN, size, size ));
CV_CALL( cvSubS( mean, cvRealScalar( delta ), mean ));
CV_CALL( cvCmp( src, mean, dst, type == CV_THRESH_BINARY ? CV_CMP_GT : CV_CMP_LT ));
if( maxValue < 255 )
CV_CALL( cvAndS( dst, cvScalarAll( maxValue ), dst ));
__END__;
cvReleaseMat( &mean );
}
CV_IMPL void
cvAdaptiveThreshold( const void *srcIm, void *dstIm, double maxValue,
int method, int type, int blockSize, double param1 )
{
CvMat src_stub, dst_stub;
CvMat *src = 0, *dst = 0;
CV_FUNCNAME( "cvAdaptiveThreshold" );
__BEGIN__;
if( type != CV_THRESH_BINARY && type != CV_THRESH_BINARY_INV )
CV_ERROR( CV_StsBadArg, "Only CV_TRESH_BINARY and CV_THRESH_BINARY_INV "
"threshold types are acceptable" );
CV_CALL( src = cvGetMat( srcIm, &src_stub ));
CV_CALL( dst = cvGetMat( dstIm, &dst_stub ));
if( !CV_ARE_CNS_EQ( src, dst ))
CV_ERROR( CV_StsUnmatchedFormats, "" );
if( CV_MAT_TYPE(dst->type) != CV_8UC1 )
CV_ERROR( CV_StsUnsupportedFormat, "" );
if( !CV_ARE_SIZES_EQ( src, dst ) )
CV_ERROR( CV_StsUnmatchedSizes, "" );
switch( method )
{
case CV_ADAPTIVE_THRESH_MEAN_C:
case CV_ADAPTIVE_THRESH_GAUSSIAN_C:
CV_CALL( icvAdaptiveThreshold_MeanC( src, dst, method, cvRound(maxValue),type,
blockSize, param1 ));
break;
default:
CV_ERROR( CV_BADCOEF_ERR, "" );
}
__END__;
}
更多推荐
所有评论(0)