OpenCV学习笔记-平滑处理

平滑处理使用的函数为cvSmooth,例题如下:


#include "StdAfx.h"
#include<cv.h>
#include<highgui.h>
#include<stdio.h>
void main()
{

	IplImage* img_src=0;
	IplImage* img_dst=0;
	char* pictureImage=(char*)("guagua.bmp");
	img_src=cvLoadImage(pictureImage,1);
	if(!img_src)
	{
		printf("Could not load image file:%s",pictureImage);
		exit(0);
	}
	img_dst=cvCreateImage(cvGetSize(img_src),IPL_DEPTH_8U,3);

	cvNamedWindow("Original Picture:",CV_WINDOW_AUTOSIZE);
	cvMoveWindow("Original Picture:",100,100);
	cvShowImage("Original Picture:",img_src);

	cvNamedWindow("CV_BLUR:",CV_WINDOW_AUTOSIZE);
	cvMoveWindow("CV_BLUR:",200,100);
	cvSmooth(img_src,img_dst,CV_BLUR,3,3,0,0);
	cvShowImage("CV_BLUR:",img_dst);

	//注意使用CV_BLUR_NO_SCALE时,原始图像和目标图像,
	//他们的类型不能是一致的。
	IplImage* img_dst2=0;
	img_dst2=cvCreateImage(cvGetSize(img_src),IPL_DEPTH_16S,3);
	cvNamedWindow("CV_BLUR_NO_SCALE:",CV_WINDOW_AUTOSIZE);
	cvMoveWindow("CV_BLUR_NO_SCALE:",300,100);
	cvSmooth(img_src,img_dst2,CV_BLUR_NO_SCALE,3,3,0,0);
	cvShowImage("CV_BLUR_NO_SCALE:",img_dst2);

	cvNamedWindow("CV_GAUSSIAN:",CV_WINDOW_AUTOSIZE);
	cvMoveWindow("CV_GAUSSIAN:",400,100);
	cvSmooth(img_src,img_dst,CV_GAUSSIAN,3,3,0,0);
	cvShowImage("CV_GAUSSIAN:",img_dst);

	cvNamedWindow("CV_MEDIAN:",CV_WINDOW_AUTOSIZE);
	cvMoveWindow("CV_MEDIAN:",500,100);
	cvSmooth(img_src,img_dst,CV_MEDIAN,3,3,0,0);
	cvShowImage("CV_MEDIAN:",img_dst);

	//	cvSmooth(pFrameMat,pFrameMat,CV_BILATERAL,3,0,0);//双向滤波
	//参数不对,改成
	//cvSmooth(pFrameMat,pFrameMat,CV_BILATERAL,3,3,11,11);
	//试试,后面两个参数分别代表了位置上和颜色上的sigma值,不能设为0的
	cvNamedWindow("CV_BILATERAL:",CV_WINDOW_AUTOSIZE);
	cvMoveWindow("CV_BILATERAL:",600,100);
	cvSmooth(img_src,img_dst,CV_BILATERAL,3,3,11,11);
	cvShowImage("CV_BILATERAL:",img_dst);

	cvWaitKey(0);
	cvReleaseImage(&img_src);
	cvReleaseImage(&img_dst);
	cvDestroyWindow("Original Picture:");
	cvDestroyWindow("CV_BLUR:");
	cvDestroyWindow("CV_GAUSSIAN:");
	cvDestroyWindow("CV_MEDIAN:");
	cvDestroyWindow("CV_BILATERAL:");
}


运行结果测试图:

OpenCV学习笔记-平滑处理_第1张图片

注意的问题:
1.在使用CV_BLUR_NO_SCALE时,目标图像和原始图像的类型不能一致.

2.在使用CV_BILATERAL时,后两个参数分别代表位置上和颜色上的信息,不能为零.\

仍旧存在问题:

存在溢出,不知原因.

参考文献:

1.学习OpenCV ,于仕祺,刘瑞祯,清华大学出版社.pp.128-134

2.http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=4521&p=50770#p50770

3.http://www.opencv.org.cn/forum/viewtopic.php?p=33338


你可能感兴趣的:(image,File,测试,出版,DST)