代码
#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;
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);
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;
}
运行结果
