Created
February 5, 2024 21:07
-
-
Save bmidgley/c54cbf9bce75a85478010dd9de4c7b41 to your computer and use it in GitHub Desktop.
display pi camera video on oled
This file contains hidden or 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
#!/usr/bin/env python3 | |
import cv2 | |
import io | |
import time | |
import picamera | |
import Adafruit_SSD1306 | |
import numpy as np | |
from Adafruit_GPIO import SPI | |
from PIL import Image | |
RST = 24 | |
DC = 23 | |
SPI_PORT = 0 | |
SPI_DEVICE = 0 | |
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000)) | |
disp.begin() | |
disp.clear() | |
disp.display() | |
def process(image): | |
image = Image.fromarray(image).convert('1').transpose(Image.FLIP_LEFT_RIGHT) | |
disp.image(image) | |
disp.display() | |
return(False) | |
with picamera.PiCamera() as camera: | |
camera.resolution = (128, 64) | |
image = np.empty((64, 128, 3), dtype=np.uint8) | |
while True: | |
camera.capture(image, format='bgr') | |
if process(image): | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment