[Python] How do I give the contours read in opencv to matplotlib for display?

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to read the contours from opencv and transfer it to matplotlib for display. Here is my code.

    What should I do?

    img = cv2.imread('sample.jpeg')
    _, bin_img = cv2.threshold(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), 180, 255,
    cv2.THRESH_BINARY_INV)
    contours, hierarchy = cv2.findContours(bin_img, mode, method)
    plt.contour(contours)


    It throws an error:

    ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (111,) + inhomogeneous part.

    Continue reading...

Compartilhe esta Página