I want to use raspberry pi camera with OpenCV in docker environment on Jetson nano

I want to use raspberry pi camera with OpenCV in docker environment on Jetson nano.

I can use the pi camera with OpenCV on my Jetson nano when I’m not in a docker environment.
But when I’m in the docker, I get the following error.
I’m using “nvidiajetson/l4t-ros-noetic-pytorch” docker image.

[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (711) open OpenCV | GStreamer warning: Error opening bin: no element “nvarguscamerasrc”
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Traceback (most recent call last):
File “opencv_csi-camera.py”, line 27, in
raise IOError(“Failed to open camera device.”)
OSError: Failed to open camera device.

I use the following command to docker run.

docker run
–gpus all
-it
–runtime nvidia
–name ros_pytorch6
–security-opt seccomp=unconfined
–net=host
-e DISPLAY=:1
-v /tmp/.X11-unix/:/tmp/.X11-unix:rw
-v /tmp/argus_socket:/tmp/argus_socket
-v /tmp/nvcamera_socket:/tmp/nvcamera_socket
-v /etc/enctune.conf:/etc/enctune.conf
–device /dev/video0 \

I’m trying to run OpenCV with the following Python code.
I’m using the same code, but I can get camera images when I’m not in the docker environment.

import cv2

GST_STR = “nvarguscamerasrc sensor-id=0 !
video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1 !
nvvidconv !
video/x-raw, width=(int)1920, height=(int)1080, format=(string)BGRx !
videoconvert !
appsink max-buffers=1 drop=true”

if name == “main”:
capture = cv2.VideoCapture(GST_STR, cv2.CAP_GSTREAMER)

if capture.isOpened() is False:
    raise IOError("Failed to open camera device.")

while True:
    retVal, frame = capture.read()

    if retVal == False:
        continue

    cv2.imshow("camera", frame)
    
    key = cv2.waitKey(1)
    if key == 27:   # ESC Key
        break

capture.release()
cv2.destroyAllWindows()

What can I do to help solve this problem?

Hi,

Have you added the device info for your camera when launching the container?

Ex.

$ sudo docker run ... --device=/dev/video0:/dev/video0 ...

Thanks.

Hi

I have added the following command but get the same error.

–device=/dev/video0:/dev/video0

Hi,

Based on the below log, the component cannot be found inside the container.

Error opening bin: no element “nvarguscamerasrc”

Which image tag do you use? Which JetPack version do you use?
Thanks.