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

Jade·2022년 4월 29일
0
import cv2

vid = cv2.VideoCapture(0)

while True:
    ret, frame = vid.read()

    cv2.imshow("frame", frame)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

vid.release()
cv2.destroyAllWindows()

위 코드를 실행 시켰더니 아래와 같은 에러가 출력 되었다.

cv2.error: OpenCV(4.5.5) /Users/runner/work/opencv-python/opencv-python/opencv/modules/highgui/src/window.cpp:1000: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

vid = cv2.VideoCapture(0)를 vid = cv2.VideoCapture(1)로 수정하였더니 해결.
stackoverflow 첫번째 답변과는 반대지만 어쨌든 작동!

profile
우당탕탕 좌충우돌 인프라 여행기

0개의 댓글