-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpitrix.py
More file actions
47 lines (34 loc) · 1.21 KB
/
pitrix.py
File metadata and controls
47 lines (34 loc) · 1.21 KB
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
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
import time
import picamera
import picamera.array
from PIL import Image
from base import PitrixBase
class Pitrix(PitrixBase):
def __init__(self, *args, **kwargs):
super(Pitrix, self).__init__(*args, **kwargs)
def run(self):
# setup
camera = picamera.PiCamera(0)
stream = picamera.array.PiRGBArray(camera)
camera.resolution = (100,100)
time.sleep(2)
# capture a continuous stream from PiCamera
for frame in camera.capture_continuous(stream, "rgb"):
# truncate the stream so it doesn't overflow the
# image buffer
stream.truncate()
stream.seek(0)
# get frame image and convert it as an array
image = Image.fromarray(frame.array)
# scale the image down to a thumbnail of size set by the
# RGBMatrixOptions
image.thumbnail((self.matrix.width, self.matrix.height), Image.ANTIALIAS)
self.matrix.SetImage(image)
# take a pause...
time.sleep(0.01)
# entrypoint ...
if __name__ == "__main__":
pitrix = Pitrix()
if (not pitrix.bootstrap()):
pitrix.print_help()