Skip to content

Instantly share code, notes, and snippets.

@waveform80
Created June 16, 2017 16:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waveform80/a2621da13b88c3d751e31a15e97695c2 to your computer and use it in GitHub Desktop.
Save waveform80/a2621da13b88c3d751e31a15e97695c2 to your computer and use it in GitHub Desktop.
Faster astro-cam demo
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()
@hijak
Copy link

hijak commented Dec 12, 2019

im trying to stream (m3u8 via http) to the unicorn hd hat how would that work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment