admin管理员组

文章数量:1388835

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)

本文标签: pythonEdge detection problem about the size of targetStack Overflow