import cv2 # Create a VideoCapture object cap = cv2.VideoCapture(0) # Check if the camera is opened successfully if not cap.isOpened(): print("Unable to open the camera") exit() # Loop to continuously read frames from the camera while True: # Read a frame from the camera ret, frame = cap.read() # Display the frame cv2.imshow('Camera Test', frame) # Break the loop when 'q' key is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break # Release the VideoCapture object and close the window cap.release() cv2.destroyAllWindows()