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

本文介绍了如何使用Python库在RaspberryPi上,通过Adafruit_SSD1306模块,将视频文件中的每一帧转换为灰度并调整尺寸后显示在128x32的OLED屏幕上,实现视频实时监控的简易系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值