A robust pipeline for tracking players in sports footage using YOLO for detection, DeepSORT for multi-object tracking, and a deep ReID model for appearance-based re-identification. This project is optimized for challenging, low-quality video and ensures consistent player IDs—even when players leave and re-enter the frame.
- Player Detection: YOLOv8 model detects players in each frame.
- Tracking: DeepSORT assigns persistent IDs, maintaining player identity across frames.
- Deep Re-Identification: Integrates OSNet (Torchreid) for robust appearance-based matching, reducing ID switches and improving re-identification after occlusion or re-entry.
- Fallback Appearance Features: Uses color histograms if deep embeddings are unavailable.
- Ghost Track Reduction: Filters out short-lived and ghost tracks with
max_ageand minimum track age. - Visualization: Draws bounding boxes, IDs, and (optionally) player trajectories.
- Optimized for Low-Quality Video: Tuned parameters and robust features handle missed detections and occlusions.
- Python 3.8+
- NVIDIA GPU (recommended for real-time performance)
All required packages are listed in requirements.txt:
ultralytics
opencv-python
numpy
deep-sort-realtime
torch
torchvision
torchreid
gdown
Install everything with:
pip install -r requirements.txtTip: For GPU acceleration, install the CUDA-enabled version of PyTorch matching your GPU and driver. See PyTorch installation instructions.
- Download the YOLO Model Weights
Download the YOLO model weights (best.pt) from the following link:
Place the file in your project directory before running the script. 2. Download the Input Video
Download the 15-second input video (15sec_input_720p.mp4) from the following link:
Place the file in your project directory before running the script. 3. Install all dependencies:
pip install -r requirements.txt- Run the tracking script:
python track_players.py- Press
qto exit the video display window.
| Parameter | Purpose | Typical Value |
|---|---|---|
max_age |
Frames to keep lost tracks before deletion | 7–15 (lower for noisy video) |
conf threshold |
Minimum detection confidence for tracking | 0.5–0.7 |
track.age |
Minimum frames before displaying a track | 3 |
- CUDA Errors: If you don't have a GPU or CUDA-enabled PyTorch, remove all
.cuda()or.to(device)calls and run on CPU. - Import Errors: If you see
ModuleNotFoundError, install the missing package withpip install <package>. - Performance: For real-time speed, use a GPU and consider a lighter ReID model.
- Save output video with OpenCV’s
VideoWriter. - Visualize player trajectories for movement analysis.
- Export tracking data to CSV for analytics.
- Fine-tune the ReID model on your own sports data for even better re-identification.
- Extend tracking to other classes (goalkeeper, referee, ball) by adjusting class filters.
This project is for educational and research purposes. Please respect the licenses of the underlying models and libraries you use.
- YOLO model: Ultralytics
- Tracking: DeepSORT
- ReID: Torchreid
- Video processing: OpenCV
For questions or improvements, open an issue or contact the project maintainer.
Ready to use! Fork, star, and contribute to make this tracker even better!