OpenCV + gstreamer + CSI

Hello,

Currently I am capturing frames from my CSI developer board/kit camera using opencv (after rebuilding it from source with cuda and tx2 flags) using this string (being passed to the capture function:

“gst-launch-1.0 nvarguscamerasrc ! nvvidconv ! appsink”

however, I am only getting gray scale frames and there seems to be some lag (20 seconds) and it seems slow.

I tried other settings but it seems that gstreamer doesn’t accept them. I get a messages stating that number of channels is undefined. not sure what that means.

I have the gstreamer 1.0 plugin also installed.

What is the string/params needed to set resolution, format and frame rate that I can use to capture images?

Thanks.

Hi,

How are you trying to modify the resolution, format and framerate when using the opencv capture function? Is it possible to obtain the pipeline, line of code and output log?

On GStreamer side you can configure resolution, format and framerate by using caps, for example:

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

If the capture function doesnt accepts the caps this way, on other projects/functions I have tried by using the capsfilter element, something like this:

IN_CAPS=‘video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1’
OUT_CAPS=‘video/x-raw(memory:NVMM), format=(string)I420’
gst-launch-1.0 -e nvarguscamerasrc ! capsfilter caps="$IN_CAPS" ! nvvidconv ! capsfilter caps="$OUT_CAPS" ! fakesink

About video lag, not sure if you are doing some extra processing that is affecting, if you test the gst-launch pipeline alone, does it have lag? Usually this simple pipelines have very low lag, you can test a gst-launch pipeline similar to the ones provided with a video sink and check for lag.

Regards.

Hello,

I am still getting the same error:

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

(MIPI_TEST:13013): GStreamer-CRITICAL **: 10:57:47.369: gst_element_make_from_uri: assertion ‘gst_uri_is_valid (uri)’ failed

(MIPI_TEST:13013): GStreamer-CRITICAL **: 10:57:47.371: gst_element_make_from_uri: assertion ‘gst_uri_is_valid (uri)’ failed

(MIPI_TEST:13013): GLib-GObject-WARNING **: 10:57:47.373: invalid cast from ‘GstFakeSink’ to ‘GstBin’

(MIPI_TEST:13013): GStreamer-CRITICAL **: 10:57:47.373: gst_bin_iterate_elements: assertion ‘GST_IS_BIN (bin)’ failed

(MIPI_TEST:13013): GStreamer-CRITICAL **: 10:57:47.373: gst_iterator_next: assertion ‘it != NULL’ failed

(MIPI_TEST:13013): GStreamer-CRITICAL **: 10:57:47.373: gst_iterator_free: assertion ‘it != NULL’ failed

(MIPI_TEST:13013): GStreamer-CRITICAL **: 10:57:47.373: gst_element_get_state: assertion ‘GST_IS_ELEMENT (element)’ failed
VIDEOIO ERROR: V4L: device gst-launch-1.0 -e nvarguscamerasrc ! ‘video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1’ ! nvvidconv ! ‘video/x-raw(memory:NVMM), format=(string)I420’ ! fakesink: Unable to query number of channels
Failed to open camera.

Regards,.

Hi selwakad,

Is the gst-launch command provided by Carlos001 working in the console (out of any C/python application)?

Also, what string are you passing to the capture function? Could you please provide a snippet of your code on this region? From your log, it looks like the pipeline description on your application is wrong.

Could you run the application enabling GStreamer debug? Use GST_DEBUG=3 to enable it.

Here you can find some help on creating an OpenCV application using GStreamer for capture:

https://devtalk.nvidia.com/default/topic/1025788/jetson-tx2/opencv-videowriter-to-nvoverlaysink-using-gstreamer-/

Best Regards,