如何在OpenCV2 Python中查看视频流 [英] How to view video stream in OpenCV2 python
问题描述
我开始玩Opencv.我在Linux上使用opencv2的python绑定.我编写了一个快速测试程序,但它似乎无限期挂起.
I'm starting to play with Opencv. I am using the python bindings for opencv2 on Linux. I wrote a quick test program but it seems to hang indefinitely.
import cv2
weblink = "http://continuous-video-stream-here"
cv2.namedWindow("video")
vid = cv2.VideoCapture(weblink)
key = -1
while (key < 0):
success, img = vid.read()
cv2.imshow("video", img)
但是它挂在此输出上:
(video:14388): GStreamer-CRITICAL **: gst_caps_unref: assertion `caps != NULL' failed
我也尝试过从urllib2中读取内容:
I have also tried reading from urllib2:
vid = cv2.VideoCapture(urllib2.urlopen(weblink).read())
但是那也不起作用.
我正在使用Opencv 2.4.2,ffmpeg-0.11.2
I am using Opencv 2.4.2, ffmpeg-0.11.2
EDIT :视频供稿使用Realplayer在浏览器中的http上显示视频.
EDIT: The video feed uses realplayer to display the video over http in the browser.
推荐答案
安全编码并测试方法的返回:
Code safely and test the return of the method:
vid = cv2.VideoCapture(weblink)
if not vid:
print("!!! Failed VideoCapture: invalid parameter!")
您使用的地址可能不受OpenCV的支持.
The address you are using is probably not supported by OpenCV.
只要方法可能失败,都应使用相同的做法:
The same practice should be used whenever a method can fail:
while (key < 0):
success, img = vid.read()
if not img:
print("!!! Failed vid.read()")
break
cv2.imshow("video", img)
这篇关于如何在OpenCV2 Python中查看视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!