python opencv2视频捕获

时间:2019-04-01 09:11:36

标签: python-3.x windows opencv ip-camera

当我尝试流ipcam时,出现如下图所示的错误

  

“ [tcp @ 000000000048c640] uri中缺少端口   警告:打开文件时出错(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901)“

import numpy as np
import cv2
cv2.__file__
cap = cv2.VideoCapture('http://admin:password@http://192.168.1.***/')
#cap = cv2.VideoCapture('https://www.youtube.com/watch?v=Mus_vwhTCq0')

while(True):

    ret, frame = cap.read()
    try:
     cv2.resizeWindow('Stream IP Camera OpenCV', 120300, 800)
     cv2.imshow('Stream IP Camera OpenCV',frame)
    except  Exception as ex:
        template = "An exception of type {0} occurred. Arguments:\n{1!r}"
        message = template.format(type(ex).__name__, ex.args)
        print  (message)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

2 个答案:

答案 0 :(得分:0)

首先打开VLC播放器,并确保您的ipcam流链接正常工作。如果可行,我们现在可以检查OpenCV是否可以使用isOpened()连接到摄像机并检查帧检索状态:

while True:
    if cap.isOpened():
        ret, frame = cap.read()
        if ret:
            # Process here

答案 1 :(得分:0)

首先要使该网址在VLC中工作。尝试使用this website以获得适用于您的相机的有效链接/端口/用户/密码组合。