首页 > 解决方案 > 如何通过线条链接找到的形状边缘?

问题描述

我有一个 Python 脚本,可以检测图片上的形状边缘。我需要逐行链接这些边缘。有没有人对如何做到这一点有任何建议,或者如何找到形状边缘然后链接它们的更好方法?

提前致谢。

def dstf(path):
    img = image(path)
    (H, W) = img.shape[:2]
    blob = cv2.dnn.blobFromImage(img, scalefactor = 1.0, size = (W, H),
    mean=(104.00698793, 116.66876762, 122.67891434),
    swapRB = False, crop = False)
    net.setInput(blob)

    hed = net.forward()
    hed = cv2.resize(hed[0, 0], (W, H))
    hed = (255 * hed).astype("uint8")

    dst = cv2.cornerHarris(np.float32(hed), 2, 3, 0.04)
    dst = cv2.dilate(dst, None)

    img[dst > 0.01 * dst.max()] = [0, 0, 255]

    return img

发现边缘:

发现边缘

原来的:

原来的

标签: pythonopencv

解决方案


推荐阅读