opencv中提供了canny函数来计算图像边缘,详细介绍如下:
void Canny(InputArray image, OutputArry edges, double threshold1, doublethreshold2, int apertureSize=3, bool L2gradient=false)
函数解析:
Image为输入图像,单通道为8bit;edges为输入图像,与输入同类型同尺寸;threshold1为第一滞后过程阈值;threshold2为第二滞后过程阈值;apetureSize为索贝尔操作此存因子。L2gradient为标志位,表示是否使用L2范数来计算图像梯度大小。
代码如下:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include <