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

相关推荐
程序员的世界你不懂20 分钟前
Appium+python自动化(十)- 元素定位
python·appium·自动化
神探小白牙1 小时前
vue-video-player视频保活成功确无法推送问题
前端·vue.js·音视频
CryptoPP1 小时前
使用WebSocket实时获取印度股票数据源(无调用次数限制)实战
后端·python·websocket·网络协议·区块链
树叶@1 小时前
Python数据分析7
开发语言·python
老胖闲聊2 小时前
Python Rio 【图像处理】库简介
开发语言·图像处理·python
码界奇点2 小时前
Python Flask文件处理与异常处理实战指南
开发语言·python·自然语言处理·flask·python3.11
浠寒AI3 小时前
智能体模式篇(上)- 深入 ReAct:LangGraph构建能自主思考与行动的 AI
人工智能·python
行云流水剑4 小时前
【学习记录】如何使用 Python 提取 PDF 文件中的内容
python·学习·pdf
心扬4 小时前
python生成器
开发语言·python
mouseliu4 小时前
python之二:docker部署项目
前端·python