7

I'm trying to find python example for computing optical flow with tvl1 opencv function createOptFlow_DualTVL1 but it seems that there isn't enough documentation for it.

Could anyone please let me do that? I've used calcOpticalFlowFarneback mentioned here http://docs.opencv.org/master/d7/d8b/tutorial_py_lucas_kanade.html but it is not giving me accurate results, will tvl1 good enough and if not is there another method I should look for?

[[EDIT]]

I've some regions come from selective search, I want keep only regions with motion in it, so computing the OF for a given frame and then get the avg in each region could do it. It's also described in this paper section 3.1

Thanks.

Ehab AlBadawy
  • 3,065
  • 4
  • 19
  • 31
  • I'm trying to do something like what is in [here](https://github.com/gkioxari/ActionTubes/blob/master/compute_OF/compute_flow.m). – Ehab AlBadawy Jun 17 '16 at 14:57
  • I've some regions come from selective search, I want keep only regions with motion in it, so computing the OF for a given frame and then get the avg in each region could do it. It's also described in this [paper](http://people.eecs.berkeley.edu/~gkioxari/ActionTubes/action_tubes.pdf) section 3.1 – Ehab AlBadawy Jun 17 '16 at 20:27
  • Both Farneback and tvl1 are dense methods that should do the job. Post your relevant code parts. – A. Sarid Jun 18 '16 at 16:23

1 Answers1

8

Change this line(Dense Optical example in http://docs.opencv.org/master/d7/d8b/tutorial_py_lucas_kanade.html):

flow = cv2.calcOpticalFlowFarneback(prvs, next, None, 0.5, 3, 15, 3, 5, 1.2, 0)

By these:

optical_flow = cv2.DualTVL1OpticalFlow_create()
flow = optical_flow.calc(prvs, next, None)

The parameter descriptions can be found here: http://docs.opencv.org/3.3.0/dc/d47/classcv_1_1DualTVL1OpticalFlow.html

Dani Cores
  • 181
  • 1
  • 6
  • 3
    In opencv 4, this is `cv2.optflow.createOptFlow_DualTVL1`, see https://docs.opencv.org/4.1.0/d2/d84/group__optflow.html – gerrit Jun 04 '19 at 10:07
  • 2
    @gerrit is correct but you need to install the `opencv-contrib-python` package to get the `cv2.optflow` module. – rgov Aug 03 '19 at 15:40
  • 1
    Worth pointing out that CUDA accelerated optical flow is done via the cudaoptflow module. https://docs.opencv.org/4.5.4/d6/d39/classcv_1_1cuda_1_1OpticalFlowDual__TVL1.html – jodag Nov 07 '21 at 23:59