Automated football tactical analysis engine using Computer Vision
Project description
Tactix — Automated Football Tactical Analysis Engine
Turn broadcast footage into tactical intelligence.
Computer vision pipeline that detects players, tracks movements, classifies teams,
and generates 2D tactical minimaps with rich analytical overlays.
Features
Core Vision Pipeline
- Player & Ball Detection — YOLOv8 / YOLO26x detects players, goalkeepers, referees, and the ball in every frame
- Multi-Object Tracking — ByteTrack (via Supervision) assigns persistent IDs across frames with occlusion handling
- Team Classification — K-Means clustering on jersey colors with cross-frame voting (
PlayerRegistry); confirms team after 5 frames with ≥70% majority - Jersey Number OCR — EasyOCR-based detection (0–99) with multi-ROI crops, CLAHE/binary preprocessing, and two-digit recovery heuristic; runs every Nth frame for performance
- Ball Interpolation — Forward-projects ball position during detection gaps (up to 10 frames) via linear extrapolation
Pitch Calibration
| Mode | Description |
|---|---|
| AI Only | Fully automatic — YOLO-Pose detects 27 pitch keypoints |
| Manual Fixed | Interactive point selection + optical flow fallback |
| Panorama | Manual initialization + global camera motion tracking (Pan/Tilt/Zoom) |
Computes a 3×3 homography matrix to map pixel coordinates to real-world pitch coordinates (105×68m).
Tactical Analysis
| Module | Description |
|---|---|
| Voronoi / Space Control | Which team dominates which area of the pitch |
| Heatmap | Cumulative movement density per team |
| Pass Network | Passing lane frequency graph between teammates |
| Pressure Index | Defensive pressure (opponent count within configurable radius) |
| Cover Shadow | Blocked passing lanes visualization |
| Team Compactness | Convex hull of team shape |
| Team Centroid | Center of mass for each team |
| Team Width & Length | Spatial dimensions of team shape |
| Velocity Vectors | Player movement direction and speed |
Phase Analysis
| Phase | Modules |
|---|---|
| Attacking | Shot Map, Pass Sonar (8-sector directional), Zone 14 Analysis, Build-up Sequence Tracker |
| Defense | Duel Heatmap (spatial distribution of 1v1 contests) |
| Transition | Attack transitions (recovery → shot, ≤15s) and defensive transitions (loss → recovery, ≤30s) |
| Set Pieces | Corner Kick Analyzer, Free Kick Analyzer (with wall detection and xG estimation) |
Formation Detection
Detects team formations (4-3-3, 4-2-3-1, 3-5-2, etc.) via K-Means clustering on player positions; matched against 17+ canonical templates with sliding-window temporal smoothing.
Event Detection
Automatically detects match events in real-time:
- Possession Changes — Ball ownership transfer with confirmation delay
- Passes — Intra-team ball transfers with origin, destination, distance, angle
- Shots — High ball velocity toward goal with outcome classification (goal/saved/blocked/off-target)
- Duels — 1v1 contests between opposing players with winner determination
- Corners — Corner kicks with side, taker, and outcome tracking
- Free Kicks — Defensive wall detection, xG estimation, outcome tracking
Data Export
| Format | Output | Description |
|---|---|---|
| FIFA EPTS STF | match_metadata.xml + match_tracking.dat |
Tracab-compatible tracking data, loadable via kloppy. Center-origin coordinates in centimeters |
| PDF Report | match_report.pdf |
Multi-page post-match tactical report with stats and visualizations |
| Cache | Pickle file | Optional frame-level tracking cache for re-processing |
Tech Stack
| Component | Technology |
|---|---|
| Language | Python 3.12+ |
| Object Detection | Ultralytics YOLOv8 / YOLO26x |
| Tracking | ByteTrack via Supervision |
| Computer Vision | OpenCV (homography, optical flow, Voronoi, heatmaps) |
| Team Classification | Scikit-learn K-Means |
| Jersey OCR | EasyOCR (optional) |
| PDF Reports | ReportLab + Pillow |
| GPU | Apple Metal (mps), CUDA, or CPU |
Getting Started
Installation
# Python 3.12+ required
pip install -r requirements.txt
# Optional: Jersey number detection
pip install easyocr>=1.7.1
Configuration
All settings are in tactix/config.py. Key options:
# Input / Output
INPUT_VIDEO = "assets/samples/test2.mp4"
OUTPUT_VIDEO = "assets/output/test2_Result.mp4"
# Device (GPU acceleration)
DEVICE = "mps" # "cuda" or "cpu"
# Calibration
CALIBRATION_MODE = CalibrationMode.PANORAMA # AI_ONLY | MANUAL_FIXED | PANORAMA
INTERACTIVE_MODE = False # True → manual point calibration UI
# Export toggles
EXPORT_STF = False # FIFA EPTS Standard Transfer Format
EXPORT_PDF = False # PDF tactical report
# FIFA STF metadata (used when EXPORT_STF = True)
STF_MATCH_ID = "TACTIX-001"
STF_HOME_TEAM_NAME = "Home"
STF_AWAY_TEAM_NAME = "Away"
Running
python run.py
Interactive mode (INTERACTIVE_MODE = True):
- First frame appears — click on visible pitch landmarks (corner flags, penalty box corners, etc.)
- Enter the corresponding keypoint ID shown in the console
- Repeat for at least 4 points
- Press
qorEscto start analysis
Visualization menu appears before processing:
- Toggle overlays (Voronoi, Heatmap, Pass Network, etc.) by entering their number
- Press
rto run,qto quit
Output
| File | Description |
|---|---|
assets/output/*_Result.mp4 |
Annotated video with tactical overlays and minimap |
| assets/output/stf/match_metadata.xml | Tracab-compatible metadata (teams, rosters, jersey numbers) |
| assets/output/stf/match_tracking.dat | Tracab DAT raw tracking data (per-frame positions & speeds) |
| assets/output/match_report.pdf | Multi-page tactical analysis report |
Loading tracking data with kloppy
from kloppy import tracab
dataset = tracab.load(
meta_data="assets/output/stf/match_metadata.xml",
raw_data="assets/output/stf/match_tracking.dat",
)
df = dataset.to_df()
print(df.head())
Architecture
Pipeline Stages
Frame → Calibration → Detection → Ball Interpolation → Tracking →
Team Classification → Jersey OCR → Coordinate Mapping →
Event Detection → Tactical Analysis → Visualization → Export
Data Flow
All data flows through FrameData — one instance per frame, acting as the central data bus between pipeline stages. Side-channel state (PlayerRegistry, BallStateTracker, EventDetector) lives on the engine, not on the per-frame bus.
Project Structure
Tactix/
├── run.py # Entry point
├── requirements.txt
├── tactix/
│ ├── config.py # Central configuration
│ ├── core/ # Data types, keypoints, geometry, events, registry
│ ├── engine/ # TactixEngine — main pipeline loop
│ ├── models/ # Model interface abstraction
│ ├── vision/
│ │ ├── detector.py # YOLO detection wrapper
│ │ ├── tracker.py # ByteTrack tracking wrapper
│ │ ├── transformer.py # Homography (pixel ↔ meters)
│ │ ├── camera.py # Optical flow camera stabilization
│ │ └── calibration/ # AI, Manual, Panorama estimators
│ ├── semantics/
│ │ ├── team.py # K-Means team classification
│ │ └── jersey_ocr.py # Jersey number detection
│ ├── analytics/
│ │ ├── base/ # Heatmap, pass network, pressure index
│ │ ├── attacking/ # Shot map, pass sonar, zone 14, build-up
│ │ ├── defense/ # Duel heatmap
│ │ ├── transition/ # Attack/defense transition tracker
│ │ ├── set_pieces/ # Corner & free kick analyzers
│ │ ├── formation/ # Formation detector
│ │ └── events/ # Event detector (passes, shots, duels, etc.)
│ ├── visualization/
│ │ ├── minimap.py # 2D tactical minimap renderer
│ │ └── overlays/ # RGBA overlay renderers for each analysis module
│ ├── export/
│ │ ├── stf_exporter.py # FIFA EPTS Standard Transfer Format
│ │ ├── pdf_exporter.py # PDF tactical report
│ │ └── cache.py # Pickle tracking cache
│ ├── ui/ # Calibration UI, visualization menu
│ └── utils/ # Video I/O, pitch generation
├── assets/
│ ├── weights/ # YOLO model weights
│ ├── samples/ # Input videos
│ └── output/ # Generated output
├── datasets/ # Training datasets
├── training/ # Model training scripts
└── notebooks/ # Experimentation
License
See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tactix-0.1.0.tar.gz.
File metadata
- Download URL: tactix-0.1.0.tar.gz
- Upload date:
- Size: 99.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0e091d95178bec6d1878df8b82d227d4904f4b6817a3d5719522333dbaf5ff1
|
|
| MD5 |
6a73caf7bda94f0b8a57c46e31784df0
|
|
| BLAKE2b-256 |
8f5ca64f05dae7de3fab6a5e5ce1f085387e1e8e5bc44aabb5ae7b6068fa8464
|
File details
Details for the file tactix-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tactix-0.1.0-py3-none-any.whl
- Upload date:
- Size: 126.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47ea9d508cb3512e2b925b9dea8e0468ffb36827f609eb2e74c96438894430c6
|
|
| MD5 |
097989548df9c10abc8c663fc94d7433
|
|
| BLAKE2b-256 |
44ac6e3322722e8bab6561b06c798b8ff8bffe605785a95efbbcdaa23a66afc2
|