Skip to main content

A lightweight Python package for real-time object tracking and trajectory forecasting using Ultralytics YOLO.

Project description

Trajectory Forecast

Ultralytics 8.4.0 Python 3.10 | Python3.11 | Python 3.12 | 3.13 | 3.14 Visitors

Trajectory Forecast is a lightweight, modular extension built on top of Ultralytics YOLO that enables real-time multi-object tracking with future motion prediction. It combines detection, tracking, motion history modeling, and velocity-based forecasting into a unified pipeline that can be used both as a command-line tool and as a Python library. The system is designed for practical computer vision applications such as traffic analytics, surveillance systems, robotics pipelines, and edge AI deployments.

https://github.com/user-attachments/assets/9a1267c2-4ba4-49f6-9802-e80fed5e682f

Installation

Recommended (Development Mode)

python -m venv .venv
source .venv/bin/activate
pip install -e .

CLI (Command-Line)

Run tracking and forecasting on a video.

trajectory-forecast \
  --model yolo26n.pt \
  --source "https://tinyurl.com/bddswzba" \
  --output result.mp4

If you want to adjust tracking and forecasting configuration, create a config.yaml in directory and paste the mentioned content:

conf: 0.5                   # object detection confidence threshold
tracker: "bytetrack.yaml"   # tracker selection i.e "botsort.yaml" or "bytetrack.yaml"
classes: [2, 3, 5]          # classes for object detection
history: 40                 # store tracking history for number of frames
min_points: 8               # minimum tracking history to start calculating forecasting
forecast_steps: 35          # total steps for forecasting, > 40 can cause gitter effect.
vel_window: 10              # previous frames used to estimate the object's velocity.
ema_alpha: 0.7              # used to smooth the velocity or trajectory prediction.
forecast_color: [255, 0, 0] # Forecast point color (B, G, R)

After that, you can use the code using the mentioned command below.

trajectory-forecast \
  --model yolo26n.pt \
  --source "https://tinyurl.com/bddswzba" \
  --config "path/to/config.yaml"

Python

from tf import run_inference
from tf.config import ForecastConfig

config = ForecastConfig(
    conf=0.5,
    forecast_steps=50,
    ema_alpha=0.7,
    classes=[0, 2, 5, 6, 7],
)

run_inference(
    model_path="yolo26s.pt",
    source="https://tinyurl.com/2t2j2vs5",
    output_path="output.mp4",
    config=config,
)

Forecasting Methodology

The current forecasting implementation is based on:

  • Exponential moving average smoothing of object centers
  • Median velocity estimation over a sliding window
  • Linear projection of future positions
  • Stationary gating to prevent unstable predictions

This approach provides a stable and computationally efficient baseline suitable for real-time systems.

Project Structure

tf/
│
├── config.py        # Configuration system
├── drawing.py       # Visualization utilities
├── forecasting.py   # Velocity estimation and projection
├── tracker.py       # Track history management
├── inference.py     # Core pipeline
└── cli.py           # Command-line interface
└── utils.py         # For downloading assets from GitHub.

Contributing

Contributions are welcome. If you would like to extend the forecasting models or improve tracking integration, please open an issue or submit a pull request.

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

trajectory_forecast-0.0.2.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

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

trajectory_forecast-0.0.2-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file trajectory_forecast-0.0.2.tar.gz.

File metadata

  • Download URL: trajectory_forecast-0.0.2.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for trajectory_forecast-0.0.2.tar.gz
Algorithm Hash digest
SHA256 305b265e8dcb79bda8a73701a37e35d21da916e515b3dfc4d397fe1059bf7602
MD5 7775e1f6bd2a6c711872efc131f9f5e0
BLAKE2b-256 bf79ad9542acda1f7799f183e4e5153e0ef30b56416374e1f531dd99683cfb1c

See more details on using hashes here.

File details

Details for the file trajectory_forecast-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for trajectory_forecast-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5e78c920e9f2d321e325dea34e84e9b3b0cdfc32e9597e7a04379e3df85d6d24
MD5 5dd5118508cfdfb513ec01d3d60183bc
BLAKE2b-256 b1ae766530b400c24f48aaf1dd8ac3480afae08014603674ff205fd7d77cc4a2

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