我使用Python和OpenCV将我的程序连接到相机IP。 我尝试将相机连接到VLC工具,它可以显示相机正常。并尝试从 python 连接到相机:
这是我的来源:
import cv2
url = 'rtsp://myuser:[email protected]:port/onvif1?rtsp_transport=udp'
# Open the video stream
cap = cv2.VideoCapture(url)
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# If the frame was not retrieved properly, break the loop
if not ret:
print("Failed to grab frame")
break
# Display the resulting frame
cv2.imshow('Mobile Camera', frame)
# Press 'q' to exit the video stream
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
cap.release()
cv2.destroyAllWindows()
当我运行时发生异常:
cannot open your camera..
如何解决这个问题,谢谢高人
尝试使用 TCP 而不是 UDP。还要确保您安装了 ffmpeg。