我正在使用opencv从DVR读取视频流。代码如下:
import cv2
# DVR
url = 'rtsp://admin:12345@192.168.10.101:8000/h264/ch1/sub/av_stream'
# IPC
url = 'rtsp://admin:xwxa12345@192.168.1.64'
cap = cv2.VideoCapture(url)
assert cap.isOpened(), 'failed to open cap'
while True:
ret, frame = cap.read()
if ret:
cv2.imshow('img', frame)
else:
print('failed to read img')
key = cv2.waitKey(1) & 0xFF
if key == 27:
break
当url为IPC值时,我可以成功读取视频。但是当URL是DVR值时,出现如下错误:
assert cap.isOpened(), 'failed to open cap'
AssertionError: failed to open cap
能否提供更详细的信息? rtsp事情有问题还是VideoCapture的责任?