【发布时间】:2019-09-13 15:45:08
【问题描述】:
我正在尝试从 IP 摄像机获取 Python 中的视频流,但出现错误。我正在使用 Pycharm IDE。
import cv2
scheme = '192.168.100.23'
host = scheme
cap = cv2.VideoCapture('http://admin:Ebmacs8485867@'+host+':81/web/admin.html')
while True:
ret, frame = cap.read()
# Place options to overlay on the video here.
# I'll go over that later.
cv2.imshow('Camera', frame)
k = cv2.waitKey(0) & 0xFF
if k == 27: # esc key ends process
cap.release()
break
cv2.destroyAllWindows()
Error:
"E:\Digital Image Processing\python\ReadingAndDisplayingImages\venv\Scripts\python.exe" "E:/Digital Image Processing/python/ReadingAndDisplayingImages/ReadandDisplay.py"
Traceback (most recent call last):
File "E:/Digital Image Processing/python/ReadingAndDisplayingImages/ReadandDisplay.py", line 14, in <module>
cv2.imshow('Camera', frame)
cv2.error: OpenCV(4.0.1) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901)
warning: http://admin:Ebmacs8485867@192.168.100.23:81/web/admin.html (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:902)
【问题讨论】:
-
您尝试检查框架是否为空,可能是空的。
-
您的意思是 cv2.imshow 无法捕获帧?
-
不是 imshow(),而是 cap.read()。
-
该链接是一个网页 (html),您需要 rtsp 链接...这取决于相机的型号。您还应该在循环之前检查
if cap.isOpened(),在ret, frame = cap.read()行之后检查if ret -
我也尝试过 rtsp,它也不起作用
标签: python opencv computer-vision video-streaming rtsp