Skip to main content

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

Project description

Trajectory Forecast

😍😍😍 You can use any Ultralytics-supported model here. 😍😍😍

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

1772592082361

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

pip install trajectory-forecast

Usage

CLI

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 the 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 run the code using the command mentioned 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

The contributions are always 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.3.tar.gz (21.8 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.3-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trajectory_forecast-0.0.3.tar.gz
  • Upload date:
  • Size: 21.8 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.3.tar.gz
Algorithm Hash digest
SHA256 b4833297766877d76de151c9923a5df51dec95ae0be4dd2d83da6ef565231f4c
MD5 e3a3bc13c42f9e8acb35f072b840c854
BLAKE2b-256 547ffa5df157556241a2cc848a9b4d14cccccebbffe2a18e49161d1564a7dbc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trajectory_forecast-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4e4e5b6a2ac78bbf1df21e3dfdfe5e528d874be8112b5dc61e2f1e8a3a60ce3b
MD5 970c8751a6cc1b9fca054576717d3a86
BLAKE2b-256 d67ecc1eb019745bcc893d525373366e83770d060562cc346170e2b60203c4c9

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