A computer vision system for analyzing cornhole games using YOLO object detection and tracking. The system detects specific objects in cornhole gameplay videos and provides annotation capabilities.
The primary goal is to detect and analyze cornhole game elements (players, sandbags, board) to provide automated scoring and game statistics. Currently, the system focuses on object detection and video annotation for specific game elements.
- Object Detection: YOLOv8n model integration for detecting objects in cornhole videos
- Custom Label Filtering: System filters detections to only include objects from
labels.yaml - Video Annotation: Automatic annotation of detected objects on video frames
- Object Tracking: YOLO tracking with persistence across frames
- Output Generation: Creates annotated videos and logs detected objects
Based on labels.yaml, the system currently detects:
- Frisbee (as proxy for sandbags)
- Sports Ball (additional game elements)
- Kite (testing object)
detected_objects.txt- List of unique objects detected in the videooutputs/output.mp4- Annotated video with bounding boxes and labels
cornhole-game-analyzer/
βββ π models/ # YOLO model weights
β βββ yolov8n.pt # Pre-trained YOLOv8n model
βββ π outputs/ # Generated output files
β βββ output.mp4 # Annotated video output
βββ π samples/ # Input video samples
βββ π venv/ # Python virtual environment
βββ π .venv/ # Alternative virtual environment
βββ π app.py # Streamlit web interface
βββ π main.py # Core video processing pipeline
βββ π tracker.py # YOLO object detection and tracking
βββ π scorer.py # Scoring logic (placeholder)
βββ π utils.py # Utility functions for video handling
βββ π labels.yaml # Custom object labels configuration
βββ π requirements.txt # Python dependencies
βββ π download_model.py # Model download script
βββ π Makefile # Build and run automation
βββ π README.md # This file
βββ π LICENSE # Project license
- Purpose: Orchestrates the entire video analysis workflow
- Key Functions:
process_video(): Main entry point for video processing- Handles FPS detection and video output generation
- Coordinates between tracking and scoring modules
- Purpose: Handles YOLO-based object detection and tracking
- Key Functions:
track_players_and_bags(): Main tracking functionfilter_results_by_labels(): Filters detections to custom labelswrite_detected_objects_to_file(): Logs unique detected objectsload_custom_labels(): Loads labels fromlabels.yaml
- Purpose: Analyzes bag positions to determine scoring
- Status: Currently a placeholder for future scoring implementation
- Future: Will analyze bag trajectories and landing positions
- Purpose: Handles video file operations
- Key Functions:
save_annotated_video(): Saves processed videos with annotations
track_labels:
- frisbee # Proxy for sandbags
- sports ball # Additional game elements
- kite # Testing object- Core:
ultralytics,opencv-python,torch - Web Interface:
streamlit - Data Processing:
numpy,pandas,moviepy - Configuration:
PyYAML
- Purpose: Provides web-based interface for video upload and processing
- Features: File upload, processing status, result display
- Purpose: Provides convenient commands for common tasks
- Commands: Model download, environment setup, app running
- Upload video through Streamlit interface or direct file processing
- System supports common video formats (MP4, AVI, etc.)
- YOLOv8n model processes each video frame
- Detects all objects present in the frame
- Filters results to only include objects from
labels.yaml
- YOLO tracking with persistence across frames
- Maintains object IDs throughout the video
- Handles object occlusion and re-appearance
- Draws bounding boxes around detected objects
- Labels objects with their class names
- Shows tracking IDs for persistent objects
- Creates annotated video in
outputs/directory - Generates
detected_objects.txtwith unique object list - Provides processing statistics and logs
- Model Retraining: Train YOLO model specifically on cornhole sandbags
- Dataset Collection: Gather cornhole game videos with sandbag annotations
- Label Updates: Update
labels.yamlto include proper sandbag labels - Model Integration: Replace current model with custom-trained sandbag detector
- Scoring Algorithm: Implement automatic scoring based on bag positions
- Player Tracking: Separate player detection from bag detection
- Game Statistics: Generate player performance metrics
- Real-time Processing: Enable live video analysis
- Multi-camera Support: Handle multiple camera angles
- Python 3.8+
- CUDA-compatible GPU (optional, for faster processing)
# Clone the repository
git clone <repository-url>
cd cornhole-game-analyzer
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
make install
# Download YOLO model
make download-model
# make help
make help# Run Streamlit web interface
make run- Base Model: YOLOv8n (nano variant for speed)
- Input: Video frames (RGB)
- Output: Bounding boxes, class labels, confidence scores
- Tracking: YOLO's built-in tracking with persistence
- YOLOv8n provides good balance of speed and accuracy
- GPU acceleration recommended for real-time processing
- Video processing time depends on video length and resolution
- Modify
labels.yamlto change detection targets - Adjust confidence thresholds in tracker.py
- Customize annotation styles in utils.py
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.