How to compute optical flow using tvl1 opencv function

2024/10/9 20:29:36

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.

Answer

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

https://en.xdnf.cn/q/69980.html

Related Q&A

Python 3.3.4: python-daemon-3K ; How to use runner

Struggling to try and get a python daemon to work using Python 3.3.4. Im using the latest version of the python-daemon-3K from PyPi i.e. 1.5.8Starting point is the following code found How do you creat…

How to select specific data variables from xarray dataset

BACKGROUND I am trying to download GFS weather data netcdf4 files via xarray & OPeNDAP. Big thanks to Vorticity0123 for their prior post, which allowed me to get the bones of the python script sort…

List object has no attribute Values error

I would like to get the data to Excel worksheet. The problem is when I run the whole code I receive an error but when I run it separately no error it works. Here is what I want; from xlwings import Wor…

How to resize an image in python, while retaining aspect ratio, given a target size?

First off part of me feels like this is a stupid question, sorry about that. Currently the most accurate way Ive found of calculating the optimum scaling factor (best width and height for target pixel …

How to limit number of followed pages per site in Python Scrapy

I am trying to build a spider that could efficiently scrape text information from many websites. Since I am a Python user I was referred to Scrapy. However, in order to avoid scraping huge websites, I …

Why is Pythons sorted() slower than copy, then .sort()

Here is the code I ran:import timeitprint timeit.Timer(a = sorted(x), x = [(2, bla), (4, boo), (3, 4), (1, 2) , (0, 1), (4, 3), (2, 1) , (0, 0)]).timeit(number = 1000) print timeit.Timer(a=x[:];a.sort(…

How to efficiently unroll a matrix by value with numpy?

I have a matrix M with values 0 through N within it. Id like to unroll this matrix to create a new matrix A where each submatrix A[i, :, :] represents whether or not M == i.The solution below uses a lo…

Anaconda Python 3.6 -- pythonw and python supposed to be equivalent?

According to Python 3 documentation, python and pythonw should be equivalent for running GUI scripts as of 3.6With older versions of Python, there is one Mac OS X quirk that you need to be aware of: pr…

Good way of handling NoneType objects when printing in Python

How do I go about printin a NoneType object in Python?# score can be a NonType object logging.info("NEW_SCORE : "+score)Also why is that sometime I see a comma instead of the + above?

problems with easy_install pycrypto

Im trying install pycrypto on osx with easy_install and Im getting the following error:easy_install pycrypto Searching for pycrypto Reading http://pypi.python.org/simple/pycrypto/ Reading http://pycryp…