import cv2 def main(): cap = cv2.VideoCapture(0) if not cap.isOpened(): print("Cannot open camera") return print("Press 's' to save a still image. Press 'q' to quit.") while True: ret, frame = cap.read() if not ret: print("Can't receive frame (stream end?). Exiting ...") break cv2.imshow('Camera', frame) key = cv2.waitKey(1) & 0xFF if key == ord('s'): cv2.imwrite('still_image.jpg', frame) print("Image saved as still_image.jpg") elif key == ord('q'): break cap.release() cv2.destroyAllWindows() if __name__ == "__main__": main()