OpenCV2:初中篇 圖像平滑技術-圖像濾波

一.簡介

 常見的圖像濾波的方法:均值濾波  中值濾波  高斯濾波  雙邊濾波ios

 

二.均值濾波

#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;
}
相關文章
相關標籤/搜索