Unable to open camera for CSİ Camera

Hello,

I am using a Jetson Orin Nano Developer Kit, and I was able to run my camera successfully with the code below. However, recently, the camera stopped working. I might have made some changes while compiling programs, but I’m not sure. Here’s the code:

# MIT License
# Copyright (c) 2019-2022 JetsonHacks

# Using a CSI camera (such as the Raspberry Pi Version 2) connected to a
# NVIDIA Jetson Nano Developer Kit using OpenCV
# Drivers for the camera and OpenCV are included in the base image

import cv2

def gstreamer_pipeline(
    sensor_id=0,
    capture_width=1920,
    capture_height=1080,
    display_width=960,
    display_height=540,
    framerate=30,
    flip_method=2,
):
    return (
        "nvarguscamerasrc sensor-id=%d ! "
        "video/x-raw(memory:NVMM), width=(int)%d, height=(int)%d, framerate=(fraction)%d/1 ! "
        "nvvidconv flip-method=%d ! "
        "video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
        "videoconvert ! "
        "video/x-raw, format=(string)BGR ! appsink"
        % (
            sensor_id,
            capture_width,
            capture_height,
            framerate,
            flip_method,
            display_width,
            display_height,
        )
    )

def show_camera():
    window_title = "CSI Camera"
    video_capture = cv2.VideoCapture(gstreamer_pipeline(flip_method=2), cv2.CAP_GSTREAMER)
    if video_capture.isOpened():
        try:
            window_handle = cv2.namedWindow(window_title, cv2.WINDOW_AUTOSIZE)
            while True:
                ret_val, frame = video_capture.read()
                if cv2.getWindowProperty(window_title, cv2.WND_PROP_AUTOSIZE) >= 0:
                    cv2.imshow(window_title, frame)
                else:
                    break
                keyCode = cv2.waitKey(10) & 0xFF
                if keyCode == 27 or keyCode == ord('q'):
                    break
        finally:
            video_capture.release()
            cv2.destroyAllWindows()
    else:
        print("Error: Unable to open camera")

if __name__ == "__main__":
    show_camera()

When I run this code, I get the following error:
onur@ubuntu:~/Desktop/Project$ /bin/python /home/onur/Desktop/Project/simple_camera.py
nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, width=(int)960, height=(int)540, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
Error: Unable to open camera

I also ran the following command to check the OpenCV version:
onur@ubuntu:~$ python3 -c "import cv2; print(cv2.__version__)"
4.10.0
onur@ubuntu:~$ python3 -c "import cv2; print(cv2.getBuildInformation())"

General configuration for OpenCV 4.10.0 =====================================
Version control: 4.10.0-dirty

Platform:
Timestamp: 2024-06-17T18:00:16Z
Host: Linux 5.3.0-28-generic aarch64
CMake: 3.29.5
CMake generator: Unix Makefiles
CMake build tool: /bin/gmake
Configuration: Release

CPU/HW features:
Baseline: NEON FP16
Dispatched code generation: NEON_DOTPROD NEON_FP16 NEON_BF16
requested: NEON_FP16 NEON_BF16 NEON_DOTPROD
NEON_DOTPROD (1 files): + NEON_DOTPROD
NEON_FP16 (2 files): + NEON_FP16
NEON_BF16 (0 files): + NEON_BF16

C/C++:
Built as dynamic libs?: NO
C++ standard: 11
C++ Compiler: /opt/rh/devtoolset-10/root/usr/bin/c++ (ver 10.2.1)
C++ flags (Release): -Wl,-strip-all -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -Wl,-strip-all -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /opt/rh/devtoolset-10/root/usr/bin/cc
C flags (Release): -Wl,-strip-all -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -Wl,-strip-all -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -L/ffmpeg_build/lib -Wl,–gc-sections -Wl,–as-needed -Wl,–no-undefined
Linker flags (Debug): -L/ffmpeg_build/lib -Wl,–gc-sections -Wl,–as-needed -Wl,–no-undefined
ccache: YES
Precompiled headers: NO
Extra dependencies: /lib64/libopenblas.so Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test Qt5::Concurrent /usr/local/lib/libpng.so /lib64/libz.so dl m pthread rt
3rdparty dependencies: libprotobuf ade ittnotify libjpeg-turbo libwebp libtiff libopenjp2 IlmImf tegra_hal

OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java python2 ts
Applications: -
Documentation: NO
Non-free algorithms: NO

GUI: QT5
QT: YES (ver 5.15.13 )
QT OpenGL support: NO
GTK+: NO
VTK support: NO

Media I/O:
ZLib: /lib64/libz.so (ver 1.2.7)
JPEG: build-libjpeg-turbo (ver 3.0.3-70)
SIMD Support Request: YES
SIMD Support: YES
WEBP: build (ver encoder: 0x020f)
PNG: /usr/local/lib/libpng.so (ver 1.6.43)
TIFF: build (ver 42 - 4.6.0)
JPEG 2000: build (ver 2.5.0)
OpenEXR: build (ver 2.3.0)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES

Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (59.37.100)
avformat: YES (59.27.100)
avutil: YES (57.28.100)
swscale: YES (6.7.100)
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)

Parallel framework: pthreads

Trace: YES (with Intel ITT)

Other third-party libraries:
Lapack: YES (/lib64/libopenblas.so)
Eigen: NO
Custom HAL: YES (carotene (ver 0.0.1, Auto detected))
Protobuf: build (3.19.1)
Flatbuffers: builtin/3rdparty (23.5.9)

OpenCL: YES (no extra features)
Include path: /io/opencv/3rdparty/include/opencl/1.2
Link libraries: Dynamic load

Python 3:
Interpreter: /opt/python/cp39-cp39/bin/python3.9 (ver 3.9.19)
Libraries: libpython3.9m.a (ver 3.9.19)
Limited API: YES (ver 0x03060000)
numpy: /home/ci/.local/lib/python3.9/site-packages/numpy/_core/include (ver 2.0.0)
install path: python/cv2/python-3

Python (for build): /opt/python/cp39-cp39/bin/python3.9

Java:
ant: NO
Java: NO
JNI: NO
Java wrappers: NO
Java tests: NO

Install to: /io/_skbuild/linux-aarch64-3.9/cmake-install

onur@ubuntu:~$ cat /etc/nv_tegra_release

R36 (release), REVISION: 4.0, GCID: 37537400, BOARD: generic, EABI: aarch64, DATE: Fri Sep 13 04:36:44 UTC 2024

KERNEL_VARIANT: oot

TARGET_USERSPACE_LIB_DIR=nvidia
TARGET_USERSPACE_LIB_DIR_PATH=usr/lib/aarch64-linux-gnu/nvidia

I also ran the following command to check the OpenCV version:

onur@ubuntu:~$ python3 -c "import cv2; print(cv2.__version__)"
4.10.0
``

Someone said that GStreamer support is disabled according to the build information. Someone suggested that I try enabling GStreamer support, and I began the following steps, but I’m not entirely sure if this is the correct approach:

``

Install necessary dependencies

sudo apt-get update
sudo apt-get install build-essential cmake git pkg-config libgtk-3-dev libatlas-base-dev gfortran python3-dev

Download OpenCV source code

git clone GitHub - opencv/opencv: Open Source Computer Vision Library
cd opencv
git checkout 4.10.0 # or specify the version you need

Create a build directory

mkdir build
cd build

Configure with CMake, enabling GStreamer

cmake -D WITH_GSTREAMER=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local …

Build and install

make -j$(nproc)
sudo make install
``

Am I on the right track with this, or is there something else I should be doing to get the camera working again?

Thank you for your help!

Hi @onurrcifcii

Let’s focus on the camera capture issue. Have you tried to dequeue some buffers using v4l2-ctl? This tool lets us focus on the camera capture issue and remove other variables like GStreamer, OpenCV, etc.

You can run a command similar to the following:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=960,height=540,pixelformat=BG12 --set-ctrl bypass_mode=0 --stream-mmap

If your pixel format is not BG12, you can check it using the following command:

v4l2-ctl -d /dev/video0 --list-formats

Please, run the above commands and share the results with us.

Eduardo Salazar
Embedded SW Engineer at RidgeRun

Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com/
Website: www.ridgerun.com

Hi @EduardoSalazar96
Here is the results;

onur@ubuntu:~$ v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture

[0]: 'RG10' (10-bit Bayer RGRG/GBGB)

onur@ubuntu:~$ v4l2-ctl -d /dev/video0 --set-fmt-video=width=960,height=540,pixelformat=BG12 --set-ctrl bypass_mode=0 --stream-mmap
The pixelformat ‘BG12’ is invalid
<<<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<<< 21.19 fps

I stop that with ctrl+c

and i tried that;

onur@ubuntu:~$ v4l2-ctl -d /dev/video0 --set-fmt-video=width=960,height=540,pixelformat=RG10 --set-ctrl bypass_mode=0 --stream-mmap
<<<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps
<<<<<<<<<<<<<<<<<<<<< 21.19 fps

What can i do next?

@onurrcifcii thanks for sharing the results!

I got confuse and I set the width and height not to be 1920x1080. You can test the following command just to confirm

v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=RG10 --set-ctrl bypass_mode=0 --stream-mmap

If the above command run with success, what we can do next is run some tests by executing a simplified standalone Gstreamer pipeline. You can use the GitHub - RidgeRun/gst-perf: GStreamer element to measure framerate, bitrate and CPU usage. element to do those tests. The pipeline could be the following:

GST_DEBUG=2 gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1 ! nvvidconv ! perf ! fakesink

Depending on the framerate, you should get an output similar to the following:

perf: perf0; timestamp: 21:30:00.521041716; bps: 147458765.756; mean_bps: 147452725.779; fps: 30.001; mean_fps: 29.999

Let us know your results!

@EduardoSalazar96 There is a problem;

onur@ubuntu:~/gst-perf$ GST_DEBUG=2 gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! ‘video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1’ ! nvvidconv ! perf ! fakesink
0:00:00.203763004 34685 0xaaaacdea6b00 WARN GST_ELEMENT_FACTORY gstelementfactory.c:701:gst_element_factory_make_with_properties: no such element factory “perf”!
0:00:00.203826073 34685 0xaaaacdea6b00 ERROR GST_PIPELINE gst/parse/grammar.y:851:priv_gst_parse_yyparse: no element “perf”
0:00:00.203848280 34685 0xaaaacdea6b00 ERROR GST_PIPELINE gst/parse/grammar.y:939:priv_gst_parse_yyparse: link has no sink [source=@0xaaaacdffcda0]
0:00:00.204695408 34685 0xaaaacdea6b00 ERROR GST_PIPELINE gst/parse/grammar.y:939:priv_gst_parse_yyparse: link has no source [sink=@0xaaaace004a90]
WARNING: erroneous pipeline: no element “perf”

@onurrcifcii

You have to install the perf element in GitHub - RidgeRun/gst-perf: GStreamer element to measure framerate, bitrate and CPU usage. since it is a custom element. Sorry for not clarifying that from my side in my previous reply. In the repo are instructions on how to install it in your jetson

@EduardoSalazar96

Here the output:

onur@ubuntu:~/gst-perf$ GST_DEBUG=2 gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1' ! nvvidconv ! perf ! fakesink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3280 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3280 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1640 x 1232 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
   Camera index = 0 
   Camera mode  = 2 
   Output Stream W = 1920 H = 1080 
   seconds to Run    = 0 
   Frame Rate = 29.999999 
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
INFO:
perf: perf0; timestamp: 3:11:20.397505480; bps: 0.000; mean_bps: 0.000; fps: 0.000; mean_fps: 0.000
Redistribute latency...
INFO:01.2 / 99:99:99.
perf: perf0; timestamp: 3:11:21.403680458; bps: 10240.000; mean_bps: 0.000; fps: 30.810; mean_fps: 30.810
INFO:02.2 / 99:99:99.
perf: perf0; timestamp: 3:11:22.403800697; bps: 15360.000; mean_bps: 15360.000; fps: 29.996; mean_fps: 30.403
INFO:03.3 / 99:99:99.
perf: perf0; timestamp: 3:11:23.438213685; bps: 15360.000; mean_bps: 15360.000; fps: 29.969; mean_fps: 30.258
INFO:04.4 / 99:99:99.
perf: perf0; timestamp: 3:11:24.470298506; bps: 15360.000; mean_bps: 15360.000; fps: 30.036; mean_fps: 30.203
INFO:05.4 / 99:99:99.
perf: perf0; timestamp: 3:11:25.504077668; bps: 15360.000; mean_bps: 15360.000; fps: 29.987; mean_fps: 30.160
INFO:06.4 / 99:99:99.
perf: perf0; timestamp: 3:11:26.536596314; bps: 15360.000; mean_bps: 15360.000; fps: 30.024; mean_fps: 30.137
INFO:07.5 / 99:99:99.
perf: perf0; timestamp: 3:11:27.568732079; bps: 15360.000; mean_bps: 15360.000; fps: 30.035; mean_fps: 30.122
INFO:08.5 / 99:99:99.
perf: perf0; timestamp: 3:11:28.568854046; bps: 15360.000; mean_bps: 15360.000; fps: 29.996; mean_fps: 30.107
INFO:09.5 / 99:99:99.
perf: perf0; timestamp: 3:11:29.569108941; bps: 15360.000; mean_bps: 15360.000; fps: 29.992; mean_fps: 30.094
INFO:10.5 / 99:99:99.
perf: perf0; timestamp: 3:11:30.602139365; bps: 15360.000; mean_bps: 15360.000; fps: 30.009; mean_fps: 30.085
INFO:11.5 / 99:99:99.
perf: perf0; timestamp: 3:11:31.602687990; bps: 15360.000; mean_bps: 15360.000; fps: 29.984; mean_fps: 30.076
INFO:12.5 / 99:99:99.
perf: perf0; timestamp: 3:11:32.635313484; bps: 15360.000; mean_bps: 15360.000; fps: 30.021; mean_fps: 30.072
INFO:13.5 / 99:99:99.
perf: perf0; timestamp: 3:11:33.635321275; bps: 15360.000; mean_bps: 15360.000; fps: 30.000; mean_fps: 30.066
INFO:14.5 / 99:99:99.
perf: perf0; timestamp: 3:11:34.667966769; bps: 15360.000; mean_bps: 15360.000; fps: 30.020; mean_fps: 30.063
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:14.983031333
Setting pipeline to NULL ...
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
Freeing pipeline ...

@EduardoSalazar96

I did something and camera is working on my code;

pip uninstall opencv-python
pip uninstall opencv-python-headless
sudo apt update
sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-ffmpeg

sudo apt-get install build-essential cmake git pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libv4l-dev
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install libgtk2.0-dev
cd ~
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

cd ~/opencv
mkdir build
cd build

cmake -D WITH_GSTREAMER=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

make -j$(nproc)
sudo make install

Now when i check GStreamer with that code:

import cv2
print(cv2.getBuildInformation())

output has the Streamer: YES

after that i try again and issue change. After that i change the cap;

cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1920, height=1080, framerate=30/1 ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink")

İt worked.

However, if there is a problem with the current view, I would be very happy to solve it, I do not want to have any problems later. Thanks in advance for all your help.

@onurrcifcii

Your welcome.

Sure, if you have any more issues do not hesitate to reach us. I do recommend to open a new post if you encounter additional problems.

Regards!

Hi @EduardoSalazar96 ;

I reset the board for a fresh start. Now, I’m trying to run the Raspberry Pi camera using the code from GitHub - JetsonHacksNano/CSI-Camera: Simple example of using a CSI-Camera (like the Raspberry Pi Version 2 camera) with the NVIDIA Jetson Developer Kit, but I’m encountering an error.

Here is the error message I get:

onur@ubuntu:~/CSI-Camera$ python3 simple_camera.py
nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)960, height=(int)540, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
Error: Unable to open camera

Even though I have installed everything using SDK Manager, it seems that GStreamer is not working correctly. When I run the following command, it shows GStreamer: No:

onur@ubuntu:~$ python3 -c "import cv2; print(cv2.getBuildInformation())"

This is part of the output:

General configuration for OpenCV 4.10.0 =====================================
...
GStreamer: NO
...

I’m also trying to set up DeepStream and hoping that once I get DeepStream running, I might not need to solve the GStreamer issue, as DeepStream could handle the pipeline.

Do I still need to fix GStreamer for the CSI camera, or can I adapt the following code to work with DeepStream instead?

Here’s the code I’m currently using:

import cv2

def gstreamer_pipeline(
    sensor_id=0,
    capture_width=1920,
    capture_height=1080,
    display_width=960,
    display_height=540,
    framerate=30,
    flip_method=0,
):
    return (
        "nvarguscamerasrc sensor-id=%d ! "
        "video/x-raw(memory:NVMM), width=(int)%d, height=(int)%d, framerate=(fraction)%d/1 ! "
        "nvvidconv flip-method=%d ! "
        "video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
        "videoconvert ! "
        "video/x-raw, format=(string)BGR ! appsink"
        % (
            sensor_id,
            capture_width,
            capture_height,
            framerate,
            flip_method,
            display_width,
            display_height,
        )
    )

def show_camera():
    window_title = "CSI Camera"
    print(gstreamer_pipeline(flip_method=0))
    video_capture = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
    if video_capture.isOpened():
        try:
            window_handle = cv2.namedWindow(window_title, cv2.WINDOW_AUTOSIZE)
            while True:
                ret_val, frame = video_capture.read()
                if cv2.getWindowProperty(window_title, cv2.WND_PROP_AUTOSIZE) >= 0:
                    cv2.imshow(window_title, frame)
                else:
                    break
                keyCode = cv2.waitKey(10) & 0xFF
                if keyCode == 27 or keyCode == ord('q'):
                    break
        finally:
            video_capture.release()
            cv2.destroyAllWindows()
    else:
        print("Error: Unable to open camera")

if __name__ == "__main__":
    show_camera()

Thanks for any help or suggestions!

Hi @onurrcifcii

When you suspect GStreamer, it is better to run a standalone pipeline outside the application to confirm whether GStreamer is failing or not.

Could you repeat the test from the following comment?

Do not forget to install GitHub - RidgeRun/gst-perf: GStreamer element to measure framerate, bitrate and CPU usage.

Please, let us know the results.

Regards!

@proventusnova @EduardoSalazar96 thanks for reply,

Here is the output;

onur@ubuntu:~/gst-perf$ GST_DEBUG=2 gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1' ! nvvidconv ! perf ! fakesink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3280 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3280 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1640 x 1232 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
   Camera index = 0 
   Camera mode  = 2 
   Output Stream W = 1920 H = 1080 
   seconds to Run    = 0 
   Frame Rate = 29.999999 
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
INFO:
perf: perf0; timestamp: 1:38:32.949670029; bps: 0.000; mean_bps: 0.000; fps: 0.000; mean_fps: 0.000
Redistribute latency...
INFO:01.3 / 99:99:99.
perf: perf0; timestamp: 1:38:33.951304217; bps: 9216.000; mean_bps: 0.000; fps: 30.949; mean_fps: 30.949
INFO:02.3 / 99:99:99.
perf: perf0; timestamp: 1:38:34.982309941; bps: 15360.000; mean_bps: 15360.000; fps: 30.068; mean_fps: 30.509
INFO:03.3 / 99:99:99.
perf: perf0; timestamp: 1:38:35.982897132; bps: 15360.000; mean_bps: 15360.000; fps: 29.982; mean_fps: 30.333
INFO:04.4 / 99:99:99.
perf: perf0; timestamp: 1:38:37.014799285; bps: 15360.000; mean_bps: 15360.000; fps: 30.042; mean_fps: 30.260
INFO:05.5 / 99:99:99.
perf: perf0; timestamp: 1:38:38.048663875; bps: 15360.000; mean_bps: 15360.000; fps: 29.985; mean_fps: 30.205
INFO:06.5 / 99:99:99.
perf: perf0; timestamp: 1:38:39.049046639; bps: 15360.000; mean_bps: 15360.000; fps: 29.989; mean_fps: 30.169
INFO:07.5 / 99:99:99.
perf: perf0; timestamp: 1:38:40.081535030; bps: 15360.000; mean_bps: 15360.000; fps: 30.025; mean_fps: 30.148
INFO:08.5 / 99:99:99.
perf: perf0; timestamp: 1:38:41.081697080; bps: 15360.000; mean_bps: 15360.000; fps: 29.995; mean_fps: 30.129
INFO:09.5 / 99:99:99.
perf: perf0; timestamp: 1:38:42.082274478; bps: 15360.000; mean_bps: 15360.000; fps: 29.983; mean_fps: 30.113
INFO:10.5 / 99:99:99.
perf: perf0; timestamp: 1:38:43.114170071; bps: 15360.000; mean_bps: 15360.000; fps: 30.042; mean_fps: 30.106
INFO:11.5 / 99:99:99.
perf: perf0; timestamp: 1:38:44.114798192; bps: 15360.000; mean_bps: 15360.000; fps: 29.981; mean_fps: 30.095
INFO:12.6 / 99:99:99.
perf: perf0; timestamp: 1:38:45.147838099; bps: 15360.000; mean_bps: 15360.000; fps: 30.009; mean_fps: 30.087
INFO:13.6 / 99:99:99.
perf: perf0; timestamp: 1:38:46.180300538; bps: 15360.000; mean_bps: 15360.000; fps: 30.025; mean_fps: 30.083
INFO:14.6 / 99:99:99.
perf: perf0; timestamp: 1:38:47.180337268; bps: 15360.000; mean_bps: 15360.000; fps: 29.999; mean_fps: 30.077
INFO:15.6 / 99:99:99.
perf: perf0; timestamp: 1:38:48.182385013; bps: 15360.000; mean_bps: 15360.000; fps: 29.939; mean_fps: 30.067
INFO:16.6 / 99:99:99.
perf: perf0; timestamp: 1:38:49.213758564; bps: 15360.000; mean_bps: 15360.000; fps: 30.057; mean_fps: 30.067
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:17.054496850
Setting pipeline to NULL ...
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
Freeing pipeline ...

Hello @onurrcifcii,

The GStreamer output seems to indicate everything is fine at GStreamer level.

Going back to your previous comment, with regards to this:

OpenCV seems to be missing GStreamer support.
That might be an issue when trying to interact with GStreamer using OpenCV on Python.

What is very interesting to me, is that you just recently flashed the board from scratch.
Therefore, you should already have a version of OpenCV with GStreamer support enabled.

Reading around, found this;

I believe that you might have the same happening to you.
Apparently when you install ultralytics with pip, that removes GStreamer support for OpenCV.

Maybe you could just take the OpenCV Debian package downloaded by SDK Manager into your downloads folder, copy it into your board, and installing.

regards,
Andrew
Embedded Software Engineer at ProventusNova

Hi @proventusnova

In the link below, I see someone resolved a similar issue by downgrading OpenCV: Opencv doesnt support Gstreamer - #5 by seinan.malgas

Would you recommend that I try this approach? Also, do you know which OpenCV version would be compatible with GStreamer support?

@onurrcifcii,

If I were you, I would first try installing the OpenCV Debian that SDK Manager downloads.

regards,
Andrew
Embedded Software Engineer at ProventusNova

@proventusnova
Which ones should I choose in the SDK manager?

@onurrcifcii,

SDK Manager downloads the packages that it installs into the folder you configure during step2 of the installation process. By default, the folder is located in ~/Downloads.

Can you please provide me with the output of:

ls ~/Downloads

Of the linux computer you are using to run SDK Manager?

regards,
Andrew
Embedded Software Engineer at ProventusNova

Hi @onurrcifcii

Could you please uninstall the opencv from pip and install the following apt packages:

sudo apt install libopencv-dev libopencv-python libgstreamer-opencv1.0-0

and then, rerun your example app.

Regards!

Hi @proventusnova ,

Downloads has nvidia then just 1 folder "sdkm_downloads and here is the ~ls

onur@onur:~/Downloads/nvidia/sdkm_downloads$ ls
cudnn-local-tegra-repo-ubuntu2204-9.3.0_1.0-1_arm64.deb
cupva-2.5.3-l4t.deb
deepstream-7.1_7.1.0-1_arm64.deb
deepstream-reference-graphs-7.1.deb
graph_composer-4.1.0_x86_64.deb
graph_composer-runtime-4.1.0_arm64.deb
graph_composer-runtime-4.1.0_x86_64.deb
hwdata
Jetson_Linux_R36.4.0_aarch64.tbz2
l4t-cuda-repo-cross-aarch64-ubuntu2204-12-6-local_12.6.11-1_all.deb
l4t-cuda-repo-ubuntu2204-12-6-local_12.6.11-560.35.03-1_amd64.deb
l4t-cuda-tegra-repo-ubuntu2204-12-6-local_12.6.11-1_arm64.deb
libnvidia-container1_1.14.2-1_arm64.deb
libnvidia-container-tools_1.14.2-1_arm64.deb
nsight-systems-2024.5.4.34-3485573-DVS-1_tegra_igpu_arm64.deb
NsightSystems-linux-public-DVS-2024.5.4.34-3485573.deb
nvidia-container-toolkit_1.14.2-1_arm64.deb
nvidia-container-toolkit-base_1.14.2-1_arm64.deb
nvidia-l4t-cudadebuggingsupport_12.6-34622040.0_arm64.deb
nvidia-l4t-dla-compiler_36.4.0-20240912212859_arm64.deb
nvidia-l4t-gstreamer_36.4.0-20240912212859_arm64.deb
nvidia-l4t-jetson-multimedia-api_36.4.0-20240912212859_arm64.deb
NVIDIA_Nsight_Graphics_L4T_Public_2024.2.24262_arm64.deb
NVIDIA_Nsight_Graphics_L4T_Public_2024.2.24262_x64.deb
NVIDIA_Nsight_Perf_SDK_2023.5.0_L4T.tar.gz
NVIDIA_Nsight_Perf_SDK_Docs_2023.5.0.zip
nvsci_pkg_x86_64_rel-36_20240822_37344366.deb
nv-tensorrt-local-tegra-repo-ubuntu2204-10.3.0-cuda-12.5_1.0-1_arm64.deb
nvv4l2_x86_ds-7.1.deb
OpenCV-4.8.0-1-g6371ee1-aarch64-dev.deb
OpenCV-4.8.0-1-g6371ee1-aarch64-libs.deb
OpenCV-4.8.0-1-g6371ee1-aarch64-licenses.deb
OpenCV-4.8.0-1-g6371ee1-aarch64-python.deb
OpenCV-4.8.0-1-g6371ee1-aarch64-samples-data.deb
OpenCV-4.8.0-1-g6371ee1-aarch64-samples.deb
pva-allow-2.0.0~rc3.deb
sdkmanager_2.2.0-12021_amd64.deb
sdkml3_deepstream_71.json
sdkml3_gxf_runtime_41.json
sdkml3_jetpack_61.json
Tegra_Linux_Sample-Root-Filesystem_R36.4.0_aarch64.tbz2
vpi-cross-aarch64-l4t-3.2.4-cuda12-x86_64-linux.deb
vpi-dev-3.2.4-aarch64-l4t.deb
vpi-dev-3.2.4-cuda12-x86_64-linux.deb
vpi-lib-3.2.4-aarch64-l4t.deb
vpi-lib-3.2.4-cuda12-x86_64-linux.deb
vpi-python3.10-3.2.4-aarch64-l4t.deb
vpi-python3.10-3.2.4-cuda12-x86_64-linux.deb
vpi-python-src-3.2.4-aarch64-l4t.deb
vpi-python-src-3.2.4-cuda12-x86_64-linux.deb
vpi-samples-3.2.4-aarch64-l4t.deb
vpi-samples-3.2.4-cuda12-x86_64-linux.deb

@onurrcifcii,

That is great, these are the packages you would need to install.

You can simply copy them via scp into your Jetson board.
Then, from your Jetson you can do: sudo apt install ./OpenCV*.deb

Please let us know how it goes.

regards,
Andrew
Embedded Software Engineer at ProventusNova