边缘检测一般步骤:
1、滤波:这里推荐使用高斯滤波
2、增强:增强算法可将灰度图点邻域强度值有显著变化的点凸显出来。可用形态学梯度来计算图像的梯度
3、检测:可用canny、sobel、Laplacian算子进行边缘检测
Canny算子
canny边缘检测步骤:
1、原图-------->灰度图
2、高斯滤波
3、canny边缘检测
#include
#include
#include
#include
using namespace cv;
using namespace std;
int main()
{
Mat src=imread("1.jpg");
Mat src_gray,dst;
imshow("原图",src);
cvtColor(src,src_gray,COLOR_RGB2GRAY);
GaussianBlur(src_gray,dst,Size(5,5),10,10);
Canny(dst,dst,100,300,3);
imshow("效果图",dst);
waitKey(0);
return 0;
}
cann函数解析:
Canny(dst,dst,100,300,3);
若某一像素值超过高阈值,该像素被保留为边缘像素;若某一像素值小于低阈值,该像素被排除;若某一像素值在两个阈值之间,该像素仅仅在连接到一个高于高阈值的像素时被保留。