Gingerbread House

Neil HaddleyDecember 26, 2023

holiday.py

PythonIOTraspberry-pipythonholidaygpio
BASH
1$ sudo apt-get update
2$ sudo  apt-get dist-upgrade
3
4$ python -m venv my-env
5$ source my-env/bin/activate
6
7$ pip install --upgrade pip setuptools wheel
8$ pip install opencv-contrib-python
9
10$ python
11>>> import cv2
12>>> print(cv2.__version__)
13
14$ pip install --upgrade luma.oled
15$ sudo raspi-config
16
17$ curl -o holiday.mp4 https://download-video.akamaized.net/...
18
19$ vi holiday.py
20$ python holiday.py
I opened Raspberry Pi Imager

I opened 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

I moved the SD card from the MacBook to the Raspberry Pi

I moved the SD card from the MacBook to the 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 it, and ran pip install

I created a Python environment, activated it, and ran pip install

I ran pip install opencv-contrib-python and imported cv2 to verify OpenCV was installed

I ran pip install opencv-contrib-python and imported cv2 to verify OpenCV was installed

I ran pip install --upgrade luma.oled to install the library for the mini OLED display

I ran pip install --upgrade luma.oled to install the library for the mini OLED display

I ran sudo raspi-config and selected the Interface Options menu option

I ran sudo raspi-config and 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.py. I noted that the cv.imshow("Img", frame) line is commented out

I created and ran holiday.py. I noted 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

PYTHON
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()