调用两个API,一个是均值模糊,一个是高斯模糊。如下所示:
#include<opencv2/opencv.hpp> #include<iostream> using namespace std; using namespace cv; int main(int argc, char **argv) { Mat src = imread("D:/meinv.jpg"); cvNamedWindow("src_image", CV_WINDOW_AUTOSIZE); imshow("src_image", src); //均值滤波 Mat dst; blur(src, dst, Size(5, 5), Point(-1, -1)); //size(5,5)为5*5的模板,Point(-1,-1)默认卷积核在中心像素位置 //blur(src, dst, Size(1, 71), Point(-1, -1)); //y方向的模糊 //blur(src, dst, Size(71, 1), Point(-1, -1)); //x方向的模糊 imshow("blur_demo", dst); imwrite("D:/learn-opencv/blur.jpg", dst); //高斯滤波 Mat dst2; GaussianBlur(src, dst2, Size(5, 5), 11, 11); imshow("gaussian_demo", dst2); imwrite("D:/learn-opencv/gaussian.jpg", dst2); waitKey(0); return 0; }
显示结果:
(1)原图像
(2)均值模糊(5*5)模板
(3) x方向的均值模糊:
(4)y方向的均值模糊
(4)高斯模糊