from picamera2 import Picamera2 import cv2 def main(): picam2 = Picamera2() picam2.configure(picam2.create_preview_configuration(main={"format": "BGR888", "size": (640, 480)})) picam2.start() print("Type 's' to save a still image. Type 'q' to quit.") while True: cmd = input("Command [s/q]: ").strip().lower() if cmd == 's': frame = picam2.capture_array() cv2.imwrite("still_image.jpg", frame) print("Saved still_image.jpg") elif cmd == 'q': break picam2.stop() if __name__ == "__main__": main()