Basketball Analysis System - Testing Guide
π― Quick Start
Your system is now ready to test with the pre-trained models from the basketball_analysis repository!
β What's Already Set Up
Models Downloaded β
player_detector.pt(172.6 MB)ball_detector_model.pt(172.7 MB)court_keypoint_detector.pt(417.7 MB)
System Structure β
- All trackers, drawers, and detectors are in place
- Configuration files are set up
- Sample videos available in
input_videos/
Dependencies β
- All required packages listed in
requirements.txt
- All required packages listed in
π Testing the System
Option 1: Automated Test Script (Recommended)
# 1. Check system setup (no analysis)
python test_system.py --check-only
# 2. Run full test with first available video
python test_system.py
# 3. Test with specific video
python test_system.py --video input_videos/video_1.mp4
# 4. Test with custom output path
python test_system.py --video input_videos/video_1.mp4 --output output_videos/my_analysis.avi
Option 2: Direct Analysis with main.py
# Basic usage
python main.py input_videos/video_1.mp4
# With custom output
python main.py input_videos/video_1.mp4 --output_video output_videos/analyzed_video.avi
# With custom stub path (for caching intermediate results)
python main.py input_videos/video_1.mp4 --stub_path my_stubs
π Directory Structure
back-end/
βββ models/ # β Pre-trained models
β βββ player_detector.pt
β βββ ball_detector_model.pt
β βββ court_keypoint_detector.pt
βββ input_videos/ # Place your test videos here
β βββ video_1.mp4
β βββ video_2.mp4
β βββ video_3.mp4
βββ output_videos/ # Analysis results will be saved here
βββ stubs/ # Cached intermediate results (auto-created)
βββ images/ # Court reference images
β βββ basketball_court.png
βββ main.py # Main analysis pipeline
βββ test_system.py # System testing script
βββ requirements.txt # Python dependencies
π¬ What the Analysis Does
The system performs comprehensive basketball video analysis:
- Player Detection & Tracking - Identifies and tracks all players
- Ball Detection & Tracking - Tracks the basketball with interpolation
- Court Keypoint Detection - Identifies court lines and zones
- Team Assignment - Classifies players by jersey color
- Ball Possession - Determines which player has the ball
- Pass Detection - Identifies passes between players
- Interception Detection - Detects when passes are intercepted
- Tactical View - Creates top-down tactical visualization
- Speed & Distance - Calculates player movement metrics
Output Features
The analyzed video includes:
- Player bounding boxes with team colors
- Ball tracking visualization
- Court keypoint overlays
- Team ball control statistics
- Pass and interception markers
- Tactical view (mini-map)
- Player speed and distance metrics
- Frame numbers
π§ System Requirements
Minimum Requirements
- Python 3.8+
- 8GB RAM
- CPU: Multi-core processor
- Storage: 2GB free space
Recommended for Better Performance
- Python 3.10+
- 16GB+ RAM
- GPU: NVIDIA GPU with CUDA support
- Storage: 5GB+ free space
π Performance Expectations
Processing Time (approximate)
- CPU Only: 5-15 minutes per minute of video
- With GPU: 1-3 minutes per minute of video
First Run vs. Subsequent Runs
- First Run: Slower (no cached stubs)
- Subsequent Runs: Much faster (uses cached stubs)
The system uses "stubs" (cached intermediate results) to speed up repeated processing:
player_track_stubs.pkl- Cached player detectionsball_track_stubs.pkl- Cached ball detectionscourt_key_points_stub.pkl- Cached court keypointsplayer_assignment_stub.pkl- Cached team assignments
To force fresh analysis, delete the stubs/ directory.
π₯ Adding Your Own Test Videos
- Place basketball video files in
input_videos/ - Supported formats:
.mp4,.avi - Recommended:
- Resolution: 720p or 1080p
- Frame rate: 30fps or higher
- Clear view of the court
- Good lighting conditions
Good Test Videos Should Have:
β Clear view of basketball court β Multiple players visible β Ball clearly visible β Court lines visible β Stable camera angle (not too much movement)
π Troubleshooting
Issue: "Module not found" errors
Solution: Install dependencies
pip install -r requirements.txt
Issue: CUDA out of memory
Solution: Process smaller videos or use CPU
# The system will automatically fall back to CPU if GPU is unavailable
Issue: Analysis is very slow
Solutions:
- Use GPU if available
- Process shorter video clips first
- Reduce video resolution before processing
- Use stub caching (enabled by default)
Issue: Poor detection quality
Possible causes:
- Low video quality
- Poor lighting
- Obstructed view of court
- Non-standard camera angle
Solutions:
- Use higher quality source videos
- Ensure good lighting in videos
- Use videos with clear court view
Issue: Output video not created
Check:
- Disk space available
- Write permissions for
output_videos/ - Check console for error messages
π Next Steps After Testing
Once you've verified the system works:
Integrate with FastAPI Backend
- Add video upload endpoints
- Process videos asynchronously
- Store results in Supabase
Optimize Performance
- Implement video preprocessing
- Add progress tracking
- Optimize for real-time processing
Enhance Analysis
- Add shot detection
- Implement player performance metrics
- Add game statistics
Frontend Integration
- Display analysis results
- Show tactical view
- Present player statistics
π Verification Checklist
Before running analysis on your own videos:
- All dependencies installed (
test_system.py --check-only) - All models present and loading correctly
- Test video successfully analyzed
- Output video created and viewable
- All analysis features working (players, ball, court, etc.)
- Stub caching working (second run faster)
π‘ Tips for Best Results
- Start Small: Test with short clips (10-30 seconds) first
- Use Stubs: Keep the stub cache for faster iterations
- Monitor Resources: Watch CPU/GPU usage and memory
- Check Output: Verify each analysis component in the output video
- Iterate: Adjust video quality and length based on results
π Support
If you encounter issues:
- Check error messages in console
- Verify all dependencies are installed
- Ensure models are correctly placed
- Test with provided sample videos first
- Check system resources (RAM, disk space)
π Success Indicators
Your system is working correctly if: β Test script completes without errors β Output video is created β Players are detected and tracked β Ball is tracked with smooth interpolation β Court keypoints are detected β Teams are correctly assigned β Tactical view is displayed β Speed/distance metrics are shown
Ready to test? Run:
python test_system.py --check-only
Then when ready to analyze:
python test_system.py
Good luck! π