Last active
January 9, 2018 04:30
-
-
Save jhaberstro/3dc58512b75a02644e0e7298d5578eaf to your computer and use it in GitHub Desktop.
Lucas-Kanade Dense Optical Flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from skimage import filters | |
def optical_flow_lk(t0, t1, sigma): | |
# setup the local linear systems of equations | |
gradients = np.gradient(t0) | |
dx, dy = gradients[1], gradients[0] | |
dt = t1 - t0 | |
A00 = filters.gaussian(dx * dx, sigma) | |
A11 = filters.gaussian(dy * dy, sigma) | |
A10 = filters.gaussian(dx * dy, sigma) | |
A01 = A10 | |
b0 = -filters.gaussian(dx * dt, sigma) | |
b1 = -filters.gaussian(dy * dt, sigma) | |
# solve the local linear systems of equations via 2x2 matrix inversion | |
determinant = 1.0 / ((A00 * A11) - (A10 * A10)) | |
u = determinant * ((b0 * A11) + (b1 * -A01)) | |
v = determinant * ((b0 * -A10) + (b1 * A00)) | |
return u, v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment