photobooth/pi.py

49 lines
986 B
Python

#!/usr/bin/python3
import cv2
from gpiozero import LED, Button
from picamera2 import Picamera2
from time import sleep
red = LED(19)
blue = LED(26)
green = LED(13)
button = Button(5)
# Grab images as numpy arrays and leave everything else to OpenCV.
x = 1920
y = 1080
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
#cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.resizeWindow("window", x, y)
picam2 = Picamera2()
capture_config = picam2.create_preview_configuration(main={"size": (x, y),
"format": "RGB888"})
picam2.configure(capture_config)
picam2.start()
while True:
while True:
im = picam2.capture_array()
cv2.imshow("window", im)
if cv2.waitKey(40) & 0xFF == ord('a') or button.value:
break
while button.value:
pass
while not button.value:
sleep(0.1)
while not button.value:
pass
sleep(1)