1. 原理
有两篇经典论文可供阅读理解细节
2. 实现
想看效果的朋友强烈建议在python环境下直接调用
环境准备:保证这两个包是同一版本
image_vec = cv2.imread(path, cv2.COLOR_BGR2GRAY)
g_blurred = cv2.GaussianBlur(image_vec, (3, 3), 0)
blurred_float = g_blurred.astype(np.float32) / 255.0
edgeDetector = cv2.ximgproc.createStructuredEdgeDetection("model.yml")
edges = edgeDetector.detectEdges(blurred_float) * 255.0
cv2.imwrite(structed_path, edges)
其中,model.yml可以在Github下载https://github.com/opencv/opencv_extra/blob/master/testdata/cv/ximgproc/model.yml.gz
3. 效果
原图:
边缘图: