import cv2 # Set the camera index (0 by default, or use 1, 2, etc. for multiple cameras) camera_index = 0 # Open the camera capture cap = cv2.VideoCapture(camera_index, cv2.CAP_V4L2) # Check if the camera was opened successfully if not cap.isOpened(): print("Failed to open camera") exit() # Set the camera properties (exposure, in this case) cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0.25) # Disable auto exposure cap.set(cv2.CAP_PROP_EXPOSURE, 0.1) # Set exposure value (0.1 seconds in this case) # Read and display frames from the camera while True: # Capture frame-by-frame ret, frame = cap.read() # Check if the frame was captured successfully if not ret: print("Failed to capture frame") break # Display the resulting frame cv2.imshow('Frame', frame) # Check for key press to exit if cv2.waitKey(1) & 0xFF == ord('q'): break # Release the capture and close all windows cap.release() cv2.destroyAllWindows()