OpenCV2:初中篇 图像平滑技术-图像滤波

一.简介

 常见的图像滤波的方法:均值滤波  中值滤波  高斯滤波  双边滤波

二.均值滤波

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;


int main()
{
    // 读取图像源
    cv::Mat srcImage = cv::imread("a.jpg");

    if (srcImage.empty())
        return -1;

    // 转换为灰度图像
    cv::Mat srcGray;
    cv::cvtColor(srcImage, srcGray, CV_RGB2GRAY);
    cv::imshow("srcGray", srcGray);

    // 均值平滑
    cv::Mat blurDstImage;
    blur(srcGray, blurDstImage, cv::Size(5, 5), cv::Point(-1, -1));
    cv::imshow("blurDstImage", blurDstImage);

    // 写入图像文件
    cv::imwrite("blurDstImage.png", blurDstImage);
    cv::waitKey(0);

    return 0;
}
原文地址:https://www.cnblogs.com/k5bg/p/11224653.html