Problem Pipeline CSI camera Jetson Nano OpenCV

Hello,

I have some troubles to make my CSI camera work with OpenCV on Python.

I have already posted a similar topic but it was previously a thread problem that Nanocamera module fixed :

I upgraded Jetpack from 4.5 to 4.6 because it has native drivers to use IMX477 CSI cameras which I need for a project.
Now with the same python program as my previous post, I am not able to connect to CSI camera anymore.
I am able to make a pipeline on the console with the gst-launch-1.0 command and the same with nvgstcapture-1.0 command but I can t connect to CSI camera with Open CV on python (I have tried with a IMX477 camera and the Pi camera V2).
I tried with an USB camera and it works fine because I am using the command “cap = cv2.VideoCapture(1)”, not the pipeline.

I think something changed with the new version of OpenCV or Jetpack 4.6 and the pipeline command has to be modified a bit to work but I don t know how


Does anyone knows the solution to my problem ?

Thank in advance !

Hi,
Generally we run gstreamer pipeline in cv2.VideoCaprure() to use nvarguscamerasrc plugin. Please try the samples:
Opencv nvarguscamerasrc: hard LOCKUP on cpu 0 - #3 by DaneLLL

Hello !

Thank you very much for your reply

Sadly it doesn’t work

I have my IMX477 on the port /dev/video0

In the console :

$ gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1' ! nvoverlaysink

works fine.

But in Python :

import sys
import cv2
def read_cam():
    cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert !  appsink")
    if cap.isOpened():
        cv2.namedWindow("demo", cv2.WINDOW_AUTOSIZE)
        while True:
            ret_val, img = cap.read();
            cv2.imshow('demo',img)
            cv2.waitKey(10)
    else:
        print( "camera open failed")

    cv2.destroyAllWindows()


if __name__ == '__main__':
    read_cam()

doesn’t work.
It only print : camera open failed

I tried with all pipelines you have sent me
I used this one on jetpack 4.5 and it worked fine :

"nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, width=(int)1920, height=(int)1080, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"

but now in 4.6, it doesn’t work anymore


If I launch the program from the console, this is the error message I get :

~$ python3 camtest.py
[ERROR:0@0.449] global /io/opencv/modules/videoio/src/cap.cpp (164) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.5) /io/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can’t find starting number (in the name of file): nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)RGBA ! appsink in function ‘icvExtractPattern’

camera open failed

Hi,
From the log it looks like the OpenCV is not built with gstreamer being enabled. You may rebuild OpenCV 4.5.5 and try again. Or re-flash the system to use default OpenCV 4.1.1

1 Like

Indeed it looks like Gstreamer is not activated in my OpenCV version

It looks pretty complicated to rebuid OpenCV so I will try to reinstall Jetpack 4.6 on the SD card and reinstall everything

Thank you again for your help

I will tell you if it worked or not

I have finally finished to re flash the SD card (update and upgrade everything and install pytorch) and everything works perfectly now !

I can use my previous python program with the IMX477 camera

Thank you so much for your help ! :)

1 Like

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