Detects and tracks football players in video using YOLOv8 and BoT-SORT.
# Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
# Install dependencies
pip install ultralytics opencv-python lap
# Run detection
python detect_players.py- Uses YOLOv8n (nano) pre-trained on COCO dataset
- Filters detections to class 0 ("person") only
- Confidence threshold: 0.3
- Can swap to
yolov8s/m/l/xfor better accuracy (slower)
- BoT-SORT (Bag of Tricks for SORT) tracker
- Combines Kalman filter motion prediction with appearance features (Re-ID)
- Handles occlusions and maintains consistent IDs across frames
- Well-suited for sports with fast, erratic movement
Video Frame → YOLOv8 Detection → BoT-SORT Association → Annotated Frame
↓ ↓
Person boxes Track IDs assigned
+ confidence + history maintained
- Colored bounding boxes (unique per player)
- Labels:
Player {ID} {confidence} - Yellow movement trails (last 30 positions)
Edit detect_players.py to change:
max_seconds- Duration to process (default: 10s)conf- Detection confidence threshold (default: 0.3)- Model size - Replace
yolov8n.ptwithyolov8m.ptfor better accuracy
Generates output_annotated.mp4 with tracked players labeled and color-coded.