OpenCV2 VideoCapture issues

Using cv2 in Python. Version 4.1.1.

ls -ltrh /dev/video* lists:

crw-rw----+ 1 root video 81, 1 Mar 12 14:19 /dev/video1
crw-rw----+ 1 root video 81, 2 Mar 12 14:19 /dev/video2

When I try:

cap = cv2.VideoCapture(1)

I get:

[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1

Also cv2.VideoCapture("/dev/video1") results in

[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module source reported: Could not read from resource.

Doing the exact same with the same webcam on my x86 rig works fine without warning. I can’t seem to pull frames from my webcam at all on the Jetson Nano. If I open Ubuntu’s “Cheese Webcam Booth” software, I can see the video stream working properly.

Any ideas? Are there any dependencies I’m overlooking?

Edit:

gst-launch-1.0 -v v4l2src device=/dev/video1 --gst-debug-level=2 gives me:

/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = video/x-raw, format=(string)YUY2, width=(int)800, height=(int)600, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)15/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
0:00:00.161727559 11483   0x5581712ca0 WARN          v4l2bufferpool gstv4l2bufferpool.c:790:gst_v4l2_buffer_pool_start:<v4l2src0:pool:src> Uncertain or not enough buffers, enabling copy threshold
0:00:00.983176348 11483   0x5581712ca0 WARN                 basesrc gstbasesrc.c:3055:gst_base_src_loop:<v4l2src0> error: Internal data stream error.
0:00:00.983219215 11483   0x5581712ca0 WARN                 basesrc gstbasesrc.c:3055:gst_base_src_loop:<v4l2src0> error: streaming stopped, reason not-linked (-1)
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-linked (-1)
Execution ended after 0:00:00.858706121

Hi,
You can get width, height, format, framerate of the source by following:
https://devtalk.nvidia.com/default/topic/1057681/jetson-tx1/logitech-c930e-on-jetson-tx1-very-slow-and-choppy-video/post/5363417/#5363417

And apply it to this sample:
https://devtalk.nvidia.com/default/topic/1065637/jetson-agx-xavier/sony-camera-module-cannot-be-opened-with-opencv-on-xavier/post/5397032/#5397032

Hi, thank you for your reply. I have made some progress. The below works in a terminal:

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=800,height=600,framerate=15/1 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink

But when I try in python (open cv2):

  g_str = "gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=800,height=600,framerate=15/1 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink"
  self.cap = cv2.VideoCapture(g_str, cv2.CAP_GSTREAMER)

I get the following error:

GStreamer-CRITICAL **: 11:31:55.227: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
GStreamer-CRITICAL **: 11:31:55.234: gst_element_link_pads_filtered: assertion 'GST_IS_BIN (parent)' failed

Also I have GStreamer capabilities with cv2:

print(cv2.getBuildInformation())
...
GStreamer:                                           YES (1.14.5)

Also I’m on R32 revision 3.1

Any ideas?

Single quotes are required with gst-launch in order to prevent shell from interpreting anything between parenthesis, but you would omit these in a string for another program.

Hi,
There are samples in follow links:

And we have samples in public source package:
https://developer.nvidia.com/embedded/dlc/r32-3-1_Release_v1.0/Sources/T210/public_sources.tbz2

FYR.