This project utilizes YOLOv5, a state-of-the-art object detection model, to track players in a football game and generate a heatmap to visualize the movements of a specific player. The application is implemented using Python and Tkinter for an interactive GUI, and OpenCV for video processing and visualization.
- Automatically detects and tracks players in a football video using YOLOv5.
- Assigns a unique ID to each player based on spatial proximity.
- Generates a heatmap for a selected player based on their positions during the game.
- Superimposes the heatmap on a football field image for better visualization.
- Dynamically updates the heatmap as the video progresses.
- User-friendly Tkinter-based interface.
- Allows the user to input the ID of a player to visualize their movements.
Ensure the following dependencies are installed before running the application:
- Python: Version 3.7 or later
opencv-pythontorchPillowmatplotlibnumpy
To install the dependencies, run:
pip install opencv-python torch Pillow matplotlib numpyThe application uses the yolov5s model from the Ultralytics YOLOv5 repository.
git clone https://github.com/engyelsarta/Yolov5_Player_tracking.git
cd Yolov5_Player_tracking- Place your video file in the project directory or provide its path in the
video_pathvariable in the code.
- Use an empty football field image as the background for the heatmap.
- Update the
field_image_pathvariable in the code with the path to this image.
- Open a terminal and navigate to the project directory.
- Run the script:
Yolo.py- Video Display: The application displays the video frames with detected players and their IDs.
- Player Selection: Input the ID of the player you want to track.
- Heatmap Generation: Press the "Show Heatmap" button to generate a heatmap for the selected player.
- The YOLOv5 model detects players in each frame of the video.
- Bounding boxes and unique IDs are displayed on the video.
- Enter a player's ID in the input box and press the "Show Heatmap" button.
- A heatmap window displays the movement pattern of the selected player.
- The heatmap is dynamically updated as the video progresses.
- Tracks players by comparing their positions frame by frame.
- Assigns new IDs for newly detected players.
- Adjust the
threshold_distancevariable to change the minimum distance for considering a player the same across frames. This improves accuracy for different videos.
- Modify the
cv2.GaussianBlurkernel size and circle size in theupdate_heatmapfunction to adjust heatmap smoothness and intensity.
- Resize the video frame in the
update_framefunction for faster processing.
- Tracking accuracy might vary in videos with overlapping players or poor video quality.
- Heatmap visualization may not align perfectly with the field image if the field perspective in the video differs significantly.
This project is licensed under the MIT License. See the LICENSE file for more details.
- Ultralytics YOLOv5: For the powerful object detection framework.
- OpenCV: For image and video processing.
- Python's Tkinter library: For creating an interactive GUI.
