赞
踩
from utils.datasets import IMG_FORMATS, VID_FORMATS, LoadImages, LoadStreams
detesets下的LoadStreams,中,update方法,改为
while True: print('detesets start video') # Read stream `i` frames in daemon thread n, f, read = 0, self.frames[i], 1 # frame number, frame array, inference every 'read' frame # print(stream,'stream') # cap.open('rtsp://127.0.0.1:8554/video') cap.open(stream) time.sleep(10) while cap.isOpened() and n < f: n += 2 # _, self.imgs[index] = cap.read() for tt in range(jump_frame): cap.grab() if n % read == 0: success, im = cap.retrieve() if success: self.imgs[i] = im else: LOGGER.warning(f'WARNING: Video stream unresponsive, please check your IP camera connection.{time.time()}') self.imgs[i] = np.zeros_like(self.imgs[i]) cap.open(stream) # re-open stream if signal was lost time.sleep(1 / self.fps[i]) # wait time
原官方程序中重连代码,cap.open(stream)只连接一次,若失败便不再连接,改为一直连接,因为调用是多线程,所以不用担心。
若更改之后仍不行,将stream改为推流的url地址,两个print一下是一样的,但是不知道为什么在连接上有差别。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。