Nvidia Hardware Optical flow costbuffer question

I am using NvidiaOpticalFlow_2_0 and I am trying to access the cost buffer which shows how confident the motion tracking is


nvof = cv2.cuda.NvidiaOpticalFlow_2_0_create(

    (width, height), 

    cv2.cuda.NVIDIA_OF_PERF_LEVEL_SLOW, 

    enableCostBuffer=True

)

I have the current_frame, previous_frame, flow and cost as cv2.cuda.GpuMat

nvof.calc(current_frame, previous_frame, flow, cost)

However, the ‘cost’ array doesn’t seem to even get accessed at all, no values are being changed, I can even make it different dimensions and data types and it makes no difference

Is it possible to access the cost buffer from the Nvidia Hardware Optical flow?

might be a bug? the docs don’t state that were unused or anything.

you could submit an issue on the opencv_contrib repo:

Nvidia Hardware Optical Flow cost buffer · Issue #4093 · opencv/opencv_contrib · GitHub I opened an issue there

Some thoughts:

looking up instances of calc in nvidiaOpticalFlow.cpp, I find this:

   virtual void calc(InputArray inputImage, InputArray referenceImage,

        InputOutputArray flow, Stream& stream = Stream::Null(),

        InputArray hint = cv::noArray(), OutputArray cost = cv::noArray());

“noArray” appears nowhere else in this file, but appears in many other .hpp files under the CV_WRAP, CV_EXPORT and CV_EXPORT_W macros

In cudaoptflow.hpp , calcdoes not appear , whereas in other .hpp files, the class’s public methods with “noArray” in the initialization appear with one of those macros

Solved it, the docs say that the cost buffer format was CV_32SC1 , but that only applies to NvidiaOpticalFlow_1_0

for NvidiaOpticalFlow_2_0 , the cost buffer format has been changed to CV_8SC1, now its working properly for me

1 Like