This project focuses on analyzing football (soccer) games through video footage. Using object detection models, the project tracks players and the ball, providing a variety of insights such as player positions, ball movement, and even generating bird's-eye view images of the field. The core of the project is based on YOLO (You Only Look Once) for object detection and other techniques like perspective transformation and player tracking.
- Player Detection & Tracking: Identifies and tracks players throughout the match using deep learning models (YOLOv5 and DeepSORT).
- Ball Detection: Detects the position of the ball on the field in real-time.
- Bird's Eye View: Generates an overhead view of the football field based on detected player positions.
- Frame Extraction & Video Processing: Extracts frames from football match videos for further analysis and creates new video outputs with player markings.
- Customization: Flexible settings for detecting and processing football videos.
To use this project, ensure you have the following installed:
-
Python 3.x or higher
-
Libraries:
opencv-python-headlessmatplotlibtorchultralyticstqdmcolor-thiefnumpytensorflow(optional, if using for model loading)
To install dependencies, use the requirements.txt file:
pip install -r requirements.txt-
Clone the repository:
git clone https://github.com/your-username/comprehensive-football-analysis.git cd comprehensive-football-analysis -
Install dependencies:
pip install -r requirements.txt
-
Download YOLOv5 (if not included by default):
git clone https://github.com/ultralytics/yolov5 cd yolov5 pip install -r requirements.txt -
Download the dataset or input video:
- Ensure you have a video file (
football.mp4) placed in the directory for analysis.
- Ensure you have a video file (
-
Video Processing and Player Marking: To process a video and track players, use the
player_markingfunction. For example:player_marking("input_video.mp4", "output_video.mp4")
-
Run Image Extraction: The
run_image_extractionfunction allows you to extract frames from the video, focusing on specific scenes, such as when the green color dominates (indicating the field). For example:run_image_extraction("input_video.mp4", "output_video.mp4")
-
Bird’s Eye View Generation: The project can generate a bird’s-eye view of the football field. This requires configuring the homography matrix and applying perspective transformations based on player and ball detections.
-
Annotations & Output: Annotated frames can be saved in the output folder. You can visualize player locations, ball tracking, and more in the generated video:
annotated_video = player_marking("input_video.mp4", "annotated_output.mp4")
-
BirdsEyeView_:- Handles perspective transformation and detection.
- Generates the bird's-eye view of the football field based on tracked player positions.
-
imageextract.py:- Extracts frames from the input video based on a given frame rate.
- Saves selected frames based on specific conditions (e.g., dominant green color).
-
player_marking.py:- Handles player detection, marking, and tracking.
- Saves annotated frames or videos showing player positions, ball detection, and other game metrics.
-
main.py:- The main script that coordinates video input, processing, and saving outputs.
- Initializes models for player and ball detection, and performs perspective transformations.
generate_frames: Extracts frames from a video.plot_image: Visualizes images usingmatplotlib.filter_detections_by_class: Filters detections based on class names (e.g., players or ball).draw_rect,draw_ellipse,draw_polygon: Annotates frames with shapes to represent objects.
- Detection: Represents the detection data of an object, including its bounding box, class ID, and confidence score.
- BaseAnnotator: A class responsible for annotating images with various shapes and texts based on detection data.
├── BirdsEyeView_/
│ ├── deep_sort_pytorch/
│ ├── elements/
│ ├── inference/
│ ├── perspective_transform/
│ ├── yolov5/
│ ├── .gitignore
│ ├── README.md
│ ├── arguments.py
│ ├── main.py
│ └── requirements.txt
├── imageextract.py
├── player_marking.py
├── requirements.txt
├── README.md
└── main.py
- Annotated Video: The video output with annotations such as player positions, ball location, and other analysis.
- Bird's Eye View Image: An overhead view of the football field highlighting player and ball positions.
- Ensure all dependencies are installed correctly.
- If the
yolov5repository is missing, clone it manually into the project directory. - Adjust the
conf_thresh(confidence threshold) andiou_thresh(Intersection Over Union threshold) for YOLOv5 if detections are not accurate.