
#include <iostream>
#include <filesystem>
#include <string>
#include <windows.h>
#include <opencv2/opencv.hpp>
namespace fs = std::filesystem;
using namespace cv;
using namespace std;
int main()
{
//std::cout << "Hello World!\n";
//fs::path currentPath = fs::current_path();
//string filename = currentPath.string() + "\\jzh.png";
// 图片路径
string file = "F:/opencv/console/x64/Debug/jzh.png";
// 显示原图
Mat src = imread(file);
imshow("src", src);
// 灰度
Mat gray;
cvtColor(src, gray, COLOR_BGR2GRAY);
imshow("gray", gray);
// 边缘检测
/*
image 输入单通道图像(可以是彩色图像)对于多通道的图像可以用cvCvtColor()修改。
edges 输出的边缘图像 ,也是单通道的,但是是黑白的
threshold1 第一个阈值
threshold2 第二个阈值
apertureSize Sobel 算子内核大小
函数 cv::Canny 采用 Canny 算法发现输入图像的边缘而且在输出图像中标识这些边缘。
threshold1和threshold2 当中的小阈值用来控制边缘连接,大的阈值用来控制强边缘的初始分割。
*/
Mat edge;
cv::Canny(gray, edge, 50, 200, 3, false);
imshow("edge", edge);
waitKey(0);
destroyAllWindows();
return 0;
}