ddlsandeep/cricket-video-annotation
0
๐ Cricket Video Annotation Project
A comprehensive web-based video annotation system for cricket analysis, featuring video frame extraction, web-based annotation tools, and YOLO-compatible dataset export.
๐ Table of Contents
- Features
- System Requirements
- Installation
- Quick Start
- Usage Guide
- Project Structure
- API Documentation
- Troubleshooting
- Contributing
โจ Features
๐ฅ Video Processing
- Video Upload: Support for common video formats (MP4, AVI, MOV, etc.)
- Frame Extraction: Extract frames with customizable intervals (every Nth frame)
- High-Quality Output: JPEG frames with 95% quality preservation
- Timestamp Preservation: Frame naming includes temporal information
๐๏ธ Annotation Tools
- Web-Based Annotator: Integrated annotation interface
- Multiple Classes: Cricket Ball (0), Bat (1), Player (2)
- Bounding Box Drawing: Click and drag to create annotations
- Frame Navigation: Arrow key navigation between frames
- Real-time Updates: Instant annotation saving and loading
๐ Export & Dataset Generation
- YOLO v8-v10 Compatible: Ready-to-use dataset format
- Train/Val Split: Automatic dataset splitting (configurable ratio)
- Multiple Export Formats:
- Complete YOLO dataset (ZIP)
- Individual frame annotations
- JSON format for detailed analysis
- Dataset Statistics: Comprehensive annotation metrics
๐ง Technical Features
- Python 3.12 Compatible: Modern Python support
- Flask Web Framework: Lightweight and fast
- OpenCV Integration: Robust video processing
- Cross-Platform: Windows, macOS, Linux support
- Responsive UI: Modern, mobile-friendly interface
๐ป System Requirements
Minimum Requirements
- Python: 3.8 or higher (3.12 recommended)
- RAM: 4GB minimum, 8GB recommended
- Storage: 1GB free space minimum
- Browser: Modern browser (Chrome, Firefox, Safari, Edge)
Recommended Requirements
- Python: 3.12
- RAM: 16GB for large video processing
- Storage: 10GB+ for video datasets
- GPU: Optional, for faster video processing
๐ Installation
1. Clone the Repository
git clone <repository-url>
cd Cricket2. Create Virtual Environment (Recommended)
# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activate3. Install Dependencies
pip install -r requirements.txt4. Verify Installation
python test_flow.pyโก Quick Start
1. Start the Application
python app.py2. Access the Web Interface
Open your browser and navigate to: http://localhost:5000
3. Upload a Video
- Click "Select video" to choose your cricket video file
- Set frame extraction interval (default: every frame)
- Click "Convert to frames"
4. Annotate Frames
- Click "๐๏ธ Web Annotator" button
- Select a frame to annotate
- Draw bounding boxes for cricket objects
- Navigate between frames using arrow keys
5. Export Dataset
- Use export buttons to download YOLO-compatible dataset
- Choose train/validation split ratio
- Download complete dataset ZIP file
๐ Usage Guide
Video Upload and Processing
Supported Video Formats
- MP4 (recommended)
- AVI
- MOV
- MKV
- WebM
Frame Extraction Options
- Every Frame: Extract all frames (default)
- Every Nth Frame: Extract every N frames (e.g., every 5th frame)
- Custom Interval: Set specific frame extraction rate
Frame Naming Convention
{video_name}_frame_{frame_number:06d}_{timestamp_nanoseconds}.jpgExample: cricket_match_frame_000123_1234567890.jpg
Annotation Interface
Getting Started
- Access Annotator: Click "๐๏ธ Web Annotator" from results page
- Select Frame: Click on any frame thumbnail to open annotation view
- Draw Boxes: Click and drag to create bounding boxes
- Class Selection: Choose object class (Ball, Bat, Player)
- Save: Annotations are automatically saved
Keyboard Shortcuts
- โ โ Arrow Keys: Navigate between frames
- Delete: Remove selected annotation box
- Escape: Cancel current drawing operation
Annotation Classes
Dataset Export
YOLO Dataset Format
The system generates YOLO v8-v10 compatible datasets with the following structure:
dataset/
โโโ images/
โ โโโ train/ # Training images
โ โโโ val/ # Validation images
โโโ labels/
โ โโโ train/ # Training labels
โ โโโ val/ # Validation labels
โโโ data.yaml # YOLO configuration
โโโ README.txt # Dataset documentationExport Options
- Complete Dataset: Full YOLO-compatible ZIP file
- Legacy Format: Single directory with all images
- Individual Frames: Export annotations per frame
- JSON Format: Detailed annotation data
Training Split Configuration
- Default: 80% training, 20% validation
- Customizable: Set train/val ratio via URL parameter
- Random Split: Ensures unbiased dataset distribution
๐ Project Structure
Cricket/
โโโ app.py # Main Flask application
โโโ annotator.py # Standalone annotation tool
โโโ label.py # LabelImg integration
โโโ test_flow.py # Project testing script
โโโ requirements.txt # Python dependencies
โโโ classes.txt # Class definitions
โโโ README.md # This file
โโโ templates/ # HTML templates
โ โโโ index.html # Main upload page
โ โโโ result.html # Results display
โ โโโ annotator.html # Annotation overview
โ โโโ frame_annotator.html # Single frame annotation
โโโ static/ # Static assets
โ โโโ styles.css # CSS styling
โโโ uploads/ # Uploaded videos (auto-created)
โโโ frames/ # Extracted frames (auto-created)
โโโ __pycache__/ # Python cache (auto-created)๐ API Documentation
Main Application Routes
Video Upload
- POST
/upload - Upload video file for processing
- Parameters:
video(file),every_nth(integer)
Frame Management
- GET
/frames/<job_id>/<filename> - Serve frame images
- GET
/open-folder/<job_id> - Open frames directory in file explorer
Annotation Routes
- GET
/annotator/<job_id> - Main annotation interface
- GET
/annotator/<job_id>/frame/<frame_name> - Single frame annotation view
Annotation API Endpoints
Annotations Management
- GET
/annotator/<job_id>/api/annotations/<frame_name> - Get annotations for a frame
- POST
/annotator/<job_id>/api/annotations/<frame_name> - Add new annotation
- PUT
/annotator/<job_id>/api/annotations/<frame_name>/<annotation_id> - Update annotation
- DELETE
/annotator/<job_id>/api/annotations/<frame_name>/<annotation_id> - Delete annotation
Export Functions
- GET
/annotator/<job_id>/api/export/<frame_name> - Export single frame annotations
- GET
/annotator/<job_id>/api/export_all - Export all annotations
- GET
/annotator/<job_id>/api/download_dataset - Download complete YOLO dataset
Statistics and Navigation
- GET
/annotator/<job_id>/api/stats - Get annotation statistics
- GET
/annotator/<job_id>/api/frames - Get list of all frames
- GET
/annotator/<job_id>/api/frames/<frame_name>/next - Get next frame
- GET
/annotator/<job_id>/api/frames/<frame_name>/prev - Get previous frame
๐ ๏ธ Troubleshooting
Common Issues
Port Already in Use
# Check what's using the port
netstat -ano | findstr :5000 # Windows
lsof -i :5000 # macOS/Linux
# Change port in app.py
app.run(host="0.0.0.0", port=5001, debug=True)Video Processing Errors
- Unsupported Format: Convert video to MP4 using FFmpeg
- Large File Size: Use frame extraction to reduce processing time
- Memory Issues: Increase system RAM or process smaller videos
Annotation Interface Issues
- Browser Compatibility: Use Chrome, Firefox, or Safari
- JavaScript Errors: Clear browser cache and reload
- Slow Performance: Close other browser tabs
Installation Problems
# Update pip
python -m pip install --upgrade pip
# Install with verbose output
pip install -r requirements.txt -v
# Check Python version
python --versionPerformance Optimization
For Large Videos
- Increase Frame Interval: Use every 5th or 10th frame
- Process in Batches: Split long videos into segments
- Use SSD Storage: Faster read/write operations
- Close Other Applications: Free up system resources
For Annotation Speed
- Use Keyboard Shortcuts: Arrow keys for navigation
- Batch Annotations: Annotate similar frames together
- Use High-Quality Monitor: Better visibility for small objects
๐ค Contributing
Development Setup
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Code Style
- Follow PEP 8 guidelines
- Add docstrings to functions
- Include type hints where appropriate
- Write clear commit messages
Testing
# Run the test suite
python test_flow.py
# Test specific components
python -m pytest tests/๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- OpenCV: Computer vision library
- Flask: Web framework
- YOLO: Object detection format
- labelImg: Annotation tool inspiration
๐ Support
For issues and questions:
- Check the troubleshooting section
- Review existing GitHub issues
- Create a new issue with detailed information
- Include system information and error logs
Happy Cricket Analysis! ๐
