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

相关推荐
ai_top_trends3 分钟前
2026 年工作计划 PPT 横评:AI 自动生成的优劣分析
人工智能·python·powerpoint
TDengine (老段)12 分钟前
TDengine Python 连接器进阶指南
大数据·数据库·python·物联网·时序数据库·tdengine·涛思数据
brent42337 分钟前
DAY50复习日
开发语言·python
万行1 小时前
机器学习&第三章
人工智能·python·机器学习·数学建模·概率论
Data_agent1 小时前
Cocbuy 模式淘宝 / 1688 代购系统(欧美市场)搭建指南
开发语言·python
m0_726365831 小时前
哈希分分预测系统 打造自适应趋势分析「Python+DeepSeek+PyQt5」
python·qt·哈希算法
vyuvyucd1 小时前
Qwen-1.8B-Chat昇腾Atlas800TA2部署实战
python
轻竹办公PPT1 小时前
2026 年工作计划 PPT 内容拆解,对比不同 AI 生成思路
人工智能·python·powerpoint
癫狂的兔子2 小时前
【Python】【Flask】抽奖功能
开发语言·python·flask
linuxxx1102 小时前
python变量引用的小案例
python