I am using createOptFlow_DualTVL1()
to calculate optical flow which is giving me exactly what I want but it is very slow. Is there any way I can speed it up a little bit or is there any other optical flow function which will give me the same result with less processing time?
I have used calcOpticalFlowFarneback()
, cvGoodFeaturesToTrack()
but the quality is not good. please help.
Thank you in advance Below is how I apply createOptFlow_DualTVL1()
Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
tvl1->calc(Previous_Gray_Frame, Current_Gray_Frame, Optical_Flow);
In order to speed up the computation, you need to reduce the total count of computations performed each time. This seems obvious, but the huge number of strategies to achieve that goal can be confusing. So, here are some proposals:
Reduce the size of your images (input data). In particular, you should try to divide their size by 2 along each dimension, compute the flow, then compute a full size flow with linear interpolation. Unless your application requires a very high accuracy, this solution should be acceptable and will give you a huge speedup.
Reduce the number of warps (parameter: warps
) per scale. This will harm a little the accuracy, but unless you have very difficult motion patterns (e.g., when all the image pixels are moving in different directions, or when you have a very fast motion inside the image) the result should still be acceptable. The algorithms runs the minimization procedure warps
times per level in the image pyramid, so even a small change in warps
will give you a noticeable speedup.
Reduce the number of levels in the image pyramid (parameter: scales
). This can have an important impact on the accuracy though, so be careful and experiment a lot with it. It has been found in the literature that a good (for accuracy) scale factor between levels is 0.8, so you should compute your number of levels accordingly. Before 0.8, the standard in experimenting with optical flow was a scale factor of 0.5, so you can try to go down until this value.
Convergence speed: the inner procedure for L1 minimization is stable for time steps (parameter: tau
) up to 1/8 (0.125) in theory, but in practice values of 1/4 (0.25) are known to still work.