//文中存在两种不同的图像的平滑类型。一类是彩色图像,还有一类是灰度图像。经证明,两种均能够 #include<cv.h> #include<highgui.h> #include<cxcore.h> int param1=1; int param2=1; IplImage *img; IplImage *image; IplImage *dst; void switch_callback(int position) { int m_param1=param1*2+1; int m_param2=param2*2+1; //掩膜大小必须为大于等于1的奇数 // cvSmooth(image,dst,CV_GAUSSIAN,m_param1,m_param2); cvSmooth(img,dst,CV_GAUSSIAN,m_param1,m_param2); cvShowImage("Smooth Demo",dst); } void main() { img=cvLoadImage("2.bmp",1); //image=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); //此处为进行灰度图像的转化。再对于灰度图像进行高斯平滑 // dst=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); //cvCvtColor(img,image,CV_BGR2GRAY); dst=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3); //直接对于彩色图像进行图像的高斯平滑 cvNamedWindow("Smooth Demo",1); cvCreateTrackbar("Param1","Smooth Demo",¶m1,99,switch_callback); cvCreateTrackbar("Param2","Smooth Demo",¶m2,99,switch_callback); while(1) { if(cvWaitKey(15)==27) break; } cvReleaseImage(&img); cvReleaseImage(&image); cvReleaseImage(&dst); cvDestroyWindow("Smooth Demo"); }