0

I want to setup OpenCV and open my webcam, I am following a youtube tutorial but with the same code I got the following errors. I tried changing the index number from 0 to another number.

I'm using a Mac, Python version 3.8.5, cv2 version 4.5.5

The error message:

File "/Users/name/PycharmProjects/name/main.py", line 9, in <module> cv2.imshow ("image", img)
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'

2022-02-22 23:39:11.573 Python[51866:1110380] MyPlugTeardown
2022-02-22 23:39:11.573 Python[51866:1110380] MyPlugTeardown
import cv2

cap = cv2.VideoCapture(0)
cap.set (3,1280)
cap.set (4,720)

while True:
    success, img = cap.read()
    cv2.imshow ("Image", img)
    cv2.waitKey(1)

I also got the exact same error message when trying this tutorial from GeeksforGeeks: https://www.geeksforgeeks.org/python-opencv-capture-video-from-camera/

Thank you

Problem solved! Thank you so much @ eyllanesc! for Mac users also remember to replace 0 with a different index, 2 worked for me (not sure why)

LINDAAA
  • 36
  • 3

0 Answers0