I’m providing a description on how to integrate a USB Camera with the Jetson products (AGX Orin in my instance) inside one of the NVIDIA Docker containers. I found no clear resources online on the topic and had to patch together multiple sources of information, even though it’s the most expected configuration for anyone running multiple projects.
- AGX Orin Development Kit
- Jetpack 5.0.2 (L4T 35.1)
First and foremost I would suggest to read this post on USB Camera from Jetson Hacks.
Find one of the NVIDIA containers and pull it, e.g. I use the one on DockerHub for PyTorch
dustynv/l4t-pytorch:r35.1.0-pth1.13-py3. Make sure that it has opencv-python built for nvidia!
Open a new terminal and run
export DISPLAY=:0. Note that the
:0part could also be
:1(it is in my case). To find it for your case run in the terminal
In the same terminal, run
→ The above commands are not permanent, so if you close the terminal, re-run them!
To stream the USB Camera in the Docker environment, using libraries such as opencv-python there are two interfaces GSTREAMER or V4L2. The flags to add the docker
runcommand need to be adjusted.
This is the command I would run and will explain the new flags:
sudo docker run -it --rm --runtime nvidia --network host --device /dev/video0:/dev/video0 -e DISPLAY:$DISPLAY -v /your/origin/path:/your/destination/path -v /tmp/argus_socket:/tmp/argus_socket dustynv/l4t-pytorch:r35.1.0-pth1.13-py3
--deviceflag should be the path of your connected device. Use the command
v4l2-ctl --list-devicesto find yours.
-eis to set the environmet variable.
-vis to mount volumes, and you can use as many as you need.
/tmp/argus_socket:/tmp/argus_socketthis one is NECESSARY if you want to run with GSTREAMER backend.
Run the docker container, and once you’re in run the same
export DISPLAY=:0with the correct
python3and check if opencv-python is installed correctly by typing
import cv2and then
cv2.__version__. Then type
exit()to leave the Python environment. If there’s no installation I don’t think
pip install opencv-pythonwill work.
To quickly test your USB Camera, I would recommend to
git clone https://github.com/jetsonhacks/USB-Camera.git.
python3 usb-camera-simple.pyto check the V4L2 backend, or
python3 usb-camera-gst.pyto check the GSTREAMER backend.
→ Note that depending on your camera specs, you might have to adjust some parameters in the script (e.g. frame height, width or fps).
Last note, for the GSTREAMER backend, you might/will get the following warning:
[ WARN:0] global /opt/opencv/modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
It should still work, and I haven’t fully figured out why.
Anyway, happy coding!