Created
June 16, 2017 16:42
-
-
Save waveform80/a2621da13b88c3d751e31a15e97695c2 to your computer and use it in GitHub Desktop.
Faster astro-cam demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from picamera import PiCamera | |
from sense_hat import SenseHat | |
from PIL import Image | |
from signal import pause | |
class DisplayOutput(): | |
def __init__(self): | |
self.hat = SenseHat() | |
def write(self, buf): | |
# buf is a frame of RGB data bytes format; just need to dissect it into | |
# the format SenseHat requires [(R, G, B), (R, G, B), ...]. However, we | |
# can't resize smaller than 32x16 using the ISP so we'll handle resizing | |
# to 8x8 with PIL first... | |
img = Image.frombytes('RGB', (64, 64), buf) | |
img = img.resize((8, 8)) | |
buf = img.tobytes() | |
self.hat.set_pixels([ | |
buf[i:i + 3] for i in range(0, len(buf), 3) | |
]) | |
with PiCamera() as camera: | |
camera.resolution = (64, 64) | |
camera.start_preview() | |
output = DisplayOutput() | |
camera.start_recording(output, 'rgb') | |
try: | |
pause() | |
finally: | |
camera.stop_recording() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
im trying to stream (m3u8 via http) to the unicorn hd hat how would that work?