opencv 在C ++中使用高斯模糊平滑图像
示例
平滑(也称为模糊)是图像处理中最常用的操作之一。
平滑操作最常见的用途是减少图像中的噪点以进行进一步处理。
有许多算法可以执行平滑操作。
我们来看看最常用的过滤器的一个模糊的形象,高斯滤波使用OpenCV的库函数GaussianBlur()。该滤波器专门用于消除图像中的高频噪声。
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv){
Mat image , blurredImage;
//加载图像文件
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
//如果无法加载图像,则报告错误
if(!image.data){
cout<<"Error loading image" << "\n";
return -1;
}
//应用高斯模糊滤镜。
// The Size object determines the size of the filter (the "range" of the blur)
GaussianBlur( image, blurredImage, Size( 9, 9 ), 1.0);
//在命名窗口中显示模糊的图像
imshow("Blurred Image" , blurredImage);
//无限期等待,直到用户按下一个键
waitKey(0);
return 0;
}有关详细的数学定义和其他类型的过滤器,您可以查看原始文档。