[Python] How can I get a segmentation of the cobblestones in this picture?

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I would like to delimit the blocks from the image. at the beginning I change the image to gray and then to a binary (black/white) image.

    After that, I try to find the edges of the blocks in the image. However, there are too many disturbances in that binary image. Those blocks are black and white. I would like the blocks to be completely black. How would you succeed in that or is it dependent on the photography technique?

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    cv2.imshow('Contours', gray)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

    binary = cv2.adaptiveThreshold(gray, 500, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
    cv2.THRESH_BINARY_INV, 11, 2)

    edged = cv2.Canny(gray, 30, 200)
    cv2.waitKey(0)

    contours, hierarchy = cv2.findContours(edged,
    cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)


    cv2.drawContours(img, contours, -1, (0, 255, 0), 3)

    cv2.imshow('Contours', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()




    Black and white image:

    [​IMG]

    Continue reading...

Compartilhe esta Página