A C++17 and OpenCV research prototype that estimates dominant image motion from video, smooths the accumulated path, and resamples each frame once. The experiments use synthetic ground truth and independent real-video proxies to show where global stabilization helps and where it fails.
- On the held-out textured foreground fixture, edge-supported estimation reduced background transfer error from 8.301 to 0.193 px RMS. Edge fitting plus confidence control reduced artificial center jitter from 2.833 to 0.124 px RMS.
- On held-out handheld footage, the Gaussian baseline reduced the apparent-motion proxy from 2.120 to 1.199 px RMS across all 149 frame pairs. The edge-supported variant with confidence control measured 1.245 px. These are background-feature measurements from actual output frames.
- Edge-supported fitting preserved 0.007822 px clean-fixture transfer RMS with zero fallbacks. On riding footage, fewer fallbacks coincided with higher apparent motion.
Grid-distributed Shi–Tomasi corners feed bidirectional pyramidal Lucas–Kanade tracking. RANSAC fits a translation or orientation-preserving similarity. Each increment maps previous-frame pixels into current-frame pixels. The raw path is P[t] = M[t] P[t−1]. The correction is S[t] inverse(P[t]), followed by centered zoom in the same resample. A separate valid-pixel mask measures interpolation support. See the source walkthrough.
| Combined synthetic fixture | Translation jitter (px RMS) | Retained area | Smoothing look-ahead |
|---|---|---|---|
| Original | 8.161 | 100% | 0 ms |
| Moving average | 0.635 | 79.7% | 333 ms |
| Gaussian | 0.282 | 79.7% | 333 ms |
| Causal Kalman | 1.508 | 79.7% | 0 ms |
The stabilized methods share 1.12× zoom. Sequence-wide safe crop, evaluated separately, retained 90.75% area at 0.283 px RMS jitter with no border frames. It needs the complete sequence.
Riding failures averaged 259 accepted correspondences after forward–backward filtering. The inlier gate still rejected them because those locally consistent tracks did not support one common motion. The edge alternative requires distributed support across three sides. Edge fitting and confidence control are opt-in. Default flags preserve baseline behavior.
The camera is fixed and only the foreground moves. An apparently strong global fit can follow the foreground and induce artificial background motion. Edge support helped when textured background was visible. Low-texture background defeated the prior.
The independent evaluator matches ORB features in a predefined background region and scores the common valid frame pairs at equal crop. The apparent center displacement includes intended motion and can be affected by foreground leakage. The clip has no ground-truth camera trajectory. Source and dedication.
At zero look-ahead on the mixed development fixture, causal averaging gave 1.166 px jitter with five frames of tracking lag. EMA gave 1.556 px with three frames of lag and lower intended-path error. Three-frame fixed-lag Gaussian gave 0.670 px with 100 ms look-ahead. The executable decodes in two passes. Smoother look-ahead, tracking lag, and computational time are separate.
| Held-out synthetic case | B0 baseline | B2 edge only | B5 edge + confidence |
|---|---|---|---|
| Textured foreground jitter (px RMS) | 2.833 | 0.164 | 0.124 |
| Parallax jitter (px RMS) | 5.314 | 0.343 | 1.469 |
| Low-texture foreground jitter (px RMS) | 2.843 | 2.843 | 2.797 |
Confidence control helped the textured foreground case and gave back part of the gain on parallax. See the complete ablation.
| Resolution | Mean algorithm work | P95 | Batch wall throughput |
|---|---|---|---|
| 640×480 | 12.71 ms | 14.21 ms | 64.50 fps |
| 1280×720 | 24.02 ms | 27.13 ms | 32.51 fps |
| 1920×1080 | 54.46 ms | 62.09 ms | 14.13 fps |
Baseline measurements are medians across three runs on a Ryzen 7 5700X3D with one OpenCV thread. Timed stages exclude grayscale conversion and video I/O. Batch wall throughput includes decode and telemetry with encoding disabled. Benchmark methodology.
On riding, edge fitting reduced fallbacks from 109 to 83 while the apparent center RMS rose from 14.506 to 14.623 px across 46 common pairs. Riding comparison. Large foregrounds, missing background texture, parallax, saturation, cuts, and blur can invalidate a single global transform. Pose hold loses the rejected increment. The prototype estimates 2D motion and uses nominal FPS. It has no depth, inertial, or rolling-shutter model. Negative results · Limitations.
Prerequisites are a C++17 compiler, CMake 3.16+, OpenCV 4 development components, and Python 3. On Linux, install the OpenCV development package. On Windows, this example uses Visual Studio Build Tools 2019 and the official OpenCV 4.10 archive extracted under the temporary directory.
python -m pip install -r requirements.txt
$env:PATH="$env:TEMP/opencv/build/x64/vc16/bin;$env:PATH"
cmake -S . -B build-publication -G "Visual Studio 16 2019" -A x64 "-DOpenCV_DIR=$env:TEMP/opencv/build"
cmake --build build-publication --config Release
ctest --test-dir build-publication -C Release --output-on-failure
$exe = "build-publication/Release/stabilize_video.exe"
python tools/test_pipeline.py $exe
python tools/generate_synthetic_video.py artifacts/publication-quick --case combined --frames 48 --reference
& $exe --input artifacts/publication-quick/input.avi --output artifacts/publication-quick/output.avi --metrics artifacts/publication-quick/frames.csv --method gaussian --zoom 1.12 --visualization artifacts/publication-quick/flow
python tools/evaluate_stabilization.py artifacts/publication-quick/truth.json artifacts/publication-quick/frames.csvLinux configuration is cmake -S . -B build -DCMAKE_BUILD_TYPE=Release, followed by cmake --build build --parallel and ctest --test-dir build --output-on-failure. Use build/stabilize_video in the Python and CLI commands.
- Baseline benchmark · Reproduce the baseline · Baseline figures
- Robustness benchmark · Reproduce the robustness experiments · Robustness figures
- Root causes · Experiment protocol · Final verification ? Experiment provenance
OpenCV supplies image processing, tracking, robust-fitting and video I/O primitives. The synthetic scenes and figures are generated by the project. The handheld preview uses Oggencoder’s public-domain excerpt. See dependency and media notices and preview provenance. Codex assisted with coding, experiments and writing.






