camera_playground.py 600 B

12345678910111213141516171819202122
  1. from picamera2 import Picamera2
  2. import cv2
  3. def main():
  4. picam2 = Picamera2()
  5. picam2.configure(picam2.create_preview_configuration(main={"format": "BGR888", "size": (640, 480)}))
  6. picam2.start()
  7. print("Type 's' to save a still image. Type 'q' to quit.")
  8. while True:
  9. cmd = input("Command [s/q]: ").strip().lower()
  10. if cmd == 's':
  11. frame = picam2.capture_array()
  12. cv2.imwrite("still_image.jpg", frame)
  13. print("Saved still_image.jpg")
  14. elif cmd == 'q':
  15. break
  16. picam2.stop()
  17. if __name__ == "__main__":
  18. main()