该方法通过基于 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()

相关推荐
ZhengEnCi27 分钟前
M3-markconv库找不到wkhtmltopdf问题
python
2301_764441333 小时前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
chushiyunen4 小时前
python rest请求、requests
开发语言·python
cTz6FE7gA4 小时前
Python异步编程:从协程到Asyncio的底层揭秘
python
baidu_huihui4 小时前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip
南 阳4 小时前
Python从入门到精通day63
开发语言·python
lbb 小魔仙4 小时前
Python_RAG知识库问答系统实战指南
开发语言·python
FreakStudio5 小时前
MicroPython LVGL基础知识和概念:底层渲染与性能优化
python·单片机·嵌入式·电子diy
素玥5 小时前
实训5 python连接mysql数据库
数据库·python·mysql