[Python] OpenCV error: (-215:Assertion failed) size.width>0 && size.height>0 in function...

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to OpenCV and am trying to make a live face tracker on my computer. I seem to be having an issue with my video input (is it not getting any?). I'm on a mac laptop and am trying to use my built-in webcam.

    Error:

    cv2.error: OpenCV(4.3.0) /Users/travis/build/skvark/opencv-
    python/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0
    && size.height>0 in function 'imshow'


    Code:

    import numpy as np
    import cv2

    cap = cv2.VideoCapture(0)

    while True:
    #capture frame by frame
    ret, img = cap.read()
    cv2.imshow('test', img)


    cv2.waitKey(0) & 0xFF
    cv2.destroyAllWindows()
    cap.release()


    I tried to change cv2.VideoCapture(0) to cv2.VideoCapture(1), but that resulted in this error:

    You might be loading two sets of Qt binaries into the same process. Check that all plugins
    are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that
    only one set of binaries are being loaded.
    QObject::moveToThread: Current thread (0x7ff06a82c5d0) is not the object's thread
    (0x7ff06a876c30).
    Cannot move to target thread (0x7ff06a82c5d0)

    Continue reading...

Compartilhe esta Página