First of all we need a couple of test images:
# import numpy from StringIO import StringIO I0 = numpy.loadtxt(StringIO(""" 0 0 0 0 0 0 0 0.5000 0 0 0 0 1.0000 0 0 0 0 0.5000 0 0 0 0 0 0 0""") ) I1 = numpy.loadtxt(StringIO(""" 0 0 0 0 0 0 0.5 0 0 0 0 1.0 0 0 0 0 0.5 0 0 0 0 0 0 0 0 """) )Define initial horiozontal and vertical components of optical flow
u = numpy.zeros_like(I0); v = numpy.zeros_like(I0);Lets write class for making warps. As OF usually deals only with small displacements, we need iterative estimation: estimate, shift image by found vectors, find again.