Access CSI in Docker container

Hello, I am working with a Jetson Xavier NX, and I created a docker image based on . Now I would like to access a picam v2 connected using CSI from a python script. Anyway I cannot do that, since I don’t have GStream ON in my opencv installation. Now I was wandering if there is an official image like /nvidia/dli/dli-nano-ai:v2.0.1-r32.4.4 (That is actually working for me) for the Xavier that has opencv with all/most of the features enable (Gstream, cuDNN…).
Or is there a way to use the opencv installation that is installed on the jetpack4.4 that is running as OS on the Jetson?

Hi @polivicio, if you look at this section of the JetBot Dockerfile, it installs the OpenCV from JetPack into the container that has GStreamer enabled:

This is how the dli-nano container and the JetBot container install JetPack’s OpenCV.

If you wanted to build OpenCV with CUDA/cuDNN/ect enabled in your container, you could run @mdegans OpenCV build script in your Dockerfile:

1 Like

Thanks for the link, @dusty_nv


There is a docker branch of the OpenCV build script with a sample Dockerfile. If you’re making something OpenCV based, it might be easiest to build that image and use it as a base, or modify the Dockerfile to your needs. You’ll likely have to build it yourself since I haven’t build and pushed a new version since the GA release of JetPack 4.4.

At a minimum you may with to modify the jetpack version at the top of the docker build script to match the current JetPack base image tag. You can also modify the OpenCV version in the same place. (eg. "4.4.0" instead of master)

@dusty_nv I’ve already tried the bash script for the installation but I got:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:

and a long list of libraries like CUDA_CUDA_LIBRARY, CUDA_cublas_LIBRARY

and then :

Configuring incomplete, errors occurred!
See also "/tmp/build_opencv/opencv/build/CMakeFiles/CMakeOutput.log".
See also "/tmp/build_opencv/opencv/build/CMakeFiles/CMakeError.log".
make: *** No targets specified and no makefile found.  Stop.
make: *** No rule to make target 'install'.  Stop.
Removing intermediate container 813dc4cd6a99

Are you running this inside Docker? If so, set your default docker-runtime to nvidia as shown here:

This will enable you to use CUDA while you are building Docker containers.

If you were running this script on your Jetson (not in a container), are you sure that the CUDA toolkit is installed (under /usr/local/cuda)? Did you flash your Xavier NX’s SD card with the SD card image? That SD card image already comes with CUDA/cuDNN/ect pre-installed.

1 Like

@dusty_nv Yes I am running the script inside Docker on the Xavier NX. I see that on the board cuda is installed. Checking the runtime in /etc/docker/deamon.json it has “default-runtime”: “nvidia” , but still the same configuration error:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
-- Configuring incomplete, errors occurred!
See also "/tmp/build_opencv/opencv/build/CMakeFiles/CMakeOutput.log".
See also "/tmp/build_opencv/opencv/build/CMakeFiles/CMakeError.log".
make: *** No targets specified and no makefile found.  Stop.

I am running the script from a Docker container on the Xavier. The base image that I am using is

Hmm, I just tried the same thing, and was able to get past these config steps without error. All I had to do was remove references to sudo in FYI I ran ./ 4.4.0

Can you check that you have these libraries present, both from inside and outside the container?

# ls /usr/local/cuda/lib64

libcudadevrt.a                  libnppicom_static.a                       libcusolver_static.a  libnppitc_static.a
libcudart_static.a              libnppidei_static.a                             libcusparse_static.a    libnpps_static.a
libcufft_static.a             liblapack_static.a        libnppif_static.a
libcufft_static_nocallback.a  libmetis_static.a                                 libnppig_static.a
libcufftw_static.a            libnppc_static.a                          libnvgraph_static.a       libnppim_static.a
libculibos.a                  libnppial_static.a                          libnppist_static.a                  libnppicc_static.a              stubs
libcurand_static.a     libnppisu_static.a
# ls /usr/lib/aarch64-linux-gnu/libcu*

/usr/lib/aarch64-linux-gnu/                    /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/                 /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/          /usr/lib/aarch64-linux-gnu/libcudnn_cnn_infer_static_v8.a
/usr/lib/aarch64-linux-gnu/                  /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/               /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/        /usr/lib/aarch64-linux-gnu/libcudnn_cnn_train_static_v8.a
/usr/lib/aarch64-linux-gnu/                      /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/                    /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/                  /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/                     /usr/lib/aarch64-linux-gnu/libcudnn_ops_infer_static_v8.a
/usr/lib/aarch64-linux-gnu/                   /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/               /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/           /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/         /usr/lib/aarch64-linux-gnu/libcudnn_ops_train_static_v8.a
/usr/lib/aarch64-linux-gnu/     /usr/lib/aarch64-linux-gnu/libcudnn_static_v8.a
/usr/lib/aarch64-linux-gnu/libcudnn_adv_infer_static_v8.a  /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/           /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/         /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/     /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/libcudnn_adv_train_static_v8.a  /usr/lib/aarch64-linux-gnu/
/usr/lib/aarch64-linux-gnu/           /usr/lib/aarch64-linux-gnu/

@dusty_nv I have all of them, that is really weird, I am trying again with 4.4.0 from the inside of the container. I’ll keep you update.

@dusty_nv it is now working! I guess the problems was as you mentioned the runtime, I probably forgot to restart the docker deamon after changing the daemon.json.
Thank you!


If anybody is interested in a solution that does not require modifications to the default runtime, I just updated the docker branch of my opencv script and pushed the built images to docker hub. To run, simply:

 $ sudo docker run -it --runtime nvidia
root@44004ed2b1f6:/usr/local/src/build_opencv# python3
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.cuda.printCudaDeviceInfo(0)
*** CUDA Device Query (Runtime API) version (CUDART static linking) *** 

Device count: 1

Device 0: "Xavier"
  CUDA Driver Version / Runtime Version          10.20 / 10.20
  CUDA Capability Major/Minor version number:    7.2
  Total amount of global memory:                 7772 MBytes (8149061632 bytes)
  GPU Clock Speed:                               1.11 GHz
  Max Texture Dimension Size (x,y,z)             1D=(131072), 2D=(131072,65536), 3D=(16384,16384,16384)
  Max Layered Texture Size (dim) x layers        1D=(32768) x 2048, 2D=(32768,32768) x 2048
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per block:           1024
  Maximum sizes of each dimension of a block:    1024 x 1024 x 64
  Maximum sizes of each dimension of a grid:     2147483647 x 65535 x 65535
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and execution:                 Yes with 1 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            Yes
  Support host page-locked memory mapping:       Yes
  Concurrent kernel execution:                   Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support enabled:                No
  Device is using TCC driver mode:               No
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Bus ID / PCI location ID:           0 / 0
  Compute Mode:
      Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) 

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version  = 10.20, CUDA Runtime Version = 10.20, NumDevs = 1


Build instructions are in the repo.

Please report any issues here: