Invalid GPU Ordinal in function 'NvidiaOpticalFlowImpl'

Hi there,

I want to develop a optical flow pipeline using opencv and gpu support (RTX 2070)

I installed opencv 4.2.0 from source and also the contrib modules.
I installed the optical flow sdk.

When I run the code from:

https://devblogs.nvidia.com/opencv-optical-flow-algorithms-with-nvidia-turing-gpus/

I end up getting the error:

python3 ofgpu.py 
Traceback (most recent call last):
  File "ofgpu.py", line 12, in <module>
    nvof = cv2.cuda_NvidiaOpticalFlow_1_0.create(frame1.shape[1], frame1.shape[0], 5, False, False, False, 1)
cv2.error: OpenCV(4.2.0) /home/user/opencv_contrib-4.2.0/modules/cudaoptflow/src/nvidiaOpticalFlow.cpp:321: error: (-5:Bad argument) Invalid GPU Ordinal in function 'NvidiaOpticalFlowImpl'

How can I solve this?

I can run the two samples from the optical flow sdk on my gpu without a problem with cuda 10.0

Hi.

nvof = cv2.cuda_NvidiaOpticalFlow_1_0.create(frame1.shape[1], frame1.shape[0], 5, False, False, False, 1)

In the above line, last argument is gpu ordinal. If you have 1 gpu in the system, then gpu ordinal should be 0. Implementation of this API tries to create a CUDA context based on the gpu ordinal passed. If such a device is not present physically, this error occurs.
Please try passing 0 as gpu ordinal instead of 1.

Thanks.

Thanks a lot,

is there any information about the python nvof opencv functions, or where is one supposed to find this information?

Hi.
You can refer to OpenCV’s auto generated documentation based on the doxygen tags in the source code.
Please refer
https://docs.opencv.org/master/dc/d9d/classcv_1_1cuda_1_1NvidiaOpticalFlow__1__0.html
https://docs.opencv.org/master/d5/d26/classcv_1_1cuda_1_1NvidiaHWOpticalFlow.html

Thanks.