diff --git a/python webcam.py b/python webcam.py index b2f2fe7..ea63e0f 100644 --- a/python webcam.py +++ b/python webcam.py @@ -3,6 +3,11 @@ # id of the video capturing device to open. To open default camera using default backend just pass 0. capture = cv2.VideoCapture(0) +# Check if the camera is opened successfully +if not capture.isOpened(): + print("Error: Unable to access the camera.") + exit() + while True: _, frame = capture.read() # We give the Window a name of "Capture from Webcam", and we also give it the frame which is an numpy object.