【代码】jetson+OLED屏幕+显示mp4视频

import cv2

import time

import Adafruit_GPIO.SPI as SPI

import Adafruit_SSD1306

from PIL import Image

Raspberry Pi pin configuration:

RST = 24

DC = 23

SPI_PORT = 0

SPI_DEVICE = 0

128x32 display with hardware I2C:

disp = Adafruit_SSD1306.SSD1306_128_32(rst=None, i2c_bus=1, gpio=1)

Initialize library.

disp.begin()

Clear display.

disp.clear()

disp.display()

Open the video file

cap = cv2.VideoCapture('932592103.mp4')

Check if the video file opened successfully

if not cap.isOpened():

print("Error: Unable to open video file.")

exit()

Read and display each frame

while cap.isOpened():

ret, frame = cap.read()

if not ret:

break

Convert the frame to grayscale

gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

Resize the frame to fit the OLED display

resized_frame = cv2.resize(gray_frame, (disp.width, disp.height))

Convert the frame to PIL Image

pil_image = Image.fromarray(resized_frame).convert('1')

Display image.

disp.image(pil_image)

disp.display()

Delay to control frame rate (adjust as needed)

time.sleep(0.1)

Release the video capture object and close the display

cap.release()

disp.clear()

disp.display()

相关推荐
py小王子4 分钟前
GitHub 文件/文件夹批量上传工具
python·github
小鸡吃米…24 分钟前
TensorFlow——Keras 框架
人工智能·python·tensorflow·keras
懒惰的bit31 分钟前
Python入门学习记录
python·学习
米羊12135 分钟前
Spring 框架漏洞
开发语言·python
二十雨辰38 分钟前
[python]-闭包和装饰器
python
大尚来也1 小时前
Python 调用 Ollama 本地大模型 API 完全指南
开发语言·python
qq_24218863321 小时前
Python 春节贺卡代码
开发语言·python
Lenyiin1 小时前
《LeetCode 顺序刷题》11 -20
java·c++·python·算法·leetcode·lenyiin
Jelena157795857921 小时前
淘宝图搜API接口技术深度解析:从架构设计到工程实践
python·api
瞎某某Blinder10 小时前
DFT学习记录[4] 电子和空穴的有效质量计算全流程
python·学习