Missing CUDA support for opencv-python build from jetson-ai-lab (original) (raw)

April 24, 2025, 10:36am 1

I’m using a Jetson Orin Nano and have created a docker image using nvcr.io/nvidia/l4t-cuda:12.6.11-runtime as a base image and installed opencv-python from here: https://pypi.jetson-ai-lab.dev/jp6/cu126/+f/e6d/a8e91fd7e5f79/opencv_python-4.11.0-py3-none-any.whl#sha256=e6da8e91fd7e5f79509500808b38b616af4d3a8da4a8e0a3de6fa1d4da2f4fc8

However, testing gives:
$ python3
Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
import cv2
print(cv2.cuda.getCudaEnabledDeviceCount())
0

I checked the availability of the GPU inside the container using the deviceQuery executable.

files.zip (9.3 KB)

AastaLLL April 25, 2025, 4:21am 3

Hi,

Could you double-check if you are using the installed OpenCV instead of the default one first?

>>> print(cv2.getBuildInformation())

Thanks.

naisy April 25, 2025, 7:31am 4

The container nvcr.io/nvidia/l4t-cuda:12.6.11-runtime does not include libcudnn.so.9, which is required by /usr/local/lib/python3.10/dist-packages/cv2/cv2.abi3.so.

As an alternative, you can use the nvcr.io/nvidia/deepstream-l4t:7.1-triton-multiarch container. Below is a description of how to use it.

docker run

sudo docker run --gpus all -it -v /tmp/:/tmp/ nvcr.io/nvidia/deepstream-l4t:7.1-triton-multiarch /bin/bash

install opencv

pip install \
  opencv-contrib-python==4.11.0.86 \
  opencv-python==4.11.0 \
--index-url https://pypi.jetson-ai-lab.dev/jp6/cu126/+simple/

check missing libs

ldd /usr/local/lib/python3.10/dist-packages/cv2/cv2.abi3.so | grep "not found"

install libs

apt update
apt install -y \
  libtesseract-dev \
  libtbb2 \
  libmpg123-0 \
  libatlas3-base \
  libgtk-3-0 \
  libavcodec-extra58 \
  libavformat-dev \
  libswscale-dev

apt install --reinstall -y \
  libavutil56 \
  libvpx7 \
  libmp3lame0 \
  libx264-163 \
  libx265-199 \
  libxvidcore4

check missing libs

ldd /usr/local/lib/python3.10/dist-packages/cv2/cv2.abi3.so | grep "not found"

check cv2

python3 -c "import cv2; print(cv2.cuda.getCudaEnabledDeviceCount()); print(cv2.getBuildInformation())"
1

General configuration for OpenCV 4.11.0 =====================================
  Version control:               4.11.0

  Extra modules:
    Location (extra):            /opt/opencv-python/opencv_contrib/modules
    Version control (extra):     4.11.0

  Platform:
    Timestamp:                   2025-03-05T16:32:02Z
    Host:                        Linux 5.15.148-tegra aarch64
    CMake:                       3.31.6
    CMake generator:             Ninja
    CMake build tool:            /usr/local/bin/ninja
    Configuration:               RELEASE
    Algorithm Hint:              ALGO_HINT_ACCURATE

  CPU/HW features:
    Baseline:                    NEON FP16
      requested:                 DETECT
      required:                  NEON
    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:                /usr/bin/c++  (ver 11.4.0)
    C++ flags (Release):         -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):           -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:                  /usr/bin/cc
    C flags (Release):           -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):             -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):      -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
    Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          /usr/lib/aarch64-linux-gnu/liblapack.so /usr/lib/aarch64-linux-gnu/libcblas.so /usr/lib/aarch64-linux-gnu/libatlas.so /usr/lib/aarch64-linux-gnu/libjpeg.so /usr/lib/aarch64-linux-gnu/libpng.so /usr/lib/aarch64-linux-gnu/libz.so Iconv::Iconv m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
    3rdparty dependencies:       libprotobuf ade ittnotify libwebp libtiff libopenjp2 IlmImf tegra_hal

  OpenCV modules:
    To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape signal stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    freetype world
    Disabled by dependency:      -
    Unavailable:                 cannops cvv fastcv hdf java julia matlab ovis python2 sfm ts viz
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         YES

  GUI:                           GTK3
    GTK+:                        YES (ver 3.24.33)
    VTK support:                 NO

  Media I/O: 
    ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
    JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
    WEBP:                        build (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
    AVIF:                        NO
    PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.6.0)
    JPEG 2000:                   build (ver 2.5.0)
    OpenEXR:                     build (ver 2.3.0)
    GIF:                         NO
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    FFMPEG:                      YES
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                NO
    GStreamer:                   YES (1.20.3)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2020.3 interface 11103)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Lapack:                      YES (/usr/lib/aarch64-linux-gnu/liblapack.so /usr/lib/aarch64-linux-gnu/libcblas.so /usr/lib/aarch64-linux-gnu/libatlas.so)
    Eigen:                       YES (ver 3.4.0)
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.19.1)
    Flatbuffers:                 builtin/3rdparty (23.5.9)

  NVIDIA CUDA:                   YES (ver 12.6, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             87
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 9.4.0)

  Python 3:
    Interpreter:                 /usr/bin/python3.10 (ver 3.10.12)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.10.so (ver 3.10.12)
    Limited API:                 YES (ver 0x03060000)
    numpy:                       /tmp/pip-build-env-ytul3b_k/overlay/local/lib/python3.10/dist-packages/numpy/_core/include (ver 2.2.3)
    install path:                python/cv2/python-3

  Python (for build):            /usr/bin/python3.10

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

  Install to:                    /opt/opencv-python/_skbuild/linux-aarch64-3.10/cmake-install
-----------------------------------------------------------------

example code

vi test.py
import cv2
import os

input_file = "/opt/nvidia/deepstream/deepstream-7.1/samples/streams/sample_720p.jpg"
output_file = "/tmp/flipped_output.jpg"

# Load the image from disk (on CPU)
image = cv2.imread(input_file, cv2.IMREAD_COLOR)
if image is None:
    raise RuntimeError(f"Failed to load the image file: {input_file}")

# Upload the image to GPU memory
gpu_image = cv2.cuda_GpuMat()
gpu_image.upload(image)

# Flip the image horizontally on the GPU (flipCode = 1)
gpu_flipped = cv2.cuda.flip(gpu_image, 1)

# Download the flipped image from GPU to CPU
flipped_image = gpu_flipped.download()

# Save the result as a new file
cv2.imwrite(output_file, flipped_image)
print(f"Flipped image saved to: {output_file}")

run test.py

python3 test.py

The output will be saved as /tmp/flipped_output.jpg.

Since the Docker container is started with the -v /tmp/:/tmp/ option, you can access the result directly from the Jetson Orin Nano.

This gives me the following:

\n
\n

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

Extra modules:
Location (extra): /io/opencv_contrib/modules
Version control (extra): 4.11.0

Platform:
Timestamp: 2025-01-16T09:59:40Z
Host: Linux 6.8.0-51-generic aarch64
CMake: 3.31.1
CMake generator: Unix Makefiles
CMake build tool: /bin/gmake
Configuration: Release
Algorithm Hint: ALGO_HINT_ACCURATE

CPU/HW features:
Baseline: NEON FP16
requested: DETECT
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::Test Qt5::Concurrent /usr/local/lib/libpng.so /usr/lib64/libz.so Qt5::Core Qt5::Gui Qt5::Widgets Iconv::Iconv dl m pthread rt
3rdparty dependencies: libprotobuf ade ittnotify libjpeg-turbo libwebp libtiff libopenjp2 IlmImf tegra_hal

OpenCV modules:
To be built: aruco bgsegm bioinspired calib3d ccalib core cvv datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape signal stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
Disabled: world
Disabled by dependency: -
Unavailable: alphamat cannops cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev fastcv freetype hdf java julia matlab ovis python2 sfm ts viz
Applications: -
Documentation: NO
Non-free algorithms: NO

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

Media I/O:
ZLib: /usr/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 decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
AVIF: NO
PNG: /usr/local/lib/libpng.so (ver 1.6.44)
TIFF: build (ver 42 - 4.6.0)
JPEG 2000: build (ver 2.5.0)
OpenEXR: build (ver 2.3.0)
GIF: NO
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES

Video I/O:
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))
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.20)
Libraries: libpython3.9m.a (ver 3.9.20)
Limited API: YES (ver 0x03060000)
numpy: /home/ci/.local/lib/python3.9/site-packages/numpy/_core/include (ver 2.0.2)
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

\n
\n

So install path is python/cv2/python-3. What makes me suspicious is that all the cuda modules are listed as unavailable.

I doubt that. Running strace -o file.txt python3 -c “import cv2; cv2.cuda.getCudaEnabledDeviceCount()” does not mention cudnn.

AastaLLL April 28, 2025, 7:15am 7

Hi,

Do you use Python3.9?
The package shared above is built for default Python 3.10.

Thanks.

No I’m using the default python 3.10.12. I’m running this in a docker container for which I provided the image.

I assume that:

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

specifies how opencv was built, neither the interpreter nor the numpy path exist in the container.

Hi, are there any updates?