HornSchunck() class is written in Python. It returns optical flow velocities (u,v) for given parameters:
- alpha : (float) the regularization coefficient of smoothness constraint
- maxIter : (int) maximum number of iterations required to obtain flow velocities
- applyGauss : (bool) apply Gaussian smoothing as a preprocess {False by default}
- GaussKernel : (tuple) Gaussian Filter kernel size {(15,15) by default}
Initialize an object of HornSchunck() class with an arbitrary name, optFlow() is suggested.
optFlow = HornSchunck(alpha=alpha,maxIter=maxIter)
optFlow.applyGauss = True
optFlow.GaussKernel = (5,5)
Then use estimate() method to calculate optical flow velocities (u,v). After execution, getFlowField() method returns the colorized flow field.
(u,v) = optFlow.estimate(frame1,frame2)
flowField = optFlow.getFlowField()
Prediction of target frame from anchor via flow velocities is possible with predict() method. Moreover, getCollage() method puts 4 frames together to show a collage.
anchorP = optFlow.predict()
collage = optFlow.getCollage(f1_idx,f2_idx)
[1] Horn and Schunck. (1981). Determining Optical Flow
Utilized from OpticalFlow_Visualization by Tom Runia (tomrunia@github) for optical flow field colorization.