OpenCV Python - unable to access CUDA modules

I just installed your wheel in a fresh python 3.10 environment

(py310) C:\Users\b>pip install D:\dloads\opencv_python-4.6.0.3725898-cp310-cp310-win_amd64.whl
Processing d:\dloads\opencv_python-4.6.0.3725898-cp310-cp310-win_amd64.whl
Collecting numpy>=1.19.3
Downloading numpy-1.23.3-cp310-cp310-win_amd64.whl (14.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.6/14.6 MB 2.9 MB/s eta 0:00:00
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.23.3 opencv-python-4.6.0.3725898

and executed

gpu_flow = cv2.cuda_FarnebackOpticalFlow.create(
… 5, 0.5, False, 15, 3, 5, 1.2, 0,
… )
gpu_flow
< cv2.cuda.FarnebackOpticalFlow 0000029371A0BD30>

without any problems. What happens when you do the same?

I’ve just made a discovery, in IDLE if I type

help(cv2.FarnebackOpticalFlow)

it will return

Help on class FarnebackOpticalFlow in module cv2:
....
 |  Methods inherited from DenseOpticalFlow:
 |  
 |  calc(...)
 |      calc(I0, I1, flow) -> flow
 |      .   @brief Calculates an optical flow.
 |      .   
 |      .       @param I0 first 8-bit single-channel input image.
 |      .       @param I1 second input image of the same size and the same type as prev.
 |      .       @param flow computed flow image that has the same size as prev and type CV_32FC2.

Next I typed

help(cv2.cuda_FarnebackOpticalFlow)

fully expecting that it will not work, but to my surprise it returned a result:

Help on class FarnebackOpticalFlow in module cv2.cuda:
...
 |  Methods inherited from DenseOpticalFlow:
 |  
 |  calc(...)
 |      calc(I0, I1, flow[, stream]) -> flow
 |      .   @brief Calculates a dense optical flow.
 |      .   
 |      .       @param I0 first input image.
 |      .       @param I1 second input image of the same size and the same type as I0.
 |      .       @param flow computed flow image that has the same size as I0 and type CV_32FC2.
 |      .       @param stream Stream for the asynchronous version.

So there is a distinct CUDA version of the Farneback Optical Flow on my Python, it has an extra ‘stream’ parameter

The help function in IDLE also exposes the rest of the classes in the cv2::cuda namespace in pyopencv_generated_types.h, as well as the functions listed under PyMethodDef methods_cuda[] in pyopencv_generated_modules_content.h

So the problem seems to be that Visual Studio Code’s stub file , __init__.pyi , has not been updated after repeated reinstalls of OpenCV-Python , and has been misleading by only showing the modules from my very first installation of OpenCV-Python before I embarked my attempt to enable CUDA

So this is resolved then?

Just for information I have built a python wheel with CUDA from the tip of the master which should work with all python versions >=3.6, not just 3.10 in case you need it. I will also probably update it for new OpenCV/CUDA releases.