[Python] What's the format for pts in openCV polylines?

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to draw polygons using cv.polyline, I am getting this bizzar error when doing so. Here's the output


    Points: [[[232 237]]

    [[259 247]]
    .
    .
    .
    [[214 365]]

    [[211 360]]

    [[217 321]]

    [[224 306]]

    [[224 295]]

    [[221 263]]

    [[221 257]]], type:<class 'numpy.ndarray'>, shape:(19, 1, 2)

    ---------------------------------------------------------------------------
    error Traceback (most recent call last)
    Cell In[4], line 32
    28 color = colors[label]
    30 print(f" Points: {pts}, type:{type(pts)}, shape:{pts.shape}")
    ---> 32 cv2.polylines(image, [pts],isClosed=True, color= color, thickness=2)
    34 overlay = image.copy()
    35 cv2.polylines(overlay, [pts], isClosed=True,color=color, thickness=-1)

    error: OpenCV(4.11.0) :-1: error: (-5:Bad argument) in function 'polylines'
    > Overload resolution failed:
    > - Can't parse 'pts'. Sequence item with index 0 has a wrong type
    > - Can't parse 'pts'. Sequence item with index 0 has a wrong type


    I have looked into the documentation and tried to use chatGPt to diagnose the issues but I am unable to do so. Truth be told I don't understant what's wrong with it. I have tried to use previous version i.e, ver 4.10 instead of 4.11 but i still get the same error.

    Continue reading...

Compartilhe esta Página