Моя IP-камера работает нестабильно и случайным образом отключается. Я бы хотел, чтобы мой скрипт мог определить, когда он отключился, и попытаться повторно подключиться несколько раз, вероятно, ожидая 5-10 секунд между попытками. Я пробовал несколько вещей, но ничего не работает.
Это мой основной сценарий, когда ret имеет значение false, сценарий завершается:
#!/usr/local/bin/python3
import cv2
import time
import datetime
print("start time: " + datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"))
cap = cv2.VideoCapture('rtsp://<ip><port>/live0.264')
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Confirm we have a valid image returned
if not ret:
print("disconnected!")
break
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
# Display the resulting frame
cv2.imshow('frame', gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
print("end time: " + time.strftime("%X"))
# When everything is done, release the capture
cap.release()
cv2.destroyAllWindows()
Изменить: я также хотел бы, чтобы сценарий попытался повторно подключиться к камере в случае, если моя сеть временно отключится или что-то в этом роде.
if cv2.waitKey
в проверку While. - person neophlegm   schedule 27.11.2017cv2.VideoCapture()
. Эта функция будет вызываться, когда изcap.read()
вif not ret:
ничего не возвращается - person brewcrazy   schedule 27.11.2017