#include <iostream>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <Windows.h>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("C:/Users/hasee-pc/Desktop/girl.jpg");
Mat abs_grad_x, abs_grad_y, dst;
Mat grad_x, grad_y;
imshow("【原始图】sobel边缘检测", src);
Sobel(src,//原图
grad_x,//输出
CV_16S,//图像深度
1,//x方向差分阶数
0,//y方向差分阶数
3,//sobel核大小
1,//计算导数值时可选的缩放因子
1,//可选delta
BORDER_DEFAULT //边界模式
);
convertScaleAbs(grad_x, abs_grad_x);
imshow("【效果图】x方向Sobel", abs_grad_x);
Sobel(src,
grad_y,
CV_16S,
0,
1,
3,
1,
1,
BORDER_DEFAULT
);
convertScaleAbs(grad_y, abs_grad_y);
imshow("【效果图】Y方向Sobel", abs_grad_y);
addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, dst);
imshow("【效果图】整体方向Sobel", dst);
waitKey(0);
return 0;
}