【练习5.3】高斯平滑_调整调整4个参数的处理效果对比
学习OpenCV》中文版第5章第3题
题目要求 |
程序代码 |
结果图片 |
a、设置param1=param2=9,依次将param3设为1和6对比
b、设置param1=param2=0,依次将param3设为1和6对比
c、设置param1=param2=0,但这时令param3=1,param4=9,处理并显示结果
d、令param3=9,param4=1,重复操作c
e、将图像使用c平滑一次,再使用d平滑一次,显示结果
f、对图像依次进行两次平滑操作,第一次参数为param1=param2=0,param3=param4=9,第二次参数为param1=param2=0,param3=param4=0。将结果与e操作的结果进行对比。他们相同吗?为什么?
1 // OpenCVExerciseTesting.cpp : 定义控制台应用程序的入口点。 2 // 3 //D:\\Work\\Work_Programming\\Source\\Image\\lena.jpg 4 5 6 #include "stdafx.h" 7 #include <cv.h> 8 #include <highgui.h> 9 #include <iostream> 10 using namespace cv; 11 using namespace std; 12 //函数声明-->--->-->--->-->--->-->--->// 13 14 15 16 //<--<--<--<--<--<--<--<--<--函数声明// 17 18 int _tmain(int argc, _TCHAR* argv[]) 19 { 20 ////const char * fileName = "D:\\Work\\Work_Programming\\Source\\Image\\Photoshop\\样图.jpg"; 21 22 const char * fileName = "D:\\Work\\Work_Programming\\Source\\Image\\纹理\\纹理_灰度.jpg"; 23 IplImage * img = cvLoadImage(fileName, CV_LOAD_IMAGE_UNCHANGED); 24 assert(img); 25 26 27 //IplImage * img = cvCreateImage(cvSize(100, 100), IPL_DEPTH_8U, 1); 28 //assert(img); 29 //cvZero(img); 30 //cvSetReal2D(img, 49, 49, 255); 31 32 cvNamedWindow("ExerciseWindow", 0); 33 cvNamedWindow("高斯模糊_a_1", 0); 34 cvNamedWindow("高斯模糊_a_6", 0); 35 cvNamedWindow("高斯模糊_b_1", 0); 36 cvNamedWindow("高斯模糊_b_6", 0); 37 cvNamedWindow("高斯模糊_c", 0); 38 cvNamedWindow("高斯模糊_d", 0); 39 cvNamedWindow("高斯模糊_e", 0); 40 cvNamedWindow("高斯模糊_f", 0); 41 42 /*char * imageName = "E:\\Testing\\Image\\ExerciseWindow.jpg"; 43 cvSaveImage(imageName, img);*/ 44 cvShowImage("ExerciseWindow", img); 45 46 47 //---------------------------a:开始--------------------------------// 48 49 IplImage * image_Gauss_a = cvCloneImage(img); 50 cvZero(image_Gauss_a); 51 52 cvSmooth(img, image_Gauss_a, CV_GAUSSIAN, 9, 9, 1); 53 cvShowImage("高斯模糊_a_1", image_Gauss_a); 54 55 cvZero(image_Gauss_a); 56 cvSmooth(img, image_Gauss_a, CV_GAUSSIAN, 9, 9, 6); 57 cvShowImage("高斯模糊_a_6", image_Gauss_a); 58 59 60 //---------------------------a:结束--------------------------------// 61 62 63 //---------------------------b:开始--------------------------------// 64 65 IplImage * image_Gauss_b = cvCloneImage(img); 66 cvZero(image_Gauss_b); 67 68 cvSmooth(img, image_Gauss_b, CV_GAUSSIAN, 0, 0, 1); 69 cvShowImage("高斯模糊_b_1", image_Gauss_b); 70 71 cvZero(image_Gauss_b); 72 cvSmooth(img, image_Gauss_b, CV_GAUSSIAN, 0, 0, 6); 73 cvShowImage("高斯模糊_b_6", image_Gauss_b); 74 75 //---------------------------b:结束--------------------------------// 76 77 //---------------------------c:开始--------------------------------// 78 79 IplImage * image_Gauss_c = cvCloneImage(img); 80 cvZero(image_Gauss_c); 81 82 cvSmooth(img, image_Gauss_c, CV_GAUSSIAN, 0, 0, 1,9); 83 84 cvShowImage("高斯模糊_c", image_Gauss_c); 85 86 87 //---------------------------c:结束--------------------------------// 88 89 //---------------------------d:开始--------------------------------// 90 91 IplImage * image_Gauss_d = cvCloneImage(img); 92 cvZero(image_Gauss_d); 93 94 cvSmooth(img, image_Gauss_d, CV_GAUSSIAN, 0, 0, 9, 1); 95 96 cvShowImage("高斯模糊_d", image_Gauss_d); 97 98 99 //---------------------------d:结束--------------------------------// 100 101 //---------------------------e:开始--------------------------------// 102 103 IplImage * image_Gauss_e = cvCloneImage(img); 104 cvZero(image_Gauss_e); 105 106 cvSmooth(img, image_Gauss_e, CV_GAUSSIAN, 0, 0, 1, 9); 107 cvSmooth(image_Gauss_e, image_Gauss_e, CV_GAUSSIAN, 0, 0, 9, 1); 108 109 cvShowImage("高斯模糊_e", image_Gauss_e); 110 111 112 //---------------------------e:结束--------------------------------// 113 114 //---------------------------f:开始--------------------------------// 115 116 IplImage * image_Gauss_f = cvCloneImage(img); 117 cvZero(image_Gauss_f); 118 119 cvSmooth(img, image_Gauss_f, CV_GAUSSIAN, 0, 0, 9, 9); 120 //param3和4不能设置为0,,报错 121 cvSmooth(image_Gauss_f, image_Gauss_f, CV_GAUSSIAN, 0, 0, 1, 1); 122 123 cvShowImage("高斯模糊_f", image_Gauss_f); 124 125 126 //---------------------------f:结束--------------------------------// 127 128 cvWaitKey(0); 129 130 cvReleaseImage(&img); 131 cvReleaseImage(&image_Gauss_a); 132 cvReleaseImage(&image_Gauss_b); 133 cvReleaseImage(&image_Gauss_c); 134 cvReleaseImage(&image_Gauss_d); 135 cvReleaseImage(&image_Gauss_e); 136 cvReleaseImage(&image_Gauss_f); 137 138 cvDestroyWindow("ExerciseWindow"); 139 cvDestroyWindow("高斯模糊_a_1"); 140 cvDestroyWindow("高斯模糊_a_6"); 141 cvDestroyWindow("高斯模糊_b_1"); 142 cvDestroyWindow("高斯模糊_b_6"); 143 cvDestroyWindow("高斯模糊_c"); 144 cvDestroyWindow("高斯模糊_d"); 145 cvDestroyWindow("高斯模糊_e"); 146 cvDestroyWindow("高斯模糊_f"); 147 148 149 return 0; 150 } 151
‖==========钟于原创 乐于分享 宁静致远 毋忆典藏==========‖