Object detection, heat maps and real-time monitoring for robotic soccer.
The system is capable of processing videos from the FutBotMX Cup to track objects on the field, and translate that visual information into a 2D plane, calculating heatmaps and notifying collisions in real time.
The solution was structured modularly in five critical stages, executed sequentially frame by frame:
-
Calibration: At the beginning, the system captures the first frame and allows the user to mark the corners of the field to calculate the homography projection matrix (
$H$ ). - Identification: A YOLOv8n model, trained on 2,840 images across three classes ('ball', 'goal', and 'robot'), detects the bounding boxes of the elements.
- Segmentation: The Segment Anything (SAM3) model takes the bounding boxes from YOLO to segment the exact polygons, extracting the outline of the objects.
- Consistency: A tracking algorithm assigns and maintains unique, fixed IDs for each entity.
-
Homographic Projection:
-
Homography (
$H$ ): A projective mathematical transformation is applied to the bottom point of each object to calculate its real position on the field ($2D$ ) in centimeters. - HSV Analysis: The segmented areas of each robot are analyzed to classify them into teams according to their predominant color.
-
Heatmaps: Positions are accumulated on a canvas to generate a heatmap (
cv2.COLORMAP_JET). -
Collision Detection: Euclidean distances are measured to alert about crashes (
$distance < 35 \text{ cm}$ ).
-
Homography (
This project was developed in Python 3.11.15. The main libraries can be installed via pip.
opencv-pythonultralyticssupervisionnumpypathlibultralytics
(See requirements.txt file for exact versions).
Since the pipeline uses two heavy Deep Learning models (YOLOv8 + SAM) running frame by frame, the use of a GPU is strongly recommended for smooth playback.
- Processor (CPU): Intel Core i7 / AMD Ryzen 7 or higher.
- GPU (Recommended): NVIDIA GeForce RTX 3060 / RTX 4070 or higher, with at least 8GB of VRAM.
- RAM: 16GB or more.
-
Clone the repository:
git clone [https://github.com/M0ndares/futbot.git](https://github.com/M0ndares/futbot.git) cd futbot -
Create and activate the environment:
conda create -n futbot python=3.11.15 conda activate futbot
-
Install dependencies:
pip install -r requirements.txt
-
Download model weights: Make sure to place the
.ptfiles in the correct folders according to your script (/runs/segment/train/weights/best.ptand../notebooks/sam3.pt). -
Run the pipeline: If it is the first time you are running it with a new video, delete the
matriz_homografia.npyfile to force calibration.python src/app.py
The system perfectly integrates all 5 phases, displaying the tactical mini-field in real time, classifying teams by color, and illuminating the cumulative heatmap while visually alerting about robot collisions. The diploma provided by SECIHTI is available in the following Link
This project is licensed under the MIT License. You can view the full text in the attached LICENSE file in this repository.
This project uses the following open-source libraries and tools as key dependencies:
- Ultralytics: For execution and detection using the YOLOv8 model and the SAM segmentation backend.
- Roboflow Supervision: Used for the
ByteTracktracking algorithm, as well as for visualization logic using advanced annotators (MaskAnnotator,TraceAnnotator,LabelAnnotator). - OpenCV: Used for matrix image manipulation, color space conversion (HSV), homography calculation, and real-time map drawing.
