Unable to stream camera feed with OpenCV

Hi, I am trying to stream webcam camera feed to opencv VideoCapture.

I ran the following:
sudo v4l2-ctl -d /dev/video9 --list-formats

and the output is this

Index : 0
Type : Video Capture
Pixel Format: ‘YU12’
Name : Planar YUV 4:2:0

I had followed the commands from this:

but I am getting the following error while starting the gstreamer:

ERROR: Pipeline doesn’t want to pause.
ERROR: from element /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0: Could not initialise Xv output
Additional debug info:
xvimagesink.c(1773): gst_xv_image_sink_open (): /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0:

using this command:
gst-launch-1.0 v4l2src device=/dev/video9 ! video/x-raw,format=NV12,width=640,height=512,framerate=30/1 ! videoconvert ! xvimagesink sync=0

Seems that it failed to create X window. Are you locally logged in, with GUI and X server running ?
What gives:


v4l2-ctl -d /dev/video9 --list-formats-ext

Also note that NV12 format may not be correct, I’d suggest to try I420 instead for YU12.
Also note that the framerate property is not correct in the pipeline, if not just a typo when posting here you would correct it.

I am running the Jetson in headless mode, so there is no display. So, the output of the command:

echo $DISPLAY is

and Output of v4l2-ctl -d /dev/video9 --list-formats-ext is

Index : 0
Type : Video Capture
Pixel Format: ‘YU12’
Name : Planar YUV 4:2:0
Size: Discrete 1152x720
Interval: Discrete 0.033s (30.000 fps)

I changed the format to I420 and now its working. More specifically I changed argument in VideoCapture function to the following:

cap = cv2.VideoCapture("v4l2src device=/dev/video9 ! video/x-raw,format=I420 ! videoconvert ! appsink")

In above line of code, 9 represents index of camera in /dev/video.
Later I encountered the following:

Gtk-WARNING **: cannot open display:

which I fixed it by running the following command in terminal

export DISPLAY=':0'

and now I’m able to stream camera feed. Thank you

Yes it was a typo error while posting it here. I have fixed it now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.