Using TX1 Camera with Xavier and Python (Solved)

I’ve tried to follow this example but i cant quite get the camera to work.
https://jkjung-avt.github.io/tx2-camera-with-python/
#

Using this gstream command in terminal works, this also keeps it from copying to memory.
gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM), width=(int)2592, height=(int)1944, format=(string)NV12, framerate=(fraction)30/1’ ! nvivafilter cuda-process=true customer-lib-name=“libnvsample_cudaprocess.so” ! ‘video/x-raw(memory:NVMM), format=(string)NV12’ ! nvvidconv flip-method=2 ! nvoverlaysink -e

I replaced this line
gst_str = “v4l2src device=/dev/video{} ! video/x-raw, width=(int){}, height=(int){}, format=(string)RGB ! videoconvert ! appsink”.format(dev, width, height)

with this one
gst_str = nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)2592, height=(int)1944, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, width=(int){}, height=(int){}, format=(string)BGRx ! videoconvert ! appsink.format(width, height)

but it has a syntax error at appsink, so if anybody knows what to do

Hi,
There is a code of opening onboard camera:

def open_cam_onboard(width, height):
    # On versions of L4T prior to 28.1, add 'flip-method=2' into gst_str
    gst_str = ('nvcamerasrc ! '
               'video/x-raw(memory:NVMM), '
               'width=(int)2592, height=(int)1458, '
               'format=(string)I420, framerate=(fraction)30/1 ! '
               'nvvidconv ! '
               'video/x-raw, width=(int){}, height=(int){}, '
               'format=(string)BGRx ! '
               'videoconvert ! appsink').format(width, height)
    return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

Does it work? Suggest you try nvcamerasrc.

Hi

@Dane nvcamerasrc is not supported anymore (according to the doc, it is depreciated ). gst-inspect is not able to parse the plugin , so depreciated → not supported :-(

@jbrowning, I tested the TX2 cam (CSI) on the Xavier, I suppose this the same cam as the TX1. Under python you must be sure to add the flag .CAP_GSTREAMER in the cv2.VideoCapture.

I used this pipeline (if I remember correctly)
nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)RGB" ! appsink
(your can try BGR as output to increase the performance)

Even with a code optimized I was not able to get more than 10fps under python with a CSI camera or with an USB cam (I used opencv 3.4 → Opencv : No Cuda with python)

With a C++ code, I got 30fps, with the TX2 CSI camera or an USB CAM (same performance), you can use the code provided by Dustin on his github (you must update it to support the CSI camera : nvcamerasrc, pipeline… ).

I posted a small video with the performance I got:

Br

ps: opencv 3.3.1 delivered with the jetpack 4 has not been compiled for gstreamer, so you must recompile it

Nope ludvic and dane niether solution worked.

Called with args:
Namespace(image_height=1944, image_width=2592, rtsp_latency=200, rtsp_uri=None, use_rtsp=False, use_usb=False, video_dev=0)
OpenCV version: 3.3.1
Failed to open camera!

But ludvic i think you’re right i need to compile opencv with gstreamer so now im waiting on m2 drive.
will report back when done, thanks guys

To be sure (python 2.7) or add the ()

import cv2
print cv2.getBuildInformation()

→ you will find the gstremear capability

Br
Ludovic

We have verified below steps on Xavier:
[url]https://devtalk.nvidia.com/default/topic/1042892/jetson-agx-xavier/nvarguscamerasrc-opencv-/post/5290833/#5290833[/url]

Works for us with the following gstreamer pipeline:

gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=30/1’ ! nvvidconv flip-method=2 !nvoverlaysink -e -vvv

-albertr