引用这个类似的问题How to parse mjpeg http stream from ip camera?通过使用 requests
,我能够从 IP 摄像机读取流:
stream = requests.get('http://<user>:<pass>@<addr>:<port>/videostream.cgi', stream=True)
bytez = ''
while True:
bytez += stream.raw.read(16384)
...
它工作得很好,但我想通过使用 cv2.VideoCapture()
而不是请求来实现。
我尝试了以下方式的变体:
cap = cv2.VideoCapture()
cap.open('http://<user>:<pass>@<addr>:<port>/videostream.cgi?.mjpg')
while(True):
ret, frame = cap.read()
...
但除了关于空帧的异常之外什么也得不到。
如何使用cv2.VideoCapture()读取网络摄像头流?
最佳答案
在 cap = cv2.VideoCapture()
行中传递摄像头的位置:
cap = cv2.VideoCapture('http://<user>:<pass>@<addr>:<port>/videostream.cgi?.mjpg')
关于python - 使用 cv2.VideoCapture() 从 IP 摄像机读取流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22654948/