CoolFace
Apppublic

ddlsandeep/cricket-video-annotation

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

๐Ÿ 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

๐ŸŽฅ 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

bash
git clone <repository-url>
cd Cricket

2. Create Virtual Environment (Recommended)

bash
# Windows
python -m venv venv
venv\Scripts\activate

# macOS/Linux
python3 -m venv venv
source venv/bin/activate

3. Install Dependencies

bash
pip install -r requirements.txt

4. Verify Installation

bash
python test_flow.py

โšก Quick Start

1. Start the Application

bash
python app.py

2. Access the Web Interface

Open your browser and navigate to: http://localhost:5000

3. Upload a Video

  1. 1.Click "Select video" to choose your cricket video file
  2. 2.Set frame extraction interval (default: every frame)
  3. 3.Click "Convert to frames"

4. Annotate Frames

  1. 1.Click "๐Ÿ–Š๏ธ Web Annotator" button
  2. 2.Select a frame to annotate
  3. 3.Draw bounding boxes for cricket objects
  4. 4.Navigate between frames using arrow keys

5. Export Dataset

  1. 1.Use export buttons to download YOLO-compatible dataset
  2. 2.Choose train/validation split ratio
  3. 3.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}.jpg

Example: cricket_match_frame_000123_1234567890.jpg

Annotation Interface

Getting Started
  1. 1.Access Annotator: Click "๐Ÿ–Š๏ธ Web Annotator" from results page
  2. 2.Select Frame: Click on any frame thumbnail to open annotation view
  3. 3.Draw Boxes: Click and drag to create bounding boxes
  4. 4.Class Selection: Choose object class (Ball, Bat, Player)
  5. 5.Save: Annotations are automatically saved
Keyboard Shortcuts
  • โ€”โ† โ†’ Arrow Keys: Navigate between frames
  • โ€”Delete: Remove selected annotation box
  • โ€”Escape: Cancel current drawing operation
Annotation Classes
Class IDClass NameDescription
0Cricket BallThe cricket ball in play
1BatCricket bat
2PlayerCricket player/person

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 documentation
Export Options
  1. 1.Complete Dataset: Full YOLO-compatible ZIP file
  2. 2.Legacy Format: Single directory with all images
  3. 3.Individual Frames: Export annotations per frame
  4. 4.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
bash
# 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
bash
# Update pip
python -m pip install --upgrade pip

# Install with verbose output
pip install -r requirements.txt -v

# Check Python version
python --version

Performance Optimization

For Large Videos
  1. 1.Increase Frame Interval: Use every 5th or 10th frame
  2. 2.Process in Batches: Split long videos into segments
  3. 3.Use SSD Storage: Faster read/write operations
  4. 4.Close Other Applications: Free up system resources
For Annotation Speed
  1. 1.Use Keyboard Shortcuts: Arrow keys for navigation
  2. 2.Batch Annotations: Annotate similar frames together
  3. 3.Use High-Quality Monitor: Better visibility for small objects

๐Ÿค Contributing

Development Setup

  1. 1.Fork the repository
  2. 2.Create a feature branch
  3. 3.Make your changes
  4. 4.Add tests if applicable
  5. 5.Submit a pull request

Code Style

  • โ€”Follow PEP 8 guidelines
  • โ€”Add docstrings to functions
  • โ€”Include type hints where appropriate
  • โ€”Write clear commit messages

Testing

bash
# 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:

  1. 1.Check the troubleshooting section
  2. 2.Review existing GitHub issues
  3. 3.Create a new issue with detailed information
  4. 4.Include system information and error logs

Happy Cricket Analysis! ๐Ÿ