CoolFace
Apppublic

samson82-aiml/cricket-batting-coach

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

๐Ÿ Cricket Batting Coach

A real-time cricket batting coach that uses computer vision to detect and analyze batting swings. Built with Streamlit and optimized for Hugging Face Spaces.

๐Ÿš€ Live Demo

![Hugging Face Spaces](https://huggingface.co/spaces/samjosdev/cricket-batting-coach)

๐ŸŽฏ Features

  • โ€”Real-time Pose Detection: Uses MediaPipe for accurate pose tracking
  • โ€”Swing Analysis: Detects forward batting swings with speed and direction analysis
  • โ€”Live Video Processing: WebRTC-based video streaming for low-latency performance
  • โ€”Swing Counter: Tracks and displays swing count in real-time
  • โ€”Visual Feedback: Real-time overlay with swing detection indicators

๐Ÿ› ๏ธ Technology Stack

  • โ€”Frontend: Streamlit
  • โ€”Video Processing: OpenCV, MediaPipe
  • โ€”Real-time Communication: WebRTC
  • โ€”Deployment: Hugging Face Spaces

๐Ÿ“‹ Requirements

  • โ€”Python 3.11 (for MediaPipe compatibility)
  • โ€”Webcam access
  • โ€”Modern web browser with WebRTC support

๐Ÿš€ Quick Start

Local Development

  1. 1.Clone the repository
bash
   git clone https://github.com/samjosdev/cricket-batting-coach.git
   cd cricket-batting-coach
  1. 1.Install dependencies
bash
   pip install -r requirements.txt
  1. 1.Run the application
bash
   streamlit run app.py
  1. 1.Open your browser Navigate to http://localhost:8501

Hugging Face Spaces Deployment

  1. 1.Fork this repository
  2. 2.Create a new Space on Hugging Face
  3. 3.Go to Hugging Face Spaces
  4. 4.Click "Create new Space"
  5. 5.Choose "Streamlit" as the SDK
  6. 6.Set the repository to your forked repo
  1. 1.Configure the Space
  2. 2.The Space will automatically detect the app.py file
  3. 3.Dependencies will be installed from requirements.txt
  4. 4.Python version will be set to 3.11

๐ŸŽฎ How to Use

  1. 1.Start the Application
  2. 2.Click "Start" to begin video processing
  3. 3.Allow camera access when prompted
  1. 1.Position Yourself
  2. 2.Stand in front of the camera
  3. 3.Ensure your full body is visible
  4. 4.Hold a cricket bat or simulate batting motion
  1. 1.Practice Your Swings
  2. 2.Make forward batting swings
  3. 3.The app will detect and count your swings
  4. 4.Watch for the "SWING DETECTED!" indicator
  1. 1.Monitor Your Progress
  2. 2.Track your swing count in real-time
  3. 3.Analyze swing speed and direction
  4. 4.Reset counters as needed

๐Ÿ”ง Configuration

Python Version

The app is configured to use Python 3.11 for optimal MediaPipe compatibility:

  • โ€”.python-version: Specifies Python 3.11
  • โ€”runtime.txt: Alternative Python version specification

Dependencies

Key dependencies are specified in requirements.txt:

txt
streamlit==1.28.1
streamlit-webrtc==0.47.1
opencv-python-headless==4.8.1.78
mediapipe==0.10.7
numpy==1.24.3
av==10.0.0

System Dependencies

Required system packages are specified in packages.txt:

txt
libgl1-mesa-glx
libglib2.0-0
libsm6
libxext6
libxrender-dev
libgomp1

๐ŸŽฏ Swing Detection Algorithm

The app uses a sophisticated algorithm to detect cricket batting swings:

  1. 1.Pose Tracking: MediaPipe tracks 33 body landmarks
  2. 2.Wrist Movement: Monitors wrist position changes over time
  3. 3.Speed Calculation: Computes movement speed between frames
  4. 4.Direction Analysis: Determines swing direction (forward/backward)
  5. 5.Threshold Filtering: Applies minimum speed and direction thresholds
  6. 6.Cooldown System: Prevents double-counting of swings

Detection Parameters

  • โ€”Speed Threshold: 0.045 (minimum movement speed)
  • โ€”Direction Threshold: 0.005 (minimum forward motion)
  • โ€”History Length: 15 frames for analysis
  • โ€”Cooldown: 80 frames between detections

๐Ÿ› Troubleshooting

Common Issues

  1. 1.Camera Not Working
  2. 2.Ensure camera permissions are granted
  3. 3.Try refreshing the page
  4. 4.Check browser WebRTC support
  1. 1.Swing Detection Issues
  2. 2.Ensure good lighting
  3. 3.Position yourself clearly in frame
  4. 4.Make deliberate forward swings
  1. 1.Performance Issues
  2. 2.Close other browser tabs
  3. 3.Use a modern browser (Chrome, Firefox, Safari)
  4. 4.Ensure stable internet connection

Hugging Face Spaces Issues

  1. 1.Build Failures
  2. 2.Check Python version compatibility
  3. 3.Verify all dependencies are available
  4. 4.Review build logs for specific errors
  1. 1.Runtime Errors
  2. 2.Ensure MediaPipe version compatibility
  3. 3.Check system dependency installation
  4. 4.Verify WebRTC configuration

๐Ÿค Contributing

  1. 1.Fork the repository
  2. 2.Create a feature branch (git checkout -b feature/amazing-feature)
  3. 3.Commit your changes (git commit -m 'Add amazing feature')
  4. 4.Push to the branch (git push origin feature/amazing-feature)
  5. 5.Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support

If you encounter any issues or have questions:

  1. 1.Check the Issues page
  2. 2.Create a new issue with detailed information
  3. 3.Include your browser, OS, and error messages

Happy Batting! ๐Ÿ