OpenCV Python - unable to access CUDA modules

I am only able to access the following CUDA modules in Python:

cv2.cuda_BufferPool
cv2.cuda_DeviceInfo
cv2.cuda_Event
cv2.cuda_GpuMat
cv2.cuda_GpuMatAllocator
cv2.cuda_HostMem
cv2.cuda_Stream
cv2.cuda_TargetArchs

Other modules such as cv2.cuda.cvtColor , cv2.cuda_FarnebackOpticalFlow , etc are missing

More information:

I have used PIP to build the wheel file successfully, and I have installed this wheel file as opencv-contrib-python, with version 4.6.0+4638ce5 , it is the only version of OpenCV I have installed
As an aside,I had to install via the wheel method because using PIP with the --no-binary flag will cause it to attempt installation of Numpy 1.21.2 , which fails to build

This is the configuration of the build process

  -- General configuration for OpenCV 4.6.0 =====================================
  --   Version control:               4.6.0
  --
  --   Extra modules:
  --     Location (extra):            C:/opencv-python/opencv_contrib/modules
  --     Version control (extra):     4.6.0
  --
  --   Platform:
  --     Timestamp:                   2022-09-07T06:57:52Z
  --     Host:                        Windows 10.0.22000 AMD64
  --     CMake:                       3.24.1
  --     CMake generator:             Visual Studio 17 2022
  --     CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
  --     MSVC:                        1932
  --     Configuration:               Debug Release
  --
  --   CPU/HW features:
  --     Baseline:                    SSE SSE2 SSE3
  --       requested:                 SSE3
  --     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
  --       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
  --       SSE4_1 (16 files):         + SSSE3 SSE4_1
  --       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
  --       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
  --       AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
  --       AVX2 (31 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
  --       AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
  --
  --   C/C++:
  --     Built as dynamic libs?:      NO
  --     C++ standard:                11
  --     C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe  (ver 19.32.31332.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 /MP  /MT /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 /MP  /MTd /Zi /Ob0 /Od /RTC1
  --     C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/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   /MT /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 /MTd /Zi /Ob0 /Od /RTC1
  --     Linker flags (Release):      /machine:x64  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
  --     Linker flags (Debug):        /machine:x64  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
  --     ccache:                      NO
  --     Precompiled headers:         YES
  --     Extra dependencies:          wsock32 comctl32 gdi32 ole32 setupapi ws2_32 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:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib/x64 -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib
  --     3rdparty dependencies:       libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib quirc ippiw ippicv
  --
  --   OpenCV modules:
  --     To be built:                 aruco barcode 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 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 cvv freetype hdf java julia matlab ovis python2 sfm ts viz
  --     Applications:                -
  --     Documentation:               NO
  --     Non-free algorithms:         YES
  --
  --   Windows RT support:            NO
  --
  --   GUI:                           WIN32UI
  --     Win32 UI:                    YES
  --     VTK support:                 NO
  --
  --   Media I/O:
  --     ZLib:                        build (ver 1.2.12)
  --     JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
  --     WEBP:                        build (ver encoder: 0x020f)
  --     PNG:                         build (ver 1.6.37)
  --     TIFF:                        build (ver 42 - 4.2.0)
  --     JPEG 2000:                   build (ver 2.4.0)
  --     OpenEXR:                     build (ver 2.3.0)
  --     HDR:                         YES
  --     SUNRASTER:                   YES
  --     PXM:                         YES
  --     PFM:                         YES
  --
  --   Video I/O:
  --     DC1394:                      NO
  --     FFMPEG:                      YES (prebuilt binaries)
  --       avcodec:                   YES (58.134.100)
  --       avformat:                  YES (58.76.100)
  --       avutil:                    YES (56.70.100)
  --       swscale:                   YES (5.9.100)
  --       avresample:                YES (4.0.0)
  --     GStreamer:                   NO
  --     DirectShow:                  YES
  --     Media Foundation:            YES
  --       DXVA:                      YES
  --
  --   Parallel framework:            Concurrency
  --
  --   Trace:                         YES (with Intel ITT)
  --
  --   Other third-party libraries:
  --     Intel IPP:                   2020.0.0 Gold [2020.0.0]
  --            at:                   C:/opencv-python/_skbuild/win-amd64-3.10/cmake-build/3rdparty/ippicv/ippicv_win/icv
  --     Intel IPP IW:                sources (2020.0.0)
  --               at:                C:/opencv-python/_skbuild/win-amd64-3.10/cmake-build/3rdparty/ippicv/ippicv_win/iw
  --     Lapack:                      NO
  --     Eigen:                       NO
  --     Custom HAL:                  NO
  --     Protobuf:                    build (3.19.1)
  --
  --   NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS FAST_MATH)
  --     NVIDIA GPU arch:             61
  --     NVIDIA PTX archs:
  --
  --   cuDNN:                         YES (ver 8.4.1)
  --
  --   OpenCL:                        YES (NVD3D11)
  --     Include path:                C:/opencv-python/opencv/3rdparty/include/opencl/1.2
  --     Link libraries:              Dynamic load
  --
  --   Python 3:
  --     Interpreter:                 C:\Users\fdsahfjksda\AppData\Local\Programs\Python\Python310\python.exe (ver 3.10.7)
  --     Libraries:                   C:/Users/fdsahfjksda/AppData/Local/Programs/Python/Python310/libs/python310.lib (ver 3.10.7)
  --     numpy:                       C:/Users/fdsahfjksda/AppData/Local/Temp/pip-build-env-8zwk4n9l/overlay/Lib/site-packages/numpy/core/include (ver 1.23.2)
  --     install path:                python/cv2/python-3
  --
  --   Python (for build):            C:\Users\fdsahfjksda\AppData\Local\Programs\Python\Python310\python.exe
  --
  --   Java:
  --     ant:                         NO
  --     JNI:                         NO
  --     Java wrappers:               NO
  --     Java tests:                  NO
  --
  --   Install to:                    C:/opencv-python/_skbuild/win-amd64-3.10/cmake-install
  -- -----------------------------------------------------------------

That’s strange. Just to confirm the build information is the output from within python? If so do the c++ cuda tests run successfully?

the only thing I did was enter ‘pip wheel . – verbose’ , and it automatically called Cmake

by ‘c++ cuda tests’ do you mean the .exe files in the opencv\build\bin\Release directory?

I had to move them to the opencv-extra\testdata\gpu directory for them to find the files they need to run

this is the result of running opencv_test_cudaoptflow

C:\opencv-python\opencv_extra\testdata\gpu>opencv_test_cudaoptflow

Available options besides google test option:
Usage: opencv_test_cudaoptflow [params]

        --cuda_device (value:-1)
                CUDA device on which tests will be executed (-1 means all devices)
        -h, --help (value:false)
                Print help info

Run tests on all supported CUDA devices

[----------]
[ GPU INFO ]    Run on OS Windows x64.
[----------]
*** CUDA Device Query (Runtime API) version (CUDART static linking) ***

Device count: 1

Device 0: "NVIDIA GeForce GTX 1080"
  CUDA Driver Version / Runtime Version          11.70 / 11.70
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 8192 MBytes (8589672448 bytes)
  GPU Clock Speed:                               1.73 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:                     Yes
  Integrated GPU sharing Host Memory:            No
  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:           1 / 0
  Compute Mode:
      Default (multiple host threads can use ::cudaSetDevice() with device simultaneously)

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

CTEST_FULL_OUTPUT
OpenCV version: 4.6.0
OpenCV VCS version: 4.6.0
Build type: Debug Release
WARNING: build value differs from runtime: Release
Compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe  (ver 19.32.31332.0)
Parallel framework: ms-concurrency (nthreads=8)
CPU features: SSE? SSE2? SSE3? *SSE4.1? *SSE4.2? *FP16? *AVX? *AVX2? *AVX512-SKX?
Intel(R) IPP version: disabled
OpenCL is disabled
TEST: Skip tests with tags: 'mem_6gb', 'verylong'
[==========] Running 46 tests from 6 test cases.
[----------] Global test environment set-up.
[----------] 2 tests from CUDA_OptFlow/BroxOpticalFlow
[ RUN      ] CUDA_OptFlow/BroxOpticalFlow.Regression/0, where GetParam() = NVIDIA GeForce GTX 1080
[       OK ] CUDA_OptFlow/BroxOpticalFlow.Regression/0 (321 ms)
[ RUN      ] CUDA_OptFlow/BroxOpticalFlow.OpticalFlowNan/0, where GetParam() = NVIDIA GeForce GTX 1080
[       OK ] CUDA_OptFlow/BroxOpticalFlow.OpticalFlowNan/0 (123 ms)
[----------] 2 tests from CUDA_OptFlow/BroxOpticalFlow (445 ms total)

[----------] 12 tests from CUDA_OptFlow/PyrLKOpticalFlow
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/0, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(1), DataType(0))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/0 (82 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/1, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(1), DataType(2))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/1 (20 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/2, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(1), DataType(4))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/2 (20 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/3, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(1), DataType(5))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/3 (18 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/4, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(3), DataType(0))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/4 (26 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/5, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(3), DataType(2))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/5 (25 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/6, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(3), DataType(4))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/6 (28 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/7, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(3), DataType(5))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/7 (27 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/8, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(4), DataType(0))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/8 (22 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/9, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(4), DataType(2))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/9 (24 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/10, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(4), DataType(4))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/10 (28 ms)
[ RUN      ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/11, where GetParam() = (NVIDIA GeForce GTX 1080, Chan(4), DataType(5))
[       OK ] CUDA_OptFlow/PyrLKOpticalFlow.Sparse/11 (25 ms)
[----------] 12 tests from CUDA_OptFlow/PyrLKOpticalFlow (354 ms total)

[----------] 24 tests from CUDA_OptFlow/FarnebackOpticalFlow
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/0, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.3), PolyN(5), 0, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/0 (109 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/1, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.3), PolyN(5), 0, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/1 (110 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/2, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.3), PolyN(5), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/2 (124 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/3, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.3), PolyN(5), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/3 (124 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/4, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.3), PolyN(7), 0, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/4 (109 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/5, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.3), PolyN(7), 0, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/5 (120 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/6, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.3), PolyN(7), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/6 (123 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/7, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.3), PolyN(7), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/7 (129 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/8, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.5), PolyN(5), 0, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/8 (121 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/9, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.5), PolyN(5), 0, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/9 (132 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/10, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.5), PolyN(5), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/10 (139 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/11, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.5), PolyN(5), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/11 (147 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/12, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.5), PolyN(7), 0, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/12 (125 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/13, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.5), PolyN(7), 0, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/13 (137 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/14, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.5), PolyN(7), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/14 (143 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/15, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.5), PolyN(7), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/15 (152 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/16, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.8), PolyN(5), 0, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/16 (205 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/17, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.8), PolyN(5), 0, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/17 (223 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/18, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.8), PolyN(5), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/18 (247 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/19, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.8), PolyN(5), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/19 (254 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/20, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.8), PolyN(7), 0, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/20 (221 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/21, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.8), PolyN(7), 0, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/21 (233 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/22, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.8), PolyN(7), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(false))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/22 (251 ms)
[ RUN      ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/23, where GetParam() = (NVIDIA GeForce GTX 1080, PyrScale(0.8), PolyN(7), 0|OPTFLOW_FARNEBACK_GAUSSIAN, UseInitFlow(true))
[       OK ] CUDA_OptFlow/FarnebackOpticalFlow.Accuracy/23 (271 ms)
[----------] 24 tests from CUDA_OptFlow/FarnebackOpticalFlow (3971 ms total)

[----------] 4 tests from CUDA_OptFlow/OpticalFlowDual_TVL1
[ RUN      ] CUDA_OptFlow/OpticalFlowDual_TVL1.Accuracy/0, where GetParam() = (NVIDIA GeForce GTX 1080, Gamma(0))
[       OK ] CUDA_OptFlow/OpticalFlowDual_TVL1.Accuracy/0 (347 ms)
[ RUN      ] CUDA_OptFlow/OpticalFlowDual_TVL1.Accuracy/1, where GetParam() = (NVIDIA GeForce GTX 1080, Gamma(1))
[       OK ] CUDA_OptFlow/OpticalFlowDual_TVL1.Accuracy/1 (456 ms)
[ RUN      ] CUDA_OptFlow/OpticalFlowDual_TVL1.Async/0, where GetParam() = (NVIDIA GeForce GTX 1080, Gamma(0))
[       OK ] CUDA_OptFlow/OpticalFlowDual_TVL1.Async/0 (388 ms)
[ RUN      ] CUDA_OptFlow/OpticalFlowDual_TVL1.Async/1, where GetParam() = (NVIDIA GeForce GTX 1080, Gamma(1))
[       OK ] CUDA_OptFlow/OpticalFlowDual_TVL1.Async/1 (439 ms)
[----------] 4 tests from CUDA_OptFlow/OpticalFlowDual_TVL1 (1632 ms total)

[----------] 2 tests from CUDA_OptFlow/NvidiaOpticalFlow_1_0
[ RUN      ] CUDA_OptFlow/NvidiaOpticalFlow_1_0.Regression/0, where GetParam() = NVIDIA GeForce GTX 1080
unknown file: error: C++ exception with description "Current configuration is not supported" thrown in the test body.
[  FAILED  ] CUDA_OptFlow/NvidiaOpticalFlow_1_0.Regression/0, where GetParam() = NVIDIA GeForce GTX 1080 (80 ms)
[ RUN      ] CUDA_OptFlow/NvidiaOpticalFlow_1_0.OpticalFlowNan/0, where GetParam() = NVIDIA GeForce GTX 1080
unknown file: error: C++ exception with description "Current configuration is not supported" thrown in the test body.
[  FAILED  ] CUDA_OptFlow/NvidiaOpticalFlow_1_0.OpticalFlowNan/0, where GetParam() = NVIDIA GeForce GTX 1080 (122 ms)
[----------] 2 tests from CUDA_OptFlow/NvidiaOpticalFlow_1_0 (204 ms total)

[----------] 2 tests from CUDA_OptFlow/NvidiaOpticalFlow_2_0
[ RUN      ] CUDA_OptFlow/NvidiaOpticalFlow_2_0.Regression/0, where GetParam() = NVIDIA GeForce GTX 1080
unknown file: error: C++ exception with description "Current configuration is not supported" thrown in the test body.
[  FAILED  ] CUDA_OptFlow/NvidiaOpticalFlow_2_0.Regression/0, where GetParam() = NVIDIA GeForce GTX 1080 (109 ms)
[ RUN      ] CUDA_OptFlow/NvidiaOpticalFlow_2_0.OpticalFlowNan/0, where GetParam() = NVIDIA GeForce GTX 1080
unknown file: error: C++ exception with description "Current configuration is not supported" thrown in the test body.
[  FAILED  ] CUDA_OptFlow/NvidiaOpticalFlow_2_0.OpticalFlowNan/0, where GetParam() = NVIDIA GeForce GTX 1080 (110 ms)
[----------] 2 tests from CUDA_OptFlow/NvidiaOpticalFlow_2_0 (222 ms total)

[----------] Global test environment tear-down
[ SKIPSTAT ] 4 tests skipped
[ SKIPSTAT ] TAG='skip_other' skip 4 tests
[==========] 46 tests from 6 test cases ran. (6834 ms total)
[  PASSED  ] 42 tests.
[  FAILED  ] 4 tests, listed below:
[  FAILED  ] CUDA_OptFlow/NvidiaOpticalFlow_1_0.Regression/0, where GetParam() = NVIDIA GeForce GTX 1080
[  FAILED  ] CUDA_OptFlow/NvidiaOpticalFlow_1_0.OpticalFlowNan/0, where GetParam() = NVIDIA GeForce GTX 1080
[  FAILED  ] CUDA_OptFlow/NvidiaOpticalFlow_2_0.Regression/0, where GetParam() = NVIDIA GeForce GTX 1080
[  FAILED  ] CUDA_OptFlow/NvidiaOpticalFlow_2_0.OpticalFlowNan/0, where GetParam() = NVIDIA GeForce GTX 1080

 4 FAILED TESTS

I can’t remember the exact command and don’t have access to python at the moment but something similar to the below should tell you the build information for the version of OpenCV you have installed in python

print(cv2.getBuildInformation())
1 Like

when I enter ‘pip list’ , the only OpenCV entry it shows is opencv-contrib-python , version number 4.6.0+4638ce5

I am encountering another problem, now the CMake arguments for pointing to the opencv-contrib folder is throwing away the slashes
in my Windows Environment Variable ‘CMAKE_ARGS’ , the value is :
-DOPENCV_EXTRA_MODULES_PATH:PATH=C:\opencv_contrib\modules

this results in:

  CMake Error at cmake/OpenCVModule.cmake:274 (message):
    No modules has been found: C:opencv_contribmodules

cmake does like to use forward slashes, even on Windows. Windows is okay with that.

if you see backslashes disappearing but don’t want them to, escape them.

I think I solved it by enclosing the path to the directory in double quotes

I have edited my posts for brevity. I wish that OpenCV Python would just use the latest version of Numpy automatically, instead of me having edit the pyproject.toml file and specify the Numpy path on my computer as a Cmake argument

the problem seems to be that it’s looking for Numpy in C:/Users/fdsahfjksda/AppData/Local/Temp/pip-build-env-ng3i1j4c/overlay/Lib/site-packages/numpy/core/include
instead of the directory i specified in the CMAKE_ARGS

::edit:: I found that the CMAKE_ARGS values must match the names within CMakeLists.txt, in this case

  status("    numpy:"         PYTHON3_NUMPY_INCLUDE_DIRS THEN "${PYTHON3_NUMPY_INCLUDE_DIRS} (ver ${PYTHON3_NUMPY_VERSION})" ELSE "NO (Python3 wrappers can not be generated)")

so I changed it from ‘PYTHON_NUMPY_INCLUDE_DIRS’ to ‘PYTHON3_NUMPY_INCLUDE_DIRS’ , and now the CMake configuration is pointing to the correct directory

Back on topic, I have successfully built OpenCV Python using the latest git repository clone


and the problem is still not solved, I am still only getting what seems like only the core CUDA classes:
image

Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
import cv2
print(cv2.getBuildInformation())

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

  Extra modules:
    Location (extra):            C:/opencv-python/opencv_contrib/modules
    Version control (extra):     4.6.0

  Platform:
    Timestamp:                   2022-09-09T19:51:33Z
    Host:                        Windows 10.0.22000 AMD64
    CMake:                       3.24.1
    CMake generator:             Visual Studio 17 2022
    CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
    MSVC:                        1932
    Configuration:               Debug Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (16 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (31 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      NO
    C++ standard:                11
    C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe  (ver 19.32.31332.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 /MP  /MT /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 /MP  /MTd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/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   /MT /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 /MTd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
    Linker flags (Debug):        /machine:x64  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          wsock32 comctl32 gdi32 ole32 setupapi ws2_32 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:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib/x64 -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib
    3rdparty dependencies:       libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib quirc ippiw ippicv

  OpenCV modules:
    To be built:                 aruco barcode 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 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 cvv freetype hdf java julia matlab ovis python2 sfm ts viz
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         YES

  Windows RT support:            NO

  GUI:                           WIN32UI
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.12)
    JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   C:/opencv-python/_skbuild/win-amd64-3.10/cmake-build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/opencv-python/_skbuild/win-amd64-3.10/cmake-build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)

  NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             61
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 8.4.1)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/opencv-python/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 C:\Users\fdsahfjksda\AppData\Local\Programs\Python\Python310\python.exe (ver 3.10.7)
    Libraries:                   C:/Users/fdsahfjksda/AppData/Local/Programs/Python/Python310/libs/python310.lib (ver 3.10.7)
    numpy:                       C:/Users/fdsahfjksda/AppData/Local/Programs/Python/Python310/Lib/site-packages/numpy/core/include (ver 1.23.3)
    install path:                python/cv2/python-3

  Python (for build):            C:\Users\fdsahfjksda\AppData\Local\Programs\Python\Python310\python.exe

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

  Install to:                    C:/opencv-python/_skbuild/win-amd64-3.10/cmake-install
-----------------------------------------------------------------



Pay attention to this line

OpenCV modules:
    To be built:                 aruco barcode 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 stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto

none of these modules are accessible in Python for me, and they are all OpenCV-Contrib modules… They all get processed by Cmake , and there are .lib.recipe and .lastbuildstate files which are generated for all of them

Furthermore, I have rebuilt OpenCV Python with the ENABLE_CONTRIB=1 flag, and it has resulted in a wheel with the ‘opencv_contrib_python’ name
However, when I try to use PIP to install it, this is the result

c:\Users\fdsahfjksda\AppData\Local\pip\cache\wheels\f2\da\05\297091d04307f374f8f8e99c9a1f1182d2f632f8e394ec281f>pip install opencv_contrib_python-4.6.0.3725898-cp310-cp310-win_amd64.whl
WARNING: Ignoring invalid distribution -pencv-python (c:\users\fdsahfjksda\appdata\local\programs\python\python310\lib\site-packages)
WARNING: Ignoring invalid distribution -pencv-python (c:\users\fdsahfjksda\appdata\local\programs\python\python310\lib\site-packages)
Processing c:\users\fdsahfjksda\appdata\local\pip\cache\wheels\f2\da\05\297091d04307f374f8f8e99c9a1f1182d2f632f8e394ec281f\opencv_contrib_python-4.6.0.3725898-cp310-cp310-win_amd64.whl
Requirement already satisfied: numpy>=1.17.3 in c:\users\fdsahfjksda\appdata\local\programs\python\python310\lib\site-packages (from opencv-contrib-python==4.6.0.3725898) (1.23.3)
WARNING: Ignoring invalid distribution -pencv-python (c:\users\fdsahfjksda\appdata\local\programs\python\python310\lib\site-packages)
Installing collected packages: opencv-contrib-python
WARNING: Ignoring invalid distribution -pencv-python (c:\users\fdsahfjksda\appdata\local\programs\python\python310\lib\site-packages)
Successfully installed opencv-contrib-python-4.6.0.3725898
WARNING: Ignoring invalid distribution -pencv-python (c:\users\fdsahfjksda\appdata\local\programs\python\python310\lib\site-packages)
WARNING: Ignoring invalid distribution -pencv-python (c:\users\fdsahfjksda\appdata\local\programs\python\python310\lib\site-packages)
WARNING: Ignoring invalid distribution -pencv-python (c:\users\fdsahfjksda\appdata\local\programs\python\python310\lib\site-packages)

seems that the beginning ‘O’ is missing in opencv-python

Quick question, what do you want to use the CUDA modules for? I’m asking because you seem to be new to OpenCv and it may be that you go to all this effort to build with CUDA and it’s not going to solve your problem.

By the way for dev purposes you dont need to build a wheel you can just manually build OpenCv and copy across the python bindings. Building a wheel is something more suited to re-distribution.

and Visual Studio’s INSTALL target/project (generated by cmake) does that for you, so you don’t have to know how to do it

that you should try to clean up by going in that directory and finding something that looks like a mangled -pencv-python file/directory. just delete that.

It should but I’ve found the python loader pre 4.6.0 can be a bit error prone and even then it can fail on rebuilds. From memory 60% of the time it works every time!

1 Like

I am trying to use the optical flow with my webcam, but the CPU-only OpenCV FarnebackOpticalFlow is too slow

I wish I can edit the title of my topic now because the problem seems to be that the contrib modules aren’t being exposed in Python

in IDLE, if I type
help(cv2.cuda)

within the first few lines from the result are :


> 
> Help on module cv2.cuda in cv2:
> 
> NAME
>     cv2.cuda
> 
> CLASSES
....
>     cv2.Algorithm(builtins.object)
       ...
>         DenseOpticalFlow
>             BroxOpticalFlow
>             DensePyrLKOpticalFlow
>             FarnebackOpticalFlow
>             OpticalFlowDual_TVL1
       ...
>         NvidiaHWOpticalFlow
>             NvidiaOpticalFlow_1_0
>             NvidiaOpticalFlow_2_0
>         SparseOpticalFlow
>            SparsePyrLKOpticalFlow
>         

there are the opticalflow-related entries from the ‘CUDA-accelerated Computer Vision’ documentation:


but they are listed under ‘cv2.Algorithm(builtins.object)’

I searched for files with ‘farneback’ , ‘brox’ and ‘pyrlk’ in their names(easier to search because of their distinctive names), and I found .cpp files with those exact names , all of them under the opencv-contrib folder, and all of them having #if !defined (HAVE_CUDA) at the beginning of their code

Therefore it stands to reason that the compiled cv2.FarnebackOpticalFlow in my Python is in fact CUDA-enabled, although this contradicts what this website says:

#start optical flow timer
start_of = time.time()

#create optical flow instance
gpu_flow = cv2.cuda_FarnebackOpticalFlow.create(
5, 0.5, False, 15, 3, 5, 1.2, 0,
)
#calculate optical flow
gpu_flow = cv2.cuda_FarnebackOpticalFlow.calc(
gpu_flow, gpu_previous, gpu_current, None,
)

#end of timer
end_of = time.time()

#add elapsed iteration time
timers[“optical flow”].append(end_of - start_of)

looking at __init__.pyi , there are also entries for FarnebackOpticalFlow_create and calcOpticalFlowFarneback(which I presume are the functions to be called in that code) but there is no mention of other classes which should have been in OpenCV-Contrib such as ‘BroxOpticalFlow’ , ‘NvidiaOpticalFlow’ , etc

I can assure you this is not the case, from what you have described your issue is you have not managed to build or install the python OpenCv contrib wheel with CUDA successfully. Without that there are no CUDA modules, the reason you can access the CUDA data classes (GpuMat etc.) is because they are part of the main OpenCv python wheel.

My procedure was as follows:

In Windows Environment Variables, I have a variable named CMAKE_ARGS with the following value:

-DCMAKE_BUILD_TYPE=RELEASE -DWITH_CUDA=ON -DWITH_CUBLAS=ON -DINSTALL_PYTHON_EXAMPLES=OFF -DINSTALL_C_EXAMPLES=OFF -DWITH_CUDNN=ON -DOPENCV_DNN_CUDA=ON -DENABLE_FAST_MATH=ON -DCUDA_FAST_MATH=ON -DOPENCV_ENABLE_NONFREE=ON -D CUDA_ARCH_BIN=6.1 -DPYTHON3_NUMPY_INCLUDE_DIRS:PATH="C:\Users\fdsahfjksda\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\core\include"

Notice the last argument :

-DPYTHON3_NUMPY_INCLUDE_DIRS:PATH=“C:\Users\fdsahfjksda\AppData\Local\Programs\Python\Python310\Lib\site-packages\numpy\core\include”

This is because of the Numpy version which OpenCV-Python tries to look for, if I don’t specify this argument, it will look for Numpy in some temp folder and end with fatal error C1083: Cannot open include file: 'numpy/ndarrayobject.h'near the end of the build process

In Windows Command Line in C:\ directory, I ran

git clone --recursive https://github.com/opencv/opencv-python.git

This created the C:\opencv-python directory (it includes the opencv-contrib subdirectory)

Then, I edited the pyproject.toml file, from
"numpy==1.21.2; python_version>='3.10'"
to
"numpy==1.23.3; python_version>='3.10'"
So that it uses the installed Numpy 1.23.3 version, instead of trying to install Numpy 1.21.2 which fails with TypeError: CCompiler_spawn() got an unexpected keyword argument 'env'

Next, I executed the following commands in Windows Command Line:

C:\opencv-python\ set ENABLE_CONTRIB=1

C:\opencv-python\ pip wheel . --verbose


I was observing the build process and saw that the text output had many CUDA references like ‘Building NVCC (Device)’ and filenames with the .cu extension, and this is the CMake report:

  -- General configuration for OpenCV 4.6.0 =====================================
  --   Version control:               4.6.0
  --
  --   Extra modules:
  --     Location (extra):            C:/opencv-python/opencv_contrib/modules
  --     Version control (extra):     4.6.0
  --
  --   Platform:
  --     Timestamp:                   2022-09-09T19:51:33Z
  --     Host:                        Windows 10.0.22000 AMD64
  --     CMake:                       3.24.1
  --     CMake generator:             Visual Studio 17 2022
  --     CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
  --     MSVC:                        1932
  --     Configuration:               Debug Release
  --
  --   CPU/HW features:
  --     Baseline:                    SSE SSE2 SSE3
  --       requested:                 SSE3
  --     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
  --       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
  --       SSE4_1 (16 files):         + SSSE3 SSE4_1
  --       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
  --       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
  --       AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
  --       AVX2 (31 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
  --       AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
  --
  --   C/C++:
  --     Built as dynamic libs?:      NO
  --     C++ standard:                11
  --     C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe  (ver 19.32.31332.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 /MP  /MT /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 /MP  /MTd /Zi /Ob0 /Od /RTC1
  --     C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/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   /MT /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 /MTd /Zi /Ob0 /Od /RTC1
  --     Linker flags (Release):      /machine:x64  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
  --     Linker flags (Debug):        /machine:x64  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
  --     ccache:                      NO
  --     Precompiled headers:         YES
  --     Extra dependencies:          wsock32 comctl32 gdi32 ole32 setupapi ws2_32 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:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib/x64 -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib
  --     3rdparty dependencies:       libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib quirc ippiw ippicv
  --
  --   OpenCV modules:
  --     To be built:                 aruco barcode 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 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 cvv freetype hdf java julia matlab ovis python2 sfm ts viz
  --     Applications:                -
  --     Documentation:               NO
  --     Non-free algorithms:         YES
  --
  --   Windows RT support:            NO
  --
  --   GUI:                           WIN32UI
  --     Win32 UI:                    YES
  --     VTK support:                 NO
  --
  --   Media I/O:
  --     ZLib:                        build (ver 1.2.12)
  --     JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
  --     WEBP:                        build (ver encoder: 0x020f)
  --     PNG:                         build (ver 1.6.37)
  --     TIFF:                        build (ver 42 - 4.2.0)
  --     JPEG 2000:                   build (ver 2.4.0)
  --     OpenEXR:                     build (ver 2.3.0)
  --     HDR:                         YES
  --     SUNRASTER:                   YES
  --     PXM:                         YES
  --     PFM:                         YES
  --
  --   Video I/O:
  --     DC1394:                      NO
  --     FFMPEG:                      YES (prebuilt binaries)
  --       avcodec:                   YES (58.134.100)
  --       avformat:                  YES (58.76.100)
  --       avutil:                    YES (56.70.100)
  --       swscale:                   YES (5.9.100)
  --       avresample:                YES (4.0.0)
  --     GStreamer:                   NO
  --     DirectShow:                  YES
  --     Media Foundation:            YES
  --       DXVA:                      YES
  --
  --   Parallel framework:            Concurrency
  --
  --   Trace:                         YES (with Intel ITT)
  --
  --   Other third-party libraries:
  --     Intel IPP:                   2020.0.0 Gold [2020.0.0]
  --            at:                   C:/opencv-python/_skbuild/win-amd64-3.10/cmake-build/3rdparty/ippicv/ippicv_win/icv
  --     Intel IPP IW:                sources (2020.0.0)
  --               at:                C:/opencv-python/_skbuild/win-amd64-3.10/cmake-build/3rdparty/ippicv/ippicv_win/iw
  --     Lapack:                      NO
  --     Eigen:                       NO
  --     Custom HAL:                  NO
  --     Protobuf:                    build (3.19.1)
  --
  --   NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS FAST_MATH)
  --     NVIDIA GPU arch:             61
  --     NVIDIA PTX archs:
  --
  --   cuDNN:                         YES (ver 8.4.1)
  --
  --   OpenCL:                        YES (NVD3D11)
  --     Include path:                C:/opencv-python/opencv/3rdparty/include/opencl/1.2
  --     Link libraries:              Dynamic load
  --
  --   Python 3:
  --     Interpreter:                 C:\Users\fdsahfjksda\AppData\Local\Programs\Python\Python310\python.exe (ver 3.10.7)
  --     Libraries:                   C:/Users/fdsahfjksda/AppData/Local/Programs/Python/Python310/libs/python310.lib (ver 3.10.7)
  --     numpy:                       C:/Users/fdsahfjksda/AppData/Local/Programs/Python/Python310/Lib/site-packages/numpy/core/include (ver 1.23.3)
  --     install path:                python/cv2/python-3
  --
  --   Python (for build):            C:\Users\fdsahfjksda\AppData\Local\Programs\Python\Python310\python.exe
  --
  --   Java:
  --     ant:                         NO
  --     JNI:                         NO
  --     Java wrappers:               NO
  --     Java tests:                  NO
  --
  --   Install to:                    C:/opencv-python/_skbuild/win-amd64-3.10/cmake-install
  -- -----------------------------------------------------------------
  --
  -- Configuring done

At the end it produced opencv_contrib_python-4.6.0.3725898-cp310-cp310-win_amd64.whlin the C:\opencv-python folder

Next, I installed the wheel:

C:\opencv-python\ pip install opencv_contrib_python-4.6.0.3725898-cp310-cp310-win_amd64.whl

And that results in opencv-contrib-python version 4.6.0.3725898 being installed into my Python

opencv_python-4.6.0.3725898-cp310-cp310-win_amd64.whl - Google Drive this is the wheel file that was generated, can you see if the problem is in there somewhere?

In pyopencv_generated_modules_content.h, I found these lines

static PyMethodDef methods_cv[] = {
...
    {"FarnebackOpticalFlow_create", CV_PY_FN_WITH_KW_(pyopencv_cv_FarnebackOpticalFlow_create, 0), "FarnebackOpticalFlow_create([, numLevels[, pyrScale[, fastPyramids[, winSize[, numIters[, polyN[, polySigma[, flags]]]]]]]]) -> retval\n."},
...
#ifdef PYOPENCV_EXTRA_METHODS_CV
    PYOPENCV_EXTRA_METHODS_CV
#endif
    {NULL, NULL}
};
...
static PyMethodDef methods_cuda[] = {
...
    {"FarnebackOpticalFlow_create", CV_PY_FN_WITH_KW_(pyopencv_cv_cuda_FarnebackOpticalFlow_create, 0), "FarnebackOpticalFlow_create([, numLevels[, pyrScale[, fastPyramids[, winSize[, numIters[, polyN[, polySigma[, flags]]]]]]]]) -> retval\n."},
...
#ifdef PYOPENCV_EXTRA_METHODS_CUDA
    PYOPENCV_EXTRA_METHODS_CUDA
#endif
    {NULL, NULL}
};

And in pyopencv_generated_types.h , there are these lines:

...
CVPY_TYPE(FarnebackOpticalFlow, FarnebackOpticalFlow, Ptr<cv::FarnebackOpticalFlow>, Ptr, DenseOpticalFlow, 0, "");
...
CVPY_TYPE(FarnebackOpticalFlow, cuda_FarnebackOpticalFlow, Ptr<cv::cuda::FarnebackOpticalFlow>, Ptr, cuda_DenseOpticalFlow, 0, ".cuda");

These seem to suggest that FarnebackOpticalFlow is in some way related to being CUDA-enabled, but then again it is mentioned twice, once without CUDA and once again with