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

相关推荐
Learner__Q9 分钟前
每天五分钟:二分查找-LeetCode高频题解析_day4
python·算法·leetcode
Darkershadow13 分钟前
Python学习之使用pycharts
开发语言·python
写代码的【黑咖啡】19 分钟前
Python 中的控制流程:掌握程序的逻辑跳转
服务器·javascript·python
Wpa.wk39 分钟前
自动化测试(java) - PO模式了解
java·开发语言·python·测试工具·自动化·po模式
徐先生 @_@|||40 分钟前
Java/Maven 对比 Python/PyPI
开发语言·python
嘻嘻嘻开心1 小时前
Collection接口
linux·windows·python
rebekk1 小时前
什么时候会用到python -m
python
是喵斯特ya1 小时前
python开发web暴力破解工具(进阶篇 包含验证码识别和token的处理)
开发语言·python·web安全
长安牧笛1 小时前
职业技能学习路径规划工具,用户输入目标岗位,如AI工程师,结合现有技能水平,推荐分阶段学习资源(课程/书籍/项目),设置学习进度提醒。
python
老艾的AI世界1 小时前
最新AI幻脸软件,全面升级可直播,Mirage下载介绍(支持cpu)
图像处理·人工智能·深度学习·神经网络·目标检测·ai