Can not use opencv VideoCapture VIDEOIO ERROR

I installed opencv 4.4.1 using this

But I can’t use VideoCapture.

import cv2
a = cv2.VideoCapture(0)
[ WARN:0] global /home/tigerit/opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0] global /home/tigerit/opencv/modules/videoio/src/cap_gstreamer.cpp (886) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /home/tigerit/opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
VIDEOIO ERROR: V4L: can’t open camera by index 0

I’m using a raspberry pi v2 camera, I’m able to run the camera with command

gst-launch-1.0 nvarguscamerasrc sensor_id=0 ! nvoverlaysink

I tried installing v4l-utils, but getting this error:

Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 v4l-utils : Depends: libv4l2rds0 (= 1.14.2-1) but it is not installable
E: Unable to correct problems, you have held broken packages.

Hi @zabiralnabil,

Please, first of all, complete the installation of v4l-utils. You may try install the unmet dependencies:

sudo apt install libv4l2rds0

or with

sudo apt-get update --fix-missing

Then you will need to verify the formats provided by the camera, as you are using a imx219 (raspberry pi v2 camera), the format is probably RG10. Check it out with the following command:

v4l2-ctl --device /dev/video0 --list-formats-ext

As the problem suggests

OpenCV is unable to handle the incoming format from the camera.

If you have built OpenCV with the gstreamer support you can try to open videoCapture with:

a = cv2.VideoCapture(pipeline, cv2.CAP_GSTREAMER)

You can replace ‘pipeline’ with the gstreamer pipeline you want to try, you can verify your working pipeline previously from using it on Python. A good startup point is running the following command in a terminal:

gst-launch-1.0  nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1' ! nvvidconv ! xvimagesink

After that you can use the pipeline but instead of xvimagesink in Python you should replace it for

videoconvert ! appsink


cv2.VideoCapture(0) means opening /dev/video0 through V4L API.

But your sensor is a Bayer sensor, so you cannot process it from opencv. With gstreamer plugin nvarguscamerasrc, it goes thru a bypass to ISP that performs debayering and provides YUV format.

From opencv, you would have to use a gstreamer pipeline with nvarguscamerasrc to do the same, and convert YUV to BGR as expected by opencv :

# C++
a = cv::VideoCapture("nvarguscamerasrc ! nvvidconv ! video/x-raw, format=BGRx' ! videoconvert ! video/x-raw, format=BGR ! appsink", cv::CAP_GSTREAMER);

# Python
a = cv2.VideoCapture("nvarguscamerasrc ! nvvidconv ! video/x-raw, format=BGRx' ! videoconvert ! video/x-raw, format=BGR ! appsink", cv2.CAP_GSTREAMER)
1 Like