Stabilization Correction
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:
- Iterate over each frame in the video sequence.
- Calculate the difference between the smoothed and original camera positions for each frame.
This technique is widely used in handheld camera footage stabilization.
Example:
original = [(0,0), (1,0), (2,1)] smoothed = [(0,0), (1,0.5), (2,1)]
[(0, 0), (0, 0.5), (0, 0)]
-
Computing correction at each frame:
-
Frame 0: (0,0) - (0,0) = (0, 0)
-
Frame 1: (1,0.5) - (1,0) = (0, 0.5)
-
Frame 2: (2,1) - (2,1) = (0, 0)
-
Result: [(0,0), (0,0.5), (0,0)]
-
The middle frame needs a 0.5 pixel vertical correction.
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
You can think of this problem as: you already estimated how the camera moved over time (the original path) and you already chose a nicer, smoother motion (the smoothed path). Now you just need to compute, for each frame, how much to “nudge” the frame so that the original motion becomes the smoothed one.
1. Background Knowledge
In classical video stabilization, the goal is to remove unwanted high‑frequency jitter while preserving low‑frequency, intentional camera motion (like pans or zooms). Conceptually, you first estimate the camera motion trajectory over time (a sequence of transforms per frame), then you compute a smoothed trajectory that is similar but less shaky, and finally you warp each frame so the camera appears to follow the smooth trajectory instead of the original one.
Each frame’s camera pose is often represented by a small motion parameter vector (for 2D video: translation x,y, rotation θ, maybe scale s). If you stack these over time, you get a path (or trajectory) in this parameter space:
Poriginal={Poriginal,0,Poriginal,1,…}Smoothing this path (e.g., with a moving average or filter) gives Psmooth. The “correction” for frame i is simply the difference of motion parameters between where you want the camera to be and where it is:
Δi=Psmooth,i−Poriginal,iApplying Δi as a transform to frame i shifts the apparent camera from the original pose to the smoothed pose.
2. Algorithm / General Approach
The general stabilization pipeline (conceptually) is:
- Estimate per-frame camera motion to get Poriginal,i for all frames.
- Smooth the trajectory over time to get Psmooth,i.
- Compute per-frame correction transforms:
- Apply corrections: for each frame, warp it by Δi.
In this specific problem, steps 1–2 are already done; you only need step 3: compute Δi from the two given paths.
3. Step-by-Step Strategy
Assume you are given two arrays (or lists) of length N:
- original[i] = Poriginal,i
- smooth[i] = Psmooth,i
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
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.