How to make ONNX turned "ON" in OpenCV CMake for CUDA and cuDNN GPU acceleration?

System Information

OpenCV 5 Alpha
OS: Windows 10
Compiler: MVS native compilers using MVS 2022.
CMake version GUI: 3.30.2
CUDA Ver: 12.6
cuDNN ver: 9.6
NVIDIA GPU arch: 8.6 (Ampere).

Detailed description

Having issues where I can not make OpenCV CMake ONNX flag to be turned “ON”.

I am using ONNX Runtime GPU prebuilt binaries “onnxruntime-win-x64-gpu-1.20.1”:
From:
[onnxruntime-win-x64-gpu-1.20.1.zip](Release ONNX Runtime v1.20.1 · microsoft/onnxruntime · GitHub)

I placed the ONNX lib folder to window’s path:
windows_bin/onnxruntime-win-x64-gpu-1.20.1\lib

I enable the ONNX OpenCV CMake Flag:
WITH_ONNX

I placed the root directory of the onnxruntime-win-x64-gpu-1.20.1 on OpenCV ONNX Flag:
`onnxrt_root_dir = windows_bin/onnxruntime-win-x64-gpu-1.20.1

I enabled and installed CUDA and cuDNN properly and every time I click on CMake configure for OpenCV compilation.

OpenCV CMake never accepts or enables ONNX support, here is the OpenCV CMake GUI output after clicking on “configure”:

Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default.
Detected processor: AMD64
Could NOT find AVIF (missing: AVIF_LIBRARY AVIF_INCLUDE_DIR) 
libjpeg-turbo: VERSION = 3.0.3, BUILD = opencv-5.0.0alpha-libjpeg-turbo
CMAKE_ASM_NASM_COMPILER = F:/Program Files/NASM/nasm.exe
CMAKE_ASM_NASM_OBJECT_FORMAT = win64
CMAKE_ASM_NASM_FLAGS =  -DWIN64 -D__x86_64__ 
SIMD extensions: x86_64 (WITH_SIMD = 1)
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.5.0, BUILD = opencv-5.0.0alpha-openjp2-2.5.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
CMake Warning (dev) at cmake/OpenCVFindOpenEXR.cmake:13 (find_package):
  Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
  variables.  Run "cmake --help-policy CMP0144" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  CMake variable OPENEXR_ROOT is set to:

    C:/Deploy

  For compatibility, find_package is ignoring the variable, but code in a
  .cmake module might still use it.
Call Stack (most recent call first):
  cmake/OpenCVFindLibsGrfmt.cmake:324 (include)
  CMakeLists.txt:727 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

found Intel IPP (ICV version): 2021.12.0 [2021.12.0]
at: F:/AI_Componets/OpenCV/build/3rdparty/ippicv/ippicv_win/icv
found Intel IPP Integration Wrappers sources: 2021.12.0
at: F:/AI_Componets/OpenCV/build/3rdparty/ippicv/ippicv_win/iw
Found NVCUVID: F:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/lib/x64/nvcuvid.lib
Found NVCUVENC: F:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/lib/x64/nvencodeapi.lib 
CUDA detected: 12.6
CUDA: Using CUDA_ARCH_BIN=8.6
CUDA: NVCC target flags -gencode;arch=compute_86,code=sm_86;-D_FORCE_INLINES;-gencode;arch=compute_86,code=compute_86
CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.
Module opencv_alphamat disabled because the following dependencies are not found: Eigen
freetype2:   NO
harfbuzz:    NO
Julia not found. Not compiling Julia Bindings. 
Module opencv_ovis disabled because OGRE3D was not found
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
Tesseract:   NO
Module opencv_aruco disabled because opencv_calib3d dependency can't be resolved!
Module opencv_bgsegm disabled because opencv_calib3d dependency can't be resolved!
Module opencv_ccalib disabled because opencv_calib3d dependency can't be resolved!
Module opencv_cudafeatures2d disabled because opencv_features2d dependency can't be resolved!
Module opencv_cudastereo disabled because opencv_calib3d dependency can't be resolved!
Module opencv_datasets disabled because opencv_ml dependency can't be resolved!
Module opencv_face disabled because opencv_calib3d dependency can't be resolved!
Module opencv_mcc disabled because opencv_calib3d dependency can't be resolved!
Module opencv_optflow disabled because opencv_calib3d dependency can't be resolved!
Module opencv_quality disabled because opencv_ml dependency can't be resolved!
Module opencv_rapid disabled because opencv_calib3d dependency can't be resolved!
Module opencv_rgbd disabled because opencv_calib3d dependency can't be resolved!
Module opencv_saliency disabled because opencv_features2d dependency can't be resolved!
Module opencv_shape disabled because opencv_calib3d dependency can't be resolved!
Module opencv_stereo disabled because opencv_features2d dependency can't be resolved!
Module opencv_structured_light disabled because opencv_calib3d dependency can't be resolved!
Module opencv_superres disabled because opencv_optflow dependency can't be resolved!
Module opencv_text disabled because opencv_ml dependency can't be resolved!
Module opencv_videostab disabled because opencv_features2d dependency can't be resolved!
Module opencv_xfeatures2d disabled because opencv_features2d dependency can't be resolved!
Module opencv_ximgproc disabled because opencv_calib3d dependency can't be resolved!
Module opencv_calib disabled because opencv_stereo dependency can't be resolved!
Module opencv_cudaoptflow disabled because opencv_optflow dependency can't be resolved!
Processing WORLD modules...
    module opencv_cudev...
    module opencv_core...
Excluding from source files list: <BUILD>/modules/world/test/test_intrin256.lasx.cpp
    module opencv_cudaarithm...
    module opencv_flann...
    module opencv_imgproc...
UNIFONT: Downloading WenQuanYiMicroHei.ttf.gz from https://raw.githubusercontent.com/vpisarev/opencv_3rdparty/cc7d85179d69a704bee209aa37ce8a657f2f8b34/WenQuanYiMicroHei.ttf.gz
Unicode font has been downloaded successfully.
    module opencv_intensity_transform...
    module opencv_line_descriptor...
    module opencv_phase_unwrapping...
    module opencv_plot...
    module opencv_reg...
    module opencv_signal...
    module opencv_surface_matching...
    module opencv_cudafilters...
    module opencv_cudaimgproc...
    module opencv_cudawarping...
    module opencv_dnn...
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': F:/AI_Componets/OpenCV/opencv-5.0.0-alpha/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
    module opencv_dnn_superres...
    module opencv_features...
    module opencv_fuzzy...
    module opencv_hfs...
    module opencv_imgcodecs...
imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326
    module opencv_photo...
    module opencv_videoio...
    module opencv_xphoto...
    module opencv_3d...
3d: Eigen support is disabled. Eigen is Required for Posegraph optimization
    module opencv_cudacodec...
    module opencv_highgui...
highgui: using builtin backend: WIN32UI
    module opencv_objdetect...
    module opencv_video...
    module opencv_wechat_qrcode...
wechat_qrcode: Downloading detect.caffemodel from https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/a8b69ccc738421293254aec5ddb38bd523503252/detect.caffemodel
wechat_qrcode: Downloading detect.prototxt from https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/a8b69ccc738421293254aec5ddb38bd523503252/detect.prototxt
wechat_qrcode: Downloading sr.caffemodel from https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/a8b69ccc738421293254aec5ddb38bd523503252/sr.caffemodel
wechat_qrcode: Downloading sr.prototxt from https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/a8b69ccc738421293254aec5ddb38bd523503252/sr.prototxt
    module opencv_xobjdetect...
    module opencv_bioinspired...
    module opencv_cudabgsegm...
    module opencv_cudalegacy...
    module opencv_cudaobjdetect...
    module opencv_dnn_objdetect...
    module opencv_dpm...
    module opencv_stitching...
    module opencv_tracking...
Processing WORLD modules... DONE
Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
Excluding from source files list: <BUILD>/modules/world/layers/layers_common.rvv.cpp
Excluding from source files list: <BUILD>/modules/world/layers/layers_common.lasx.cpp
Excluding from source files list: <BUILD>/modules/world/int8layers/layers_common.rvv.cpp
Excluding from source files list: <BUILD>/modules/world/int8layers/layers_common.lasx.cpp
Excluding from source files list: <BUILD>/modules/world/layers/cpu_kernels/conv_block.neon.cpp
Excluding from source files list: <BUILD>/modules/world/layers/cpu_kernels/conv_block.neon_fp16.cpp
Excluding from source files list: <BUILD>/modules/world/layers/cpu_kernels/conv_depthwise.rvv.cpp
Excluding from source files list: <BUILD>/modules/world/layers/cpu_kernels/conv_depthwise.lasx.cpp
Excluding from source files list: <BUILD>/modules/world/layers/cpu_kernels/fast_gemm_kernels.neon.cpp
Excluding from source files list: <BUILD>/modules/world/layers/cpu_kernels/fast_gemm_kernels.lasx.cpp
Use autogenerated whitelist F:/AI_Componets/OpenCV/build/modules/js_bindings_generator/whitelist.json
Found 'misc' Python modules from F:/AI_Componets/OpenCV/opencv-5.0.0-alpha/modules/python/package/extra_modules
Found 'mat_wrapper;utils' Python modules from F:/AI_Componets/OpenCV/opencv-5.0.0-alpha/modules/core/misc/python/package
Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 

General configuration for OpenCV 5.0.0alpha =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            F:/AI_Componets/OpenCV/opencv_contrib/modules
    Version control (extra):     4.10.0-51-g3e776c87

  Platform:
    Timestamp:                   2024-12-30T20:01:29Z
    Host:                        Windows 10.0.19045 AMD64
    CMake:                       3.30.2
    CMake generator:             Visual Studio 17 2022
    CMake build tool:            F:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
    MSVC:                        1942
    Configuration:               Debug Release
    Algorithm Hint:              ALGO_HINT_ACCURATE

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (18 files):         + SSSE3 SSE4_1
      SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      AVX (9 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16
      AVX2 (39 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16 AVX2 FMA3
      AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16 AVX2 FMA3 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                17
    C++ Compiler:                F:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe  (ver 19.42.34435.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast    /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP -openmp  /O2 /Ob2 /DNDEBUG 
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast    /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP -openmp  /Zi /Ob0 /Od /RTC1 
    C Compiler:                  F:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast    /MP -openmp   /O2 /Ob2 /DNDEBUG 
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast    /MP -openmp /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64  /INCREMENTAL:NO 
    Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL 
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:F:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/lib/x64
    3rdparty dependencies:

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

  Windows RT support:            NO

  GUI: 
    Win32 UI:                    YES
    OpenGL support:              YES (opengl32 glu32)
    Built-in Unicode font:       YES

  Media I/O: 
    ZLib:                        build (ver 1.3.1)
    JPEG:                        build-libjpeg-turbo (ver 3.0.3-70)
      SIMD Support Request:      YES
      SIMD Support:              YES
    WEBP:                        build (ver encoder: 0x020f)
    AVIF:                        NO
    PNG:                         build (ver 1.6.43)
      SIMD Support Request:      YES
      SIMD Support:              YES (Intel SSE)
    TIFF:                        build (ver 42 - 4.6.0)
    JPEG 2000:                   build (ver 2.5.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (61.19.100)
      avformat:                  YES (61.7.100)
      avutil:                    YES (59.39.100)
      swscale:                   YES (8.3.100)
      avresample:                NO
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            OpenMP

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2021.12.0 [2021.12.0]
           at:                   F:/AI_Componets/OpenCV/build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2021.12.0)
              at:                F:/AI_Componets/OpenCV/build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      YES (libclapack 3.9.0)
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)
    Flatbuffers:                 builtin/3rdparty (23.5.9)

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

  cuDNN:                         YES (ver 9.6.0)

  OpenCL:                        YES (SVM NVD3D11)
    Include path:                F:/AI_Componets/OpenCV/opencv-5.0.0-alpha/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  **ONNX:                          NO**

  Python (for build):            C:/Python312/python.exe

  Install to:                    F:/AI_Componets/OpenCV/build/install
-----------------------------------------------------------------

Configuring done (71.2s)

What could be issue that ONNX shows it is not “ON”?

Thanks for any advice.

Alright, I have resolved this.

There are more hidden keywords for ONNX which needs to be dealt with:

I have successfully compiled OpenCV 5.0.0-Alpha with CUDA 12.6 , cuDNN 9.6 , ONNX Runtime 1.20.1 (GPU version, prebuilt release) and OpenCV Extra Contrib 5.0.0-Alpha.

Make sure to uncheck build_opencv_world, as this threw errors conflicting with opencv contrib xobjdetect module (maybe due to the fact I am using latest opencv version).

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