API介绍:
void Canny( InputArray image, OutputArray edges,double threshold1,
double threshold2,int apertureSize = 3, bool L2gradient = false );
//InputArray image:输入图像,需要为8bit单通道图像。
//OutputArray edges:输出图像,为相同大小8bit图像。
//threshold1:低阈值。
//threshold2:高阈值。
//apertureSize:sobel算子大小。
//L2gradient:是否用L2计算梯度的方法:sqrt{(dI/dx)^2 + (dI/dy)^2},否则用L1:|dI/dx|+|dI/dy|。
检测步骤:
1.高斯滤波:
边缘检测对噪音非常敏感,所以实现边缘检测的第一步,是使用高斯滤波器对图像中的噪音进行移除。
2.梯度计算:
这里用的sobel算子。sobel算子卷积核如图:
x,y方向的梯度分别为: