[学习OpenCV攻略][006][平滑图片]

cvCreateImage(图片大小,像素位数,通道数)

创建图片,根据输入的图片大小,各个通道像素点的位数,和通道数。像素点宏IPL_DEPTH_8U

 

cvGetSize(图片)

得到图片的大小信息

 

cvSmooth(输入图片,输出图片,平滑方式,平滑宽,平滑高)

输出经过平滑处理后的图片,平滑方式宏CV_GAUSSIAN

 

#include "cv.h"
#include "highgui.h"

void smooth_example(IplImage *image){
	cvNamedWindow("hello-in", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("hello-out", CV_WINDOW_AUTOSIZE);
	
	cvShowImage("hello-in", image);
	
	IplImage *out = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 3);
	
	cvSmooth(image, out, CV_GAUSSIAN, 5, 5);
	cvSmooth(out, out, CV_GAUSSIAN, 5, 5);
	
	cvShowImage("hello-out", out);
	
	cvReleaseImage(&out);
	
	cvWaitKey(0);
	
	cvDestroyWindow("hello-in");
	cvDestroyWindow("hello-out");
}

int main(int argc, char **argv){
	IplImage *img = cvLoadImage(argv[1]);
	cvNamedWindow("hello", CV_WINDOW_AUTOSIZE);
	cvShowImage("hello", img);
	
	smooth_example(img);
	
	cvReleaseImage(&img);
	cvDestroyWindow("hello");
	
	return 0;
}

 

posted @ 2015-10-28 20:40  盛夏夜  阅读(213)  评论(0编辑  收藏  举报