Brief Explanation
Optical flow vectors (u,v) were calculated over Horn & Schunck algorithm. Then, least square approximation was applied to estimate 6-parameters of the affine motion model. Significant point here is the selection of appropriate pixels to solve the linear system.
I have used non-intelligent or in other words video-specific method to pick the relavant pixels. The woody region in the scene is static but appears as moving in the flow field due to camera motion. I thought, sampling pixels from this woody region is the simplest way to reach to the camera motion parameters.

Parameters of the 2D affine motion model can be classified into two: angular (a2,a3,a5,a6) and translational (a1,a4). The effect of the pan and tilt motions are pixel displacements that relate to only translational parameters if the scene is far enough. To illustrate, pan and tilt motions can be observed from a1 and a4, respectively. However, zoom required angular motion parameters to monitor the scale changes, (a2+a6)/2; and needs matrix multiplication with pixel coordinates to satisfy the equation.
Result
In the below demonstrations, you will see the optical flow field next to original video and extracted motion parameters at the bottom. The colors in parameter values have an aim to simplify the observation.
- RED Positive
- BLACK Zero
- BLUE Negative