Error While Running Python Code From https://developer.nvidia.com/blog/opencv-optical-flow-algorithms-with-nvidia-turing-gpus/

Traceback (most recent call last):
File “optflow.py”, line 8, in
nvof = cv2.cuda_NvidiaOpticalFlow_1_0.create(frame1.shape[1], frame1.shape[0])
cv2.error: OpenCV(4.2.0) /tmp/opencv_contrib/opencv_contrib-4.2.0/modules/cudaoptflow/src/nvidiaOpticalFlow.cpp:375: error: (-5:Bad argument) GetAPI()->nvCreateOpticalFlowCuda(m_cuContext, &m_hOF) returned error 2:NV_OF_ERR_UNSUPPORTED_DEVICE in function ‘NvidiaOpticalFlowImpl’

Environment:
GPU: TITAN X
CUDA: 10.2
OpenCV: 4.2.0

I’m experiencing the same issue.
It’s probably because you don’t have a GPU with Turing architecture.
See the dependencies on this page:

You can see Turing supported architecture on: https://en.wikipedia.org/wiki/List_of_Nvidia_graphics_processing_units