OpenCV基础课程笔记16自定义线性滤波

代码

#include<iostream>
#include<opencv2/opencv.hpp>
#include<cmath>
using namespace std;
using namespace cv;

int main() {
	Mat src = imread("A:\\专用\\TestForTheCV\\class6丧尸.jpg");
	Mat dst;
	imshow("图片", src);
	Mat xp, yp;

	//Sobel X方向
	Mat kernel_x = (Mat_<int>(3, 3) << -1, 0, 1, -2, 0, 2, -1, 0, 1);
	filter2D(src, xp, -1, kernel_x, Point(-1, -1), 0, 0);

	//Sobel Y方向
	Mat kernel_y = (Mat_<int>(3, 3) << -1, -2, -1, 0, 0, 0, 1, 2, 1);
	filter2D(src, yp, -1, kernel_y, Point(-1, -1), 0, 0);

	imshow("x", xp);
	imshow("y", yp);

	//拉普拉斯算子
	Mat kernel_lapulasi = (Mat_<int>(3, 3) << 0, -1, 0, -1, 4, -1, 0, -1, 0);
	filter2D(src, dst, -1, kernel_lapulasi, Point(-1, -1), 0, 0);
	imshow("拉普拉斯", dst);


	waitKey(0);
	return 0;
}

运行结果

在这里插入图片描述

posted @ 2020-08-27 14:54  爱和九九  阅读(30)  评论(0)    收藏  举报