1.cvSmooth函数
函数 cvSmooth 可使用简单模糊、简单无缩放变换的模糊、中值模糊、高斯模糊、双边滤波的不论什么一种方法平滑图像。每一种方法都有自己的特点以及局限。 没有缩放的图像平滑仅支持单通道图像,而且支持8位到16位的转换(与cvSoble和cvaplace相似)和32位浮点数到32位浮点数的变换格式。
简单模糊和高斯模糊支持
1- 或 3-通道, 8-比特 和 32-比特 浮点图像。
这两种方法能够(in-place)方式处理图像。
中值和双向滤波工作于
1- 或 3-通道, 8-位图像,可是不能以 in-place 方式处理图像。
定义原型
void cvSmooth( const CvArr* src, CvArr* dst,int smoothtype=CV_GAUSSIAN,
int param1, int param2, double param3, double param4 );
src:输入图像.
dst:输出图像.
smoothtype平滑方法:
CV_BLUR_NO_SCALE(简单不带尺度变换的模糊) – -对每一个象素的 param1×param2 领域求和。假设邻域大小是变化的,能够事先利用函数 cvIntegral 计算积分图像。
CV_BLUR (simple blur)——对每一个象素param1×param2邻域求和并做尺度变换 1/(param1×param2)。
CV_GAUSSIAN(gaussian blur)——对图像进行核大小为 param1×param2 的高斯卷积。
CV_MEDIAN(median blur)——对图像进行核大小为param1×param1 的中值滤波 (邻域是方的)。
CV_BILATERAL(双向滤波)——应用双向 3×3 滤波,彩色 sigma=param1。空间 sigma=param2.。
2.实例
IplImage* CaptureImg()
{
IplImage* pImg = NULL;
CvCapture* pCam = NULL;pCam = cvCreateCameraCapture(0);
if(NULL == pCam)
{
fprintf(stderr, "Can't init Camera!\n");
return NULL;
}cvSetCaptureProperty(pCam, CV_CAP_PROP_FRAME_WIDTH, 640);
cvSetCaptureProperty(pCam, CV_CAP_PROP_FRAME_HEIGHT,480);pImg = cvQueryFrame(pCam);
if(NULL == pImg)
{
fprintf(stderr, "Can't get one frame\n");
return NULL;
}cvSaveImage("Capture.jpg", pImg, 0);return pImg;
}//图像处理
IplImage* HandleImg(IplImage* pImg)
{
IplImage* pDst = NULL;if(NULL == pImg)
{
printf("The pImg you need handle is NULL!\n");
return NULL;
}pDst = cvCreateImage(cvGetSize(pImg), IPL_DEPTH_8U, 3);
//平滑处理
cvSmooth(pImg, pDst, CV_GAUSSIAN, 5, 5, 0, 0);
cvSaveImage("Smooth.jpg", pDst, 0);return pDst;
}
效果图:
模糊后:
版权声明:本文博客原创文章,博客,未经同意,不得转载。