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