zoukankan      html  css  js  c++  java
  • opencv + python 实时获取最新帧

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

    import cv2
    from threading import Thread
    
    
    class ThreadedCamera(object):
        def __init__(self, source=0):
    
            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.frame
            return None
    
    
    if __name__ == '__main__':
        stream_link = "http://livebroadcast.ccwb.cn/live/w1627026956756903.m3u8"
        streamer = ThreadedCamera(stream_link)
    
        while True:
            frame = streamer.grab_frame()
            if frame is not None:
                cv2.imshow("Context", frame)
            cv2.waitKey(1)
    
  • 相关阅读:
    VSCODE极简配置(备份)
    顺时针打印矩阵--剑指offer
    回文链表 leetcode
    E
    E. Kleofáš and the n-thlon
    单调栈板子
    D
    CodeForces 600E Lomsat gelral(线段树合并)
    C# 面试宝典
    JavaScript 火花效果
  • 原文地址:https://www.cnblogs.com/niulang/p/15088612.html
Copyright © 2011-2022 走看看