This guide will help you set up and run the Sports Analytics Application on your system.
- Python 3.8 or higher
- OpenCV (with camera support for live analysis)
- Webcam or video files for testing
- At least 4GB RAM (8GB recommended for optimal performance)
- GPU support (optional, for faster processing)
- ✅ Linux (Ubuntu 18.04+, CentOS 7+)
- ✅ Windows 10/11
- ✅ macOS 10.14+
git clone <repository-url>
cd sports-analytics# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows:
venv\Scripts\activate# Upgrade pip
pip install --upgrade pip
# Install required packages
pip install -r requirements.txtNote: The installation may take several minutes, especially for OpenCV and YOLO dependencies.
# Download YOLO models for object detection
python scripts/download_models.pyThis will download the YOLOv8n model (~6MB) which is optimized for speed and accuracy.
# Run the test suite
python test_app.pyYou should see all tests passing with green checkmarks.
python app.pyThe server will start on http://localhost:5000
Open your web browser and navigate to:
http://localhost:5000
- Connect Camera: Ensure your webcam is connected and accessible
- Start Analysis: Click "Start Live Analysis" button
- View Results: Real-time player tracking and analytics will appear
- Stop Analysis: Click "Stop Analysis" when finished
- Select Video: Click "Choose File" and select a sports video (MP4, AVI, etc.)
- Upload: Click "Upload & Analyze" button
- Monitor Progress: Watch the progress bar as the video is processed
- View Results: Analysis results will appear in the dashboard
- Real-time Player Tracking: See player IDs and movement trajectories
- Ball Tracking: Track ball position and movement
- Tactical Analysis: View team formations and player spacing
- Performance Metrics: Individual and team performance statistics
- Referee Assistance: Offside detection and foul analysis
# Check camera availability
python -c "import cv2; print(cv2.VideoCapture(0).isOpened())"Solution: Ensure camera permissions are granted and no other application is using the camera.
# Manual download
wget https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt
mkdir -p models
mv yolov8n.pt models/# For Ubuntu/Debian
sudo apt-get update
sudo apt-get install python3-opencv
# For macOS
brew install opencv
# For Windows
pip install opencv-pythonIf you encounter memory errors:
- Reduce video resolution
- Use smaller YOLO model (yolov8n.pt)
- Close other applications
- Increase system swap space
For better performance:
- Use GPU acceleration (if available)
- Reduce frame processing rate
- Use smaller video files for testing
pip install opencv-pythonpip install ultralytics# Linux
sudo usermod -a -G video $USER
# Then log out and log back inCreate a .env file in the project root:
FLASK_ENV=development
FLASK_DEBUG=1
CAMERA_INDEX=0
MODEL_PATH=models/yolov8n.ptEdit app.py to modify:
- Camera index for live analysis
- Video processing parameters
- WebSocket settings
- Upload file size limits
sports-analytics/
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── utils/ # Core analysis modules
│ ├── video_processor.py
│ ├── player_tracker.py
│ ├── ball_tracker.py
│ ├── tactical_analyzer.py
│ ├── performance_analyzer.py
│ └── referee_assistant.py
├── templates/ # HTML templates
├── static/ # Static files
├── uploads/ # Uploaded videos
├── models/ # AI models
├── scripts/ # Setup scripts
└── data/ # Sample data
- Create new module in
utils/ - Import in
app.py - Add WebSocket events for real-time updates
- Update frontend to display new data
-
Use Production WSGI Server:
pip install gunicorn gunicorn -w 4 -k uvicorn.workers.UvicornWorker app:app
-
Enable GPU Acceleration:
pip install torch torchvision
-
Optimize Model Loading:
- Pre-load models on startup
- Use model caching
- Implement lazy loading
-
Database Integration:
- Add PostgreSQL for data persistence
- Implement caching with Redis
- Add user authentication
- Check the troubleshooting section above
- Review error logs in the console
- Test with sample videos first
- Ensure all dependencies are installed
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- YOLO: Real-time object detection
- OpenCV: Computer vision library
- Flask: Web framework
- Socket.IO: Real-time communication
- MediaPipe: Pose estimation (optional)
Happy Analyzing! 🏈⚽🏀