该方法通过基于 cv2.VideoCapture 能够获取视频流入(rtmp/rtsp等)实时帧,能够解决由于图像处理速度不够等原因造成帧堆积的问题。

class ThreadedCamera(object):

def init(self, source=0):

global cap

self.capture = cv2.VideoCapture(source)

self.thread = Thread(target=self.update, args=())

self.thread.daemon = True # 防止主线程挂掉,子线变成程僵尸进程

self.thread.start()

self.status = False

self.frame = None

def update(self):

while True:

if self.capture.isOpened():

(self.status, self.frame) = self.capture.read()

def grab_frame(self):

if self.status:

return (self.status,self.frame)

return (None,None)

streamer = ThreadedCamera(args.video)

while True:#cv.waitKey(1) != 'q':

has_frame, show = streamer.grab_frame()

相关推荐
cnxy18839 分钟前
Python爬虫进阶:反爬虫策略与Selenium自动化完整指南
爬虫·python·selenium
用户8356290780511 小时前
Python 实现 Excel 条件格式自动化
后端·python
深蓝电商API2 小时前
Scrapy管道Pipeline深度解析:多方式数据持久化
爬虫·python·scrapy
噎住佩奇2 小时前
(Win11系统)搭建Python爬虫环境
爬虫·python
basketball6162 小时前
python 的对象序列化
开发语言·python
rgeshfgreh3 小时前
Python流程控制:从条件到循环实战
前端·数据库·python
luoluoal3 小时前
基于python大数据的电影市场预测分析(源码+文档)
python·mysql·django·毕业设计·源码
幻云20103 小时前
Python深度学习:从入门到实战
人工智能·python
EasyGBS3 小时前
EasyGBS算法算力融合架构:GB28181标准平安乡村智能视频监控建设方案设计
架构·音视频
Zoey的笔记本4 小时前
敏捷与稳定并行:Scrum看板+BPM工具选型指南
大数据·前端·数据库·python·低代码