This example analyzes motion in a short video clip by computing frame-to-frame image displacements. The displacement field is interpreted as a velocity field, and its divergence is evaluated to detect local expansion and contraction in the scene. The divergence is visualized as a color overlay on the original frames.
Load a short video clip that will be used for motion analysis:
Compute frame-to-frame displacement vectors using optical flow estimation:
In[2]:=
flow=ImageDisplacements[video];
The result is a time-indexed array of 2D displacement vectors representing horizontal and vertical motion between consecutive frames. See the dimensions of one frame:
In[3]:=
flow〚100〛//Dimensions
Out[3]=
{720,1280,2}
Define a function that computes the divergence of a 2D displacement field using finite differences. This applies centered finite differences to approximate the spatial derivatives of the horizontal and vertical displacement components: