• rtsp opencv抽取图片小工具


    import time
    import cv2
    
    
    class CaptView(object):
        def __init__(self, url, name, delay):
            self.url = url
            self.name = name
            self.capture = cv2.VideoCapture(url)
            self.fps = max(int(self.capture.get(cv2.CAP_PROP_FPS) % 100), 0) or 25
            self.delay = delay
            self.frame_count = 0
            self.start_time = time.time()
        def reconnect(self):
            self.capture = cv2.VideoCapture(self.url)
    
        def start_show(self):
            while self.capture.isOpened():
                self.frame_count += 1
                self.capture.grab()
                status, frame = self.capture.retrieve()
                current_time = time.time()
                current_delay = self.frame_count > (current_time - self.start_time - self.delay) * self.fps
                print("起始时间戳:", self.start_time, " 当前时间:", current_time, " 延迟要求:", self.delay, " 当前fps:", self.fps)
                if status and current_delay:
                    self.cv_show(self.name, frame, 1)
                else:
                    self.frame_count = 0
                    self.capture.release()
                    self.reconnect()
                    print("【INFO】重新链接....")
                time.sleep(1 / self.fps)
    
        def cv_show(self, name, image, interval, half=0.25):
            img = cv2.resize(image, (0, 0), fx=half, fy=half)
            cv2.imshow(name, img)
            cv2.waitKey(interval)
            cv2.destroyWindow(name)
    
    if __name__ == '__main__':
        capture = cv2.VideoCapture("rtsp://admin:***@192.***.110.64:554",)
        status, frame = capture.read()
        res = cv2.imencode('.jpg', frame)[1].tofile(r"D:\demo\1.jpg")
    
    
  • 相关阅读:
    apache的源代码编译安装
    python学习笔记(五) 200行实现2048小游戏
    python学习笔记(四) 思考和准备
    python学习笔记(三)高级特性
    python自学笔记(二)
    python自学笔记(一)
    redis 配置和使用(C++)
    汇编基础最后一篇--机器语言指令
    汇编语言学习笔记(六)
    网络编程学习方法和图书推荐
  • 原文地址:https://www.cnblogs.com/xujunkai/p/15602989.html
Copyright © 2020-2023  润新知