RK3568 简单的四路视频输入,一路视频输出代码

import cv2
import time

# 设置目标帧尺寸
target_frame_shape = (160,120)

# 设定摄像头设备
pipeline_mipi = (
    'v4l2src device=/dev/video0 ! '
    'video/x-raw, format=NV12, width=640, height=480, framerate=30/1 ! '
    'videoconvert ! '
    'appsink'
)

# 创建摄像头捕获器
cap_mipi = cv2.VideoCapture(pipeline_mipi, cv2.CAP_GSTREAMER)
cap_usb9 = cv2.VideoCapture('/dev/video9')
cap_usb11 = cv2.VideoCapture('/dev/video11')
cap_usb13 = cv2.VideoCapture('/dev/video13')

# 检查所有摄像头是否成功打开
cams = [cap_usb9, cap_usb11]
all_opened = all(cap.isOpened() for cap in cams)
if not all_opened:
    for i, cap in enumerate(cams):
        if not cap.isOpened():
            print(f"无法打开摄像头: /dev/video{i}")
    exit()

start_time = time.time()
while True:
    frames = []
    for cap in cams:
        ret, frame = cap.read()
        if not ret:
            print(f"读取摄像头帧失败")
            break
        
        # 调整帧尺寸到目标尺寸
        resized_frame = cv2.resize(frame, target_frame_shape, interpolation=cv2.INTER_AREA)
        frames.append(resized_frame)

    # 如果所有摄像头都成功读取了帧,则进行拼接
    if len(frames) == 2:
        # 将前两帧水平拼接
        concatenated_frames = cv2.hconcat([frames[0], frames[1]])
        # 将后两帧水平拼接
        concatenated_frames2 = cv2.hconcat([frames[2], frames[3]])
        # 再将这两部分垂直拼接
        result = cv2.vconcat([concatenated_frames, concatenated_frames2])
        result = cv2.resize(result,target_frame_shape,interpolation=cv2.INTER_AREA)
        cv2.imshow('All_Cameras', result )
    else:
        print("未能获取所有摄像头的帧")

    cv2.waitKey(1)

    # 若运行超过指定时间(例如60秒),则退出循环
    if time.time() - start_time > 60:
        break

# 释放所有摄像头资源
for cap in cams:
    cap.release()

cv2.destroyAllWindows()

代码中间修改过,直接粘贴过来了,实际使用中需要适当修改。

我用的设备:RK3568,3个usb摄像头,1个mipi摄像头

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值