Ask Your Question

Revision history [back]

Hi, In 4.1.2 the CUDA python bindings should be working, additionally on the basis that

opticalFlowGPU = cv.cuda_FarnebackOpticalFlow.create(5, 0.5, False, 15, 3, 5, 1.2, 0)

didn't throw an error I think you have them set up correctly.

You may be having a problem because if you are passing numpy arrays instead of GpuMat to the cv2.cuda_FarnebackOpticalFlow.calc() function.

From the help

help(cv2.cuda_FarnebackOpticalFlow.calc)

Help on method_descriptor:

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.

I0, I1 and flow are required so as long as frame1 and frame2 are GpuMat

flowCUDA = opticalFlowGPU.calc(frame1, frame2, None)

should work without any errors. I would therefore try the below just to check

I0 = cv2.cuda_GpuMat(frame1)
I1 = cv2.cuda_GpuMat(frame2)
flowCUDA = opticalFlowGPU.calc(I0,I1,None)
flowCUDA.download()

ensuring that frame1 and frame2 are single channel arrays.

Hi, Hi,

1) In 4.1.2 the CUDA python bindings should be working, additionally on the basis that

opticalFlowGPU = cv.cuda_FarnebackOpticalFlow.create(5, 0.5, False, 15, 3, 5, 1.2, 0)

didn't throw an error I think you have them set up correctly.

You may be having a problem because if you are passing numpy arrays instead of GpuMat to the cv2.cuda_FarnebackOpticalFlow.calc() function.

From the help

help(cv2.cuda_FarnebackOpticalFlow.calc)

Help on method_descriptor:

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.

I0, I1 and flow are required so as long as frame1 and frame2 are GpuMat

flowCUDA = opticalFlowGPU.calc(frame1, frame2, None)

should work without any errors. I would therefore try the below just to check

I0 = cv2.cuda_GpuMat(frame1)
I1 = cv2.cuda_GpuMat(frame2)
flowCUDA = opticalFlowGPU.calc(I0,I1,None)
flowCUDA.download()

ensuring that frame1 and frame2 are single channel arrays.

2) Nvidia optical flow is included in 4.1.2, you should be able to create the class in python by calling

nvidia_of = cv2.cuda.NvidiaOpticalFlow_1_0_create(720,1280)

with the height and width of your frame.