Issue with GStreamer and OpenCV in a Python Virtual Environment Using Arducam IMX519 Cameras

Issue with GStreamer and OpenCV in a Python Virtual Environment Using Arducam IMX519 Cameras

Hello everyone,

I am facing a complex issue while integrating Arducam IMX519 cameras into my development environment, specifically when using OpenCV with GStreamer in a Python virtual environment. Below, I describe the issue in detail to see if anyone has faced a similar problem and can provide guidance:


Problem Description

  1. Camera works outside the virtual environment:

Using GStreamer commands directly in the terminal, the camera works without any issues, both with gst-launch-1.0 and simple pipelines. For example:

gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM),width=1280,height=720,framerate=30/1’ ! nvvidconv ! xvimagesink

This displays the output correctly.

Additionally, when running camera scripts with sudo outside the virtual environment, the camera responds correctly.

  1. Issue in the virtual environment:

When I attempt to capture frames from the camera in a virtual environment using OpenCV with a GStreamer pipeline, I get the error:

Failed to open camera.

This happens because OpenCV in my virtual environment does not have GStreamer support (as indicated by the output of cv2.getBuildInformation()).

  1. Difference in execution permissions:

Running the code with sudo works correctly outside the virtual environment.

Without sudo, even outside the virtual environment, the camera does not work. This suggests a potential permission issue with /dev/video0 or /dev/i2c-*.


What I Have Tried

  1. Checking GStreamer support in OpenCV:

I verified whether OpenCV has GStreamer support by running:

python3 -c “import cv2; print(cv2.getBuildInformation())”

In the output, it shows that GStreamer is not enabled:

GStreamer: NO

  1. Basic pipeline with OpenCV:

I tried opening the camera directly in Python using this pipeline:

import cv2

pipeline = (
"nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, "
"format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! "
"video/x-raw, format=(string)BGRx ! videoconvert ! "
“video/x-raw, format=(string)BGR ! appsink”
)
cap = cv2.VideoCapture(pipeline, cv2.CAP_GSTREAMER)

if not cap.isOpened():
print(“Failed to open camera.”)
else:
print(“Camera opened successfully.”)

This does not work in the virtual environment because OpenCV lacks GStreamer support.

  1. Permissions on /dev:

I verified that my user is part of the video and i2c groups, and the device permissions are as follows:

ls -l /dev/video0 /dev/i2c-*
crw-rw-rw-+ 1 root video 81, 0 Dec 25 02:01 /dev/video0
crw-rw-rw- 1 root i2c 89, 9 Dec 25 02:01 /dev/i2c-9

Despite the permissions looking correct, running the code without sudo still fails.

  1. Recompiling OpenCV with GStreamer (pending):

I have seen recommendations to recompile OpenCV with GStreamer enabled. However, I have tried this before in another project, and it didn’t work as expected, so I’m hesitant to try it again unless necessary.


Goal

I need to integrate the Arducam IMX519 camera with OpenCV inside the virtual environment, without depending on sudo. Specifically, I aim to:

  1. Enable GStreamer support in OpenCV.

  2. Ensure proper permissions for accessing /dev/video0 and /dev/i2c-* for my user.

  3. Make the pipeline work in the Python virtual environment.


Questions

  1. Has anyone faced a similar issue with Arducam cameras on Jetson Nano or Orin using OpenCV and GStreamer?

  2. Is recompiling OpenCV with GStreamer support the only solution, or is there a way to enable it in my current installation?

  3. Are there any specific configurations on Jetson or Arducam that might be blocking access from the virtual environment?


I greatly appreciate any guidance.

Hi,
The OpenCV package installed through SDKManager has gstreamer enabled, so it looks like this package is not included into the container. Would suggest check this.

Or you may manually build OpenCV with gstreamer enabled. A user has shared a script to build OpenCV:
GitHub - mdegans/nano_build_opencv: Build OpenCV on Nvidia Jetson Nano

You may use it to build OpenCV in the container.

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