Skip to main content

Stabilizes video or extracted trajectories with respect to a selected reference frame in the video, with optional user-provided masks.

Project description

Stabilo

PyPI Version GitHub Release Python License Development Status Open Access arXiv Archived Code PyPi - Total Downloads PyPI - Downloads per Month

Stabilo is a specialized Python package for stabilizing video frames or tracked object trajectories in videos, using robust homography or affine transformations. Its core functionality focuses on aligning each frame or object track to a chosen reference frame, enabling precise stabilization that mitigates disturbances like camera movements. Key features include robust keypoint-based image registration and the option to integrate user-defined masks, which exclude dynamic regions (e.g., moving objects) to enhance stabilization accuracy. Integrating seamlessly with object detection and tracking algorithms, Stabilo is ideal for high-precision applications like urban traffic monitoring, as demonstrated in the Geo-trax 🚀 trajectory extraction framework. Extensive transformation and enhancement options, including multiple feature detectors and matchers, masking techniques, further expand its utility. For systematic evaluation and hyperparameter tuning, the companion tool Stabilo-Optimize 🎯 provides a dedicated benchmarking framework. The repository also includes valuable resources like utility scripts and example videos to demonstrate its capabilities.

Stabilization Visualization GIF

Features

  • Video Stabilization: Align (warp) all video frames to a custom (anchor) reference frame using homography or affine transformations.
  • Trajectory Stabilization: Transform object trajectories (e.g., bounding boxes) to a common fixed reference frame using homography or affine transformations.
  • User-Defined Masks: Allow users to specify custom masks to exclude regions of interest during stabilization, supporting both axis-aligned and oriented bounding boxes (OBBs).
  • Wide Range of Algorithms: Includes support for various feature detectors (ORB, SIFT, RSIFT, BRISK, KAZE, AKAZE), matchers (BF, FLANN), RANSAC algorithms (MAGSAC++, DEGENSAC, ...), transformation types, and pre-processing options.
  • Customizable Parameters: Fine-tune the stabilization by adjusting parameters such as the number of keypoints, RANSAC parameters, matching thresholds, downsampling factors, etc..
  • Visualization Tools: Generate visualizations of the stabilization process, with frame-by-frame comparisons and trajectory transformations (see the above animation).
  • Threshold Analysis: Analyze the relationship between detection thresholds and keypoint counts for BRISK, KAZE, and AKAZE to fairly benchmark with different detectors.
  • Benchmarking and Optimization: Fine-tune stabilization parameters with Stabilo-Optimize 🎯, which provides ground truth-free evaluation using random perturbations.
🚀 Planned Enhancements
  • Unit Tests: Comprehensive unit test suite to ensure package stability and reliability.
  • Additional Mask Types: Inclusion of additional mask types (e.g., polygonal, circular) for enhanced precision in stabilization.
  • GPU Acceleration: Integration of GPU acceleration to improve processing speed.
  • Documentation: Detailed documentation covering the package’s functionality and usage.

Installation

It is recommended to create and activate a Python Virtual Environment (Python >= 3.9) first using e.g., Miniconda3:

conda create -n stabilo python=3.11 -y
conda activate stabilo

Then, install the stabilo library using one of the following options:

Option 1: Install from PyPI

pip install stabilo

Option 2: Install from Local Source

You can also clone the repository and install the package from the local source:

git clone https://github.com/rfonod/stabilo.git
cd stabilo && pip install .

If you want the changes you make in the repo to be reflected in your install, use pip install -e . instead of pip install ..

Python API Usage

from stabilo import Stabilizer 

# Create an instance of the Stabilizer class with default parameters
stabilizer = Stabilizer() 

# Set a reference frame with (optional) mask
stabilizer.set_ref_frame(ref_frame, ref_mask)

# Stabilize any frame with (optional) mask
stabilizer.stabilize(cur_frame, cur_mask)

# Get the stabilized (warped) frame 
stabilized_frame = stabilizer.warp_cur_frame()

# Transform current masks (bounding boxes) if it was provided
stabilized_boxes = stabilizer.transform_cur_boxes()

# Transform any point (pixel coordinates) from the current frame to reference frame
cur_point = np.array([x, y, 1])
ref_point = stabilizer.get_cur_trans_matrix() @ cur_point

Bounding Box Formats

Stabilo supports multiple bounding box formats for masks and transformations:

  • xywh: Axis-aligned boxes [x_center, y_center, width, height]
  • xywha: Oriented bounding boxes [x_center, y_center, width, height, angle_degrees]
  • four: Four corner points [x1, y1, x2, y2, x3, y3, x4, y4] (auto-detects if rotated)
import numpy as np

# Example with oriented bounding boxes (OBBs)
obb_boxes = np.array([
    [100, 150, 50, 30, 45],  # Rotated 45 degrees
    [200, 200, 60, 40, 90],  # Rotated 90 degrees
])

stabilizer.set_ref_frame(ref_frame, obb_boxes, box_format='xywha')
stabilizer.stabilize(cur_frame, cur_boxes, box_format='xywha')

# Transform boxes and get result in different format
transformed = stabilizer.transform_cur_boxes(out_box_format='four')

Utility Scripts

Utility scripts are provided to demonstrate the functionality of the Stabilo package. These scripts can be found in the scripts directory and are briefly documented in the scripts README.

Stabilization Examples

  • stabilize_video.py: Implements video stabilization relative to a reference frame.
  • stabilize_boxes.py: Implements object trajectory stabilization relative to a reference frame.

Threshold Analysis

  • find_threshold_models.py: Computes regression models between detection thresholds and average keypoint counts for BRISK, KAZE, and AKAZE feature detectors.

Citing This Work

If you use Stabilo in your research, software, or product, please cite the following resources appropriately:

  1. Preferred Citation: Please cite the associated article for any use of the Stabilo package, including research, applications, and derivative work:

    @article{fonod2025advanced,
      title = {Advanced computer vision for extracting georeferenced vehicle trajectories from drone imagery},
      author = {Fonod, Robert and Cho, Haechan and Yeo, Hwasoo and Geroliminis, Nikolas},
      journal = {Transportation Research Part C: Emerging Technologies},
      volume = {178},
      pages = {105205},
      year = {2025},
      publisher = {Elsevier},
      doi = {10.1016/j.trc.2025.105205},
      url = {https://doi.org/10.1016/j.trc.2025.105205}
    }
    
  2. Repository Citation: If you reference, modify, or build upon the Stabilo software itself, please also cite the corresponding Zenodo release:

    @software{fonod2025stabilo,
      author = {Fonod, Robert},
      license = {MIT},
      month = nov,
      title = {Stabilo: A Comprehensive Python Library for Video and Trajectory Stabilization with User-Defined Masks},
      url = {https://github.com/rfonod/stabilo},
      doi = {10.5281/zenodo.12117092},
      version = {1.1.0},
      year = {2025}
    }
    

Contributing

Contributions from the community are welcome! If you encounter any issues or have suggestions for improvements, please open a GitHub Issue or submit a pull request.

License

This project is distributed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stabilo-1.1.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stabilo-1.1.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file stabilo-1.1.0.tar.gz.

File metadata

  • Download URL: stabilo-1.1.0.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.20

File hashes

Hashes for stabilo-1.1.0.tar.gz
Algorithm Hash digest
SHA256 fbf6f33f63d1500b10a9c48de26f4348decd6219c422b3cc94360a873edfc8dd
MD5 564272fa6010a95265cc735df16ec186
BLAKE2b-256 f8e79cd6798260ff19da5bc80dd499610a469fdfca167012432be5d1e1d8becc

See more details on using hashes here.

File details

Details for the file stabilo-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: stabilo-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.20

File hashes

Hashes for stabilo-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c8c9ce4c2862c6df1e25e5b353e4b1703900eff0fb207a42162ff5bd52f3860
MD5 117fdbd6ab5e50358abddd6945a21767
BLAKE2b-256 70d8c0b21bce3a89cd20cb923d90772bd3d35c5489364e95901ae3cd277aea94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page