Skip to content

Repository files navigation

Tennis Play Analyzer with YOLOv8

Project Overview

The Tennis Match Analyzer is a computer vision project that tracks and analyzes tennis matches from video input. It uses advanced object detection and tracking techniques to identify players, the tennis ball, and court boundaries, mapping these elements onto a 2D court representation.

Untitled.mov

Features

  • Player detection and tracking
  • Tennis ball tracking
  • Court boundary detection
  • Real-time mapping of players and ball positions to a 2D court view
  • Video processing with side-by-side display of detection results and 2D mapping

Technologies Used

  • Python
  • OpenCV
  • YOLOv8 (for object detection)
  • NumPy
  • Scikit-learn (for K-means clustering)

Installation

  1. Clone the repository:

git clone https://github.com/your-username/tennis-match-analyzer.git

  1. Install the required dependencies:

pip install -r requirements.txt

Usage

  1. Ensure you have the trained models in the trained_models directory:
  • Tennis ball model: trained_models/tennis_ball_model/best.pt
  • Human detection model: trained_models/yolo_model/yolov8x.pt
  • Court detection model: trained_models/court_model/last.pt
  1. Place your input video in the inputs/videos/ directory.

  2. Run the main script:

python main.py

  1. The processed video will be saved as runs/detect/processed_tennis_match.mp4.

Project Structure

  • main.py: The main script that orchestrates the entire process
  • yolo_interference.py: Contains classes for tennis ball, human, and court tracking
  • mapping.py: Handles the mapping from camera view to 2D court view
  • classification.py: Classifies detected people as players or spectators
  • drawings.py: Handles all the drawing functions for visualization

Dependencies

  • numpy==1.21.0
  • opencv-python==4.5.3.56
  • ultralytics==8.0.0

Used Datasets

Contributing

Contributions to improve the Tennis Match Analyzer are welcome. Please feel free to submit a Pull Request.

License

MIT License

Acknowledgements

  • YOLOv8 by Ultralytics
  • OpenCV community

Future Improvements

  • Implement player identification
  • Add match statistics tracking
  • Improve accuracy of ball tracking in high-speed scenarios

Contact

For any queries or suggestions, please open an issue in this repository.

About

Tennis Match Analyzer: A computer vision project that tracks players, balls, and court boundaries in tennis match videos. Uses YOLOv8 for object detection, maps elements to a 2D court view, and provides real-time analysis. Ideal for coaches, players, and tennis enthusiasts.

Resources

Stars

40 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages