cv2.VideoCapture 跳帧取图

该博客围绕 cv2.VideoCapture 进行跳帧取图操作,虽未给出具体内容,但推测是关于利用此工具实现视频跳帧获取图像的信息技术相关内容。

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

import cv2 # 定义 RTSP 流 URL rtsp_urls = [ "rtsp://admin:xkdz2025@192.168.2.100:554/streaming/channels/1", "rtsp://admin:xkdz2025@192.168.2.150:554/streaming/channels/1", "rtsp://admin:xkdz2025@192.168.2.151:554/streaming/channels/1", "rtsp://admin:xkdz2025@192.168.2.152:554/streaming/channels/1", "rtsp://admin:xkdz2025@192.168.2.153:554/streaming/channels/1", "rtsp://admin:xkdz2025@192.168.2.154:554/streaming/channels/1", "rtsp://admin:xkdz2025@192.168.2.155:554/streaming/channels/1", "rtsp://admin:xkdz2025@192.168.2.156:554/streaming/channels/1" ] # 创建 GStreamer 管道 def create_gst_pipeline(url): return ( f"rtspsrc location={url} protocols=udp latency=0 buffer-mode=0 ! " "rtpjitterbuffer latency=50 !" "rtph264depay ! h264parse ! mppvideodec !" # 使用硬件解码器 "videoconvert n-threads=4 ! " "videoscale ! video/x-raw,width=1280,height=720,framerate=8/1 ! " "queue max-size-buffers=1 leaky=downstream ! " "appsink drop=true sync=false" ) # 打开视频流 caps = [cv2.VideoCapture(create_gst_pipeline(url), cv2.CAP_GSTREAMER) for url in rtsp_urls] # 检查是否成功打开所有流 for i, cap in enumerate(caps): if not cap.isOpened(): print(f"无法打开流: {rtsp_urls[i]}") exit(1) while True: frames = [] for cap in caps: ret, frame = cap.read() if not ret: print("流结束或出错") break frames.append(frame) # 如果未能读到所有帧,跳过本次循环 if len(frames) != len(rtsp_urls): continue # 将多路流拼接为一个画面 if len(frames) == 2: combined = cv2.hconcat(frames) elif len(frames) == 3: top = cv2.hconcat(frames[:2]) combined = cv2.vconcat([top, frames[2]]) elif len(frames) == 8: top = cv2.hconcat(frames[:4]) bottom = cv2.hconcat(frames[4:]) combined = cv2.vconcat([top, bottom]) else: combined = frames[0] # 显示合并后的画面 cv2.namedWindow("Combined", cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_NORMAL) cv2.setWindowProperty("Combined",cv2.WND_PROP_OPENGL,1) cv2.imshow("Combined RTSP Streams", combined) # 按下 'q' 键退出 if cv2.waitKey(1) & 0xFF == ord('q'): break # 释放资源 for cap in caps: if cap.isOpened(): # 显式释放 GStreamer 管道 cap.release() cv2.destroyAllWindows() 上述代码如何变成 多线程架构
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值