v9.1.1
Menu

Cumulative Camera Motion

easyFREEVideo StabilizationStabilizationCV: Motion Estimation

Implement a function to compute the cumulative camera path from given frame-to-frame translations, a crucial step in video stabilization. This process involves calculating the integrated motion of the camera over time.

The concept of cumulative camera motion is rooted in motion estimation, where the goal is to estimate the movement of the camera between consecutive frames. This is often represented as a sequence of translations and rotations. In this case, we focus on the translation component, which can be thought of as the change in position (dx,dy)(dx, dy) between two frames.

To compute the cumulative path, we can follow these steps:

  1. Initialize the starting position at the origin (0,0)(0, 0).
  2. For each frame-to-frame translation (dx,dy)(dx, dy), update the current position by adding the translation.
  3. Record the updated position at each step.
xt+1=xt+dxyt+1=yt+dyx_{t+1} = x_t + dx \\ y_{t+1} = y_t + dy

This technique is widely used in handheld camera footage stabilization to reduce jitter and produce smoother video.

Example

Input
transforms = [(1, 0), (1, 1), (0, 1)]
Output
[(0, 0), (1, 0), (2, 1), (2, 2)]
Reasoning
  • Input: transforms holds three frame-to-frame translations (dx,dy)(dx, dy), in pixels: frame 0→1 moves (1,0)(1, 0), frame 1→2 moves (1,1)(1, 1), frame 2→3 moves (0,1)(0, 1).
  • Start: the camera's position at frame 0 is the origin, (x0,y0)=(0,0)(x_0, y_0) = (0, 0), before any motion has happened.
  • Frame 1: (0+1, 0+0)=(1,0)(0 + 1,\ 0 + 0) = (1, 0).
  • Frame 2: (1+1, 0+1)=(2,1)(1 + 1,\ 0 + 1) = (2, 1).
  • Frame 3: (2+0, 1+1)=(2,2)(2 + 0,\ 1 + 1) = (2, 2). Equivalently, each position is the sum of every translation so far: x3=1+1+0=2x_3 = 1 + 1 + 0 = 2, y3=0+1+1=2y_3 = 0 + 1 + 1 = 2.
  • Output: [(0, 0), (1, 0), (2, 1), (2, 2)]: four positions for three translations, since the starting origin counts as a frame. With no translations the path is just [(0, 0)].
  • Notice that motions can cancel: (−1,−1)(-1, -1) then (1,1)(1, 1) brings the camera back to (0,0)(0, 0). Stabilization smooths exactly this kind of back-and-forth jitter.

Constraints

  • transforms: list of (dx, dy) frame-to-frame motions
  • Return cumulative path as list of (x, y) positions
  • Path starts at (0, 0)
  • Path length = len(transforms) + 1

More from CV: Motion Estimation

solution.py

Test results

Sign in to run your code against the test cases.