IMX390 camera with OpenCV

Hi all,

I am using a IMX390-GMSL2 camera with Xavier NX based embedded device. By using the below terminal command, I am able to launch gstreamer display of the camera output successfully.

 gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM),width=1920,height=1080,format=NV12' ! nvvidconv ! xvimagesink

Now, I want to launch the same display using OpenCV for which I was the below script:

import cv2
import sys

gst_str = ("nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM),width=1920,height=1080,format=NV12 ! nvvidconv ! xvimagesink")

cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
if not cap.isOpened():
    print('Failed to open camera!')
    sys.exit()
while(True):
    _, img = cap.read() # grab the next image frame from camera
    cv2.imshow("cam", img)
    key = cv2.waitKey(10)

The output I get is “Failed to open camera!”. Can someone suggest the changes which could make it work ?

Thanks!

An OpenCV videoCapture with gstreamer backend would need a pipeline sinking to appsink (OpenCV application here). Try:

gst_str = "nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM),width=1920,height=1080,format=NV12 ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1"

imshow will display instead of xvimagesink (may be a bit slower, though).

1 Like

Hi @Honey_Patouceul ,

Thanks for you reply.
I tried the above suggested. I still don’t get a camera output and ‘Failed to open camera!’ is displayed.

Have reference to below github.

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