Skip to content

This project implements video stabilization using OpenCV. It estimates motion between frames and smooths the trajectory using a Kalman filter, generating a stabilized video output with side-by-side comparison.

License

Notifications You must be signed in to change notification settings

anurag965/Video-Stabilization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📹 Video Stabilization using OpenCV and Kalman Filter

This project implements video stabilization using OpenCV. It estimates motion between frames and smooths the trajectory using a Kalman filter, generating a stabilized video output with side-by-side comparison.

🛠 Features

  • Motion estimation via optical flow.
  • Affine transformation model (translation + rotation).
  • Kalman filtering to smooth the trajectory.
  • Side-by-side visualization of original vs. stabilized video.
  • Outputs transformation, trajectory, and smoothed data logs for analysis.

🧠 How it Works

  1. Feature Tracking: Good features are selected and tracked across frames using Lucas-Kanade optical flow.
  2. Motion Estimation: Affine transform (translation + rotation) is computed between each frame.
  3. Trajectory Building: The cumulative motion builds a raw trajectory.
  4. Kalman Filtering: The trajectory is smoothed to reduce jitter.
  5. Transform Correction: Differences between the raw and smoothed trajectory are used to compute new frame transforms.
  6. Video Rendering: The corrected frames are shown side-by-side with original ones and saved as a new video (compare.avi).

📂 File Outputs

  • prev_to_cur_transformation.txt: Raw frame-to-frame transformations.
  • trajectory.txt: Raw cumulative trajectory.
  • smoothed_trajectory.txt: Kalman-filtered smooth trajectory.
  • new_prev_to_cur_transformation.txt: Final stabilized frame transformations.

🚀 Getting Started

Requirements

  • Python 3.x
  • OpenCV
  • NumPy

Install Dependencies

pip install opencv-python numpy

Run the Stabilizer

python rec_stabi.py your_video_file.avi

You will see a window displaying original vs. stabilized frames side-by-side. The stabilized video is saved as compare.avi.

⚙️ Parameters You Can Tune

  • HORIZONTAL_BORDER_CROP: Controls cropping to avoid black borders.
  • Kalman filter parameters:
    • pstd: Process noise
    • cstd: Measurement noise

📸 Sample Output

Original Video Stabilized Video
Shaky frames Smooth motion

(Side-by-side comparison is shown in real time during execution.)

🧾 License

This project is open-source and available under the MIT License.

🙌 Credits

Developed using OpenCV and NumPy.

About

This project implements video stabilization using OpenCV. It estimates motion between frames and smooths the trajectory using a Kalman filter, generating a stabilized video output with side-by-side comparison.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages