File size: 7,637 Bytes
c6abe34 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | # 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
1. **Models Downloaded** β
- `player_detector.pt` (172.6 MB)
- `ball_detector_model.pt` (172.7 MB)
- `court_keypoint_detector.pt` (417.7 MB)
2. **System Structure** β
- All trackers, drawers, and detectors are in place
- Configuration files are set up
- Sample videos available in `input_videos/`
3. **Dependencies** β
- All required packages listed in `requirements.txt`
---
## π Testing the System
### Option 1: Automated Test Script (Recommended)
```bash
# 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
```bash
# 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:
1. **Player Detection & Tracking** - Identifies and tracks all players
2. **Ball Detection & Tracking** - Tracks the basketball with interpolation
3. **Court Keypoint Detection** - Identifies court lines and zones
4. **Team Assignment** - Classifies players by jersey color
5. **Ball Possession** - Determines which player has the ball
6. **Pass Detection** - Identifies passes between players
7. **Interception Detection** - Detects when passes are intercepted
8. **Tactical View** - Creates top-down tactical visualization
9. **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 detections
- `ball_track_stubs.pkl` - Cached ball detections
- `court_key_points_stub.pkl` - Cached court keypoints
- `player_assignment_stub.pkl` - Cached team assignments
To force fresh analysis, delete the `stubs/` directory.
---
## π₯ Adding Your Own Test Videos
1. Place basketball video files in `input_videos/`
2. Supported formats: `.mp4`, `.avi`
3. 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
```bash
pip install -r requirements.txt
```
### Issue: CUDA out of memory
**Solution**: Process smaller videos or use CPU
```bash
# The system will automatically fall back to CPU if GPU is unavailable
```
### Issue: Analysis is very slow
**Solutions**:
1. Use GPU if available
2. Process shorter video clips first
3. Reduce video resolution before processing
4. 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**:
1. Disk space available
2. Write permissions for `output_videos/`
3. Check console for error messages
---
## π Next Steps After Testing
Once you've verified the system works:
1. **Integrate with FastAPI Backend**
- Add video upload endpoints
- Process videos asynchronously
- Store results in Supabase
2. **Optimize Performance**
- Implement video preprocessing
- Add progress tracking
- Optimize for real-time processing
3. **Enhance Analysis**
- Add shot detection
- Implement player performance metrics
- Add game statistics
4. **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
1. **Start Small**: Test with short clips (10-30 seconds) first
2. **Use Stubs**: Keep the stub cache for faster iterations
3. **Monitor Resources**: Watch CPU/GPU usage and memory
4. **Check Output**: Verify each analysis component in the output video
5. **Iterate**: Adjust video quality and length based on results
---
## π Support
If you encounter issues:
1. Check error messages in console
2. Verify all dependencies are installed
3. Ensure models are correctly placed
4. Test with provided sample videos first
5. 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:**
```bash
python test_system.py --check-only
```
Then when ready to analyze:
```bash
python test_system.py
```
Good luck! π
|