我正在尝试从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)
rtsp://192.168.100.23:554/11
... 这个链接因型号而异。你正在传递一个HTML网页进行连接。这不是一个流,而是一个网页。有时这个网页通过JavaScript、Flash或其他方式连接到流。 - api55