Gstreamer Critical Error When Trying To Capture Video Using Webcam Python Opencv
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():
Solution 1:
The following workaround has a reasonable chance of working:
cap = cv2.VideoCapture(0, cv2.CAP_V4L)
The ability to select backends was added in OpenCV 3, see the VideoCapture()
docs.
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
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(ver2.2.4)FFMPEG:YESavcodec:YES(ver56.60.100)avformat:YES(ver56.40.101)avutil:YES(ver54.31.100)swscale:YES(ver3.1.101)avresample:NOGStreamer:base:YES(ver1.8.3)video:YES(ver1.8.3)app:YES(ver1.8.3)riff:YES(ver1.8.3)pbutils:YES(ver1.8.3)libv4l/libv4l2:NOv4l/v4l2:linux/videodev2.h
Post a Comment for "Gstreamer Critical Error When Trying To Capture Video Using Webcam Python Opencv"