opencv4学习总结-自定义滤波

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;


int main()
{
    Mat src = imread("E:/opencv_source/opencv_tutorial_data-master/images/home.jpg");
    imshow("src", src);
    //均值卷积
    int k = 15;
    Mat mkernel = Mat::ones(k, k, CV_32F) / (float)(k * k);
    Mat dst;
    filter2D(src, dst, -1, mkernel, Point(-1, -1), 0, BORDER_DEFAULT);
    imshow("mean filter", dst);

    //非均值滤波
    Mat robot = (Mat_<int>(2, 2) << 1, 0, 0, -1);

    Mat result;
    filter2D(src, result, -1, robot, Point(-1, -1), 0, BORDER_DEFAULT);
    imshow("robot filter", result);

    waitKey(0);
    destroyAllWindows();

    return 0;
}