尝试使用网络摄像头python opencv捕获视频时gstreamer严重错误 [英] gstreamer critical error when trying to capture video using webcam python opencv
问题描述
我正在尝试使用带有简单代码的opencv和python使用网络摄像头拍摄视频
i'm trying to take a video with webcam using opencv and python with a simple code
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
print('cap.isOpened')
if cap.isOpened():
print ('cap is opened')
while(True):
re,img=cap.read()
cv2.imshow("video output", img)
k = cv2.waitKey(10)&0xFF
if k==27:
break
cap.release()
cv2.destroyAllWindows()
如果我尝试播放现有视频(例如.mp4文件),效果很好.但是当我尝试使用网络摄像头时出现错误
it's working fine if i try to play an existing video such as .mp4 file. but when i try using a webcam i got an error
GStreamer-CRITICAL **:gst_element_get_state:断言"GST_IS_ELEMENT(元素)"失败 cap.isOpened
GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed cap.isOpened
有关更多信息,我将odroid xu4与ubuntu 16.04一起使用,网络摄像头我使用logitech c170(它在webcamtest和guvcview中正常工作)以为在奶酪和camorama上不起作用.
for more information i'm using odroid xu4 with ubuntu 16.04, webcam i use logitech c170 ( it work properly in webcamtest and using guvcview) thought it doesn't workon cheese and camorama.
需要对此的帮助..
推荐答案
以下解决方法具有合理的工作机会:
The following workaround has a reasonable chance of working:
cap = cv2.VideoCapture(0, cv2.CAP_V4L)
OpenCV 3中增加了选择后端的功能,请参见VideoCapture()
文档.
The ability to select backends was added in OpenCV 3, see the VideoCapture()
docs.
该解决方法将OpenCV 3.4.4构建的后端切换到 V4L (来自默认GStreamer),并在16.04机器上支持GStreamer.这是问题代码的输出以及export OPENCV_VIDEOIO_DEBUG=TRUE
之后的解决方法:
The workaround switches the backend to V4L (from default GStreamer) for my OpenCV 3.4.4 build with GStreamer support on a 16.04 box. Here the output of the question's code with workaround after export OPENCV_VIDEOIO_DEBUG=TRUE
:
[ WARN:0] VIDEOIO(cvCreateCameraCapture_V4L(index)): trying ...
[ WARN:0] VIDEOIO(cvCreateCameraCapture_V4L(index)): result=0x20b1470 ...
cap.isOpened
cap is opened
如果解决方法不适合您,则可以使用print(cv2.getBuildInformation())
检查您的OpenCV版本是否支持V4L
.这里是我构建的相关部分:
If the workaround does not work for you, you can check whether your OpenCV build supports V4L
using print(cv2.getBuildInformation())
. Here the relevant section for my build:
Video I/O:
DC1394: YES (ver 2.2.4)
FFMPEG: YES
avcodec: YES (ver 56.60.100)
avformat: YES (ver 56.40.101)
avutil: YES (ver 54.31.100)
swscale: YES (ver 3.1.101)
avresample: NO
GStreamer:
base: YES (ver 1.8.3)
video: YES (ver 1.8.3)
app: YES (ver 1.8.3)
riff: YES (ver 1.8.3)
pbutils: YES (ver 1.8.3)
libv4l/libv4l2: NO
v4l/v4l2: linux/videodev2.h
这篇关于尝试使用网络摄像头python opencv捕获视频时gstreamer严重错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!