Search code examples
opencvgstreamernvidia-jetson

nvgstcapture vs nvarguscamerasrc


I bought a CSI camera, IMX219, for my OpenCV project.

When I run the below command, there seems to be no delay at all in showing the frames in realtime.

$ nvgstcapture-1.0 -m 2 --prev-res 4

However, when I run my simple python code using the below pipleline, capturing is significantly slow,

pipeline = 'nvarguscamerasrc !  video/x-raw(memory:NVMM), width=1920, height=1080, format=NV12, framerate=30/1 ! nvvidconv flip-method=0 ! video/x-raw, width=1920, height=1080, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'

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

What should I do if I need 1920x1080, 30fps VideoCapture() in Opencv?

Appreciate your help!


Solution

  • Here's a similar question I asked on the NVIDIA devloper forums:https://forums.developer.nvidia.com/t/optimizing-opencv-gstreamer-with-mipi-and-usb-uvc-cameras/123665/27

    Basically, the issue is that you lose a lot of the hardware acceleration in the gstreamer pipeline for OpenCV. videoconvert in particular is very slow in the pipeline. With the nature of my application, I used nvvidconv to convert from BGRx to I420. OpenCV can't handle BGRx, but it can do I420 which I convert to BGR for processing in later parts of my application. appsink is also slow on their devices and you don't have another option for the sink.

    If you need constant real time frames, I would recommend using the libargus API as that probably has the highest performance being provided by NVIDIA and optimized for their hardware.