Gingerbread House

Neil HaddleyDecember 26, 2023

holiday.py

$ sudo apt-get update

$ sudo apt-get dist-upgrade

$ python -m venv my-env

$ source my-env/bin/activate

$ pip install --upgrade pip setuptools wheel

$ pip install opencv-contrib-python

$ python

>>> import cv2

>>> print(cv2.__version__)

$ pip install --upgrade luma.oled

$ sudo raspi-config

$ curl -o holiday.mp4 https://download-video.akamaized.net/...

$ vi holiday.py

$ python holiday.py

Raspberry Pi Imager

Raspberry Pi Imager

I selected the Micro SD card

I selected the Micro SD card

I clicked YES to include WIFI and logon credentials

I clicked YES to include WIFI and logon credentials

I clicked YES

I clicked YES

SD card was moved from Macbook to Raspberry Pi

SD card was moved from Macbook to Raspberry Pi

I plugged in the Raspberry Pi and used ping to access

I plugged in the Raspberry Pi and used ping to access

I connected to the Raspberry Pi using secure shell (ssh)

I connected to the Raspberry Pi using secure shell (ssh)

I executed $ sudo apt-get update

I executed $ sudo apt-get update

I executed $ sudo apt-get dist-upgrade

I executed $ sudo apt-get dist-upgrade

I created a python environment, activated the environment and ran pip install$ python -m venv my-env$ source my-env/bin/activate$ pip install --upgrade pip setuptools wheel

I created a python environment, activated the environment and ran pip install$ python -m venv my-env$ source my-env/bin/activate$ pip install --upgrade pip setuptools wheel

I ran $ pip install opencv-contrib-pythonI ran import cv2 to ensure that OpenCV was properly installed

I ran $ pip install opencv-contrib-pythonI ran import cv2 to ensure that OpenCV was properly installed

I ran $ pip install --upgrade luma.oledlibrary for the mini oled display

I ran $ pip install --upgrade luma.oledlibrary for the mini oled display

I ran $ sudo raspi-configI selected the Interface Options menu option

I ran $ sudo raspi-configI selected the Interface Options menu option

I selected the I2C menu option

I selected the I2C menu option

I selected Yes

I selected Yes

I selected Ok

I selected Ok

I selected Finish

I selected Finish

I downloaded video file from https://pixabay.com/videos/girl-child-snow-snowflakes-window-191152/

I downloaded video file from https://pixabay.com/videos/girl-child-snow-snowflakes-window-191152/

I created and ran holiday.pyNotice that the cv.imshow("Img", frame) line is commented out

I created and ran holiday.pyNotice that the cv.imshow("Img", frame) line is commented out

I wired up two displays

I wired up two displays

Sweet tooth

Sweet tooth

Edible Leaves

Edible Leaves

Raspberry Pi

Raspberry Pi

Invader Zim

Invader Zim

Traditional

Traditional

Bluey

Bluey

TEXT
1from luma.core.interface.serial import i2c, spi, pcf8574
2from luma.core.interface.parallel import bitbang_6800
3from luma.core.render import canvas
4from luma.oled.device import ssd1306, ssd1309, ssd1325, ssd1331, sh1106, sh1107
5
6from time import sleep
7
8import cv2
9
10# OpenCV follows BGR color convention and PIL follows RGB color convention
11
12# Python Imaging Library
13from PIL import Image
14
15serial = i2c(port=1, address=0x3C)
16device = sh1106(serial)
17
18width =  device.width
19height = device.height
20
21cap = cv2.VideoCapture("holiday.mp4")
22while True:
23    ret, frame = cap.read()
24    if not ret:
25        break
26#    cv2.imshow("Img", frame)
27    
28    color_coverted = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
29    pil_image = Image.fromarray(color_coverted)
30    image_r = pil_image.resize((width,height), Image.LANCZOS) 
31    # Image.BICUBIC is another option
32    image_bw = image_r.convert("1")
33
34    device.display(image_bw)
35
36    key = cv2.waitKey(1)
37    if key == 27:
38        break
39        
40cap.release()
41cv2.destroyAllWindows()