最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Edge detection: problem about the size of target - Stack Overflow

programmeradmin1浏览0评论

I would like to make a detection of some blackspots of a surface I have. But after trying to detect contours, I capture small blackspots (you can see them in the output as little white points) and not the biggers ones as needed too. The advantage of this algorithm is that it does not detect the contours of the frame as it may happen with some images I have. But still, I have to detect the big blackspots too. Can someone help me please how to rectify to detect all the blackspots ? Here is a snippet of my solution:

for idx, im, path in zip(range(len(images)), images, paths):  # (786, 1044)

    # apply thresholding
    _, binary_global = cv2.threshold(im, 127, 255, cv2.THRESH_BINARY)

    mask = np.zeros(im.shape, dtype=im.dtype)
    cont = cv2.findContours(binary_global, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    cont = cont[0] if len(cont) == 2 else cont[1]
    # print(cont)

    for c in cont:
        area = cv2.contourArea(c)
        if area < 500:
            cv2.drawContours(mask, [c], -1, (255, 255, 255), -1)
    print(mask.shape)

    removed_border = cv2.bitwise_and(im, im, mask=mask)

    cv2.imshow("Result", removed_border)
    cv2.waitKey(0)

发布评论

评论列表(0)

  1. 暂无评论