v9.1.1
Menu

Stabilization Correction

easyPROVideo StabilizationStabilizationCV: Motion Estimation

Implement a video stabilization technique by computing the per-frame correction transforms, given the original camera path and the smoothed path. This process aims to remove unwanted jitter while preserving smooth intentional motion.

The concept of motion estimation is crucial in video stabilization, as it involves tracking the movement of the camera between consecutive frames. The smoothed path represents the desired camera motion, while the original path contains unwanted jitter. The correction transform is the difference between these two paths.

To compute the correction transforms, follow these steps:

  1. Iterate over each frame in the video sequence.
  2. Calculate the difference between the smoothed and original camera positions for each frame.
Δi=Psmooth,i−Poriginal,i\Delta_i = P_{smooth,i} - P_{original,i}

This technique is widely used in handheld camera footage stabilization.

Example

Input
original = [(0,0), (1,0), (2,1)]
smoothed = [(0,0), (1,0.5), (2,1)]
Output
[(0, 0), (0, 0.5), (0, 0)]
Reasoning
  • Inputs: original is the camera's measured position (x,y)(x, y) in each of 3 frames, jitter included; smoothed is where the camera should have been in the same 3 frames. Frame ii of one list pairs with frame ii of the other.
  • Math: the correction is the vector that moves the shaky position onto the smooth one, Δi=Psmooth,i−Poriginal,i\Delta_i = P_{smooth,i} - P_{original,i}, taken separately for xx and yy.
  • Frame 0: (0−0,  0−0)=(0,0)(0 - 0,\; 0 - 0) = (0, 0), already on the smooth path.
  • Frame 1: (1−1,  0.5−0)=(0,0.5)(1 - 1,\; 0.5 - 0) = (0, 0.5), the measured yy fell 0.50.5 short of the smooth path, so the correction adds 0.50.5 in yy only.
  • Frame 2: (2−2,  1−1)=(0,0)(2 - 2,\; 1 - 1) = (0, 0).
  • Output: one (dx,dy)(dx, dy) pair per frame, rounded to 4 decimal places: [(0, 0), (0, 0.5), (0, 0)]. Notice the sign: if the smooth path were below the original, the correction would be negative, e.g. original (1,1)(1, 1) with smoothed (0,0)(0, 0) gives (−1,−1)(-1, -1).

Constraints

  • original: list of (x, y) original path positions
  • smoothed: list of (x, y) smoothed path positions
  • Return list of (dx, dy) correction transforms
  • Round to 4 decimal places

Learn this in

More from CV: Motion Estimation

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.