[Python] Why cv.convexityDefects fails in this example? Is it a bug?

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    This script:

    import numpy as np, cv2 as cv

    contour = np.array([[0, 0], [1, 0], [1, 1], [0.5, 0.2], [0, 0]], dtype='f4')
    hull = cv.convexHull(contour, returnPoints=False)
    defects = cv.convexityDefects(contour, hull)


    fails and produces this error message:

    File "/home/paul/upwork/pickleball/code/so-65-ocv-convexity-defects.py", line 5, in <module>
    defects = cv.convexityDefects(contour, hull)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cv2.error: OpenCV(4.11.0) /io/opencv/modules/imgproc/src/convhull.cpp:319: error: (-215:Assertion failed) npoints >= 0 in function 'convexityDefects'


    What is the reason? Here is a plot of contour:

    [​IMG]

    And hull is:

    [[0]
    [1]
    [2]]

    Continue reading...

Compartilhe esta Página