camera_playground.py 679 B

12345678910111213141516171819202122232425
  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. x, y, w, h = [290, 260, 240, 170]
  8. print("Type 's' to save a still image. Type 'q' to quit.")
  9. while True:
  10. cmd = input("Command [s/q]: ").strip().lower()
  11. if cmd == 's':
  12. frame = picam2.capture_array()
  13. frame = frame[y:y+h, x:x+w]
  14. cv2.imwrite("still_image.jpg", frame)
  15. print("Saved still_image.jpg")
  16. elif cmd == 'q':
  17. break
  18. picam2.stop()
  19. if __name__ == "__main__":
  20. main()