-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhappy_snaps.sh
executable file
·38 lines (34 loc) · 1.11 KB
/
happy_snaps.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/python3
import io
from picamera2 import Picamera2, Preview
from PIL import Image
from sense_hat import SenseHat
from datetime import datetime
cam = Picamera2()
hat = SenseHat()
hat.set_rotation(90)
cam_config = cam.create_preview_configuration()
cam.configure(cam_config)
cam.set_controls({"ExposureTime": 2500})
cam.start_preview(Preview.NULL)
cam.start()
print("for use with sense hat")
while True:
print(".", end="", flush=True)
stream = io.BytesIO()
cam.capture_file(stream, format='jpeg')
stream.seek(0)
image = Image.open(stream)
pixel_img = image.resize((8,8))
for x in range(0,8):
for y in range(0,8):
hat.set_pixel(x,y, pixel_img.getpixel((x,y)))
for evt in hat.stick.get_events():
if (evt.direction == "middle" and evt.action == "pressed"):
exit()
if (evt.direction == "right" and evt.action == "pressed"):
hat.clear()
label = datetime.now().strftime("%Y-%m-%d_%H_%M_%S")
image.save(label+".png", "PNG")
pixel_img.save(label+".tiny.png", "PNG")
print("Image captured...")