A Raspberry Pi-based soccer ball tracking system that uses computer vision and machine learning to detect and classify shots on a goal. The system uses YOLO for ball detection, GPIO sensors for trigger events, and computer vision for goal grid calibration.
- Real-time Ball Detection: Uses YOLO (You Only Look Once) model for accurate ball detection
- Goal Grid Calibration: Automatically detects goal corners using red markers and creates a 3x3 grid
- Shot Classification: Classifies shots as "Corner/Side Shot", "Saved Shot", or "Outside Grid"
- Statistics Generation: Generates visual plots and statistics of shot patterns
- Raspberry Pi Integration: Uses GPIO pins for sensor triggers and LCD display for status updates
- Raspberry Pi (tested on Raspberry Pi 4)
- Camera module or USB webcam
- I2C LCD display (PCF8574, address 0x27)
- Vibration sensors connected to GPIO pins 17 and 27
- Buttons connected to GPIO pins 21 and 22
- Red corner markers on the goal (for grid calibration)
- Python 3.8+
- Raspberry Pi OS (or compatible Linux distribution)
- All dependencies listed in
requirements.txt
- Clone the repository:
git clone https://github.com/genecodAlan/Ftbl_Tracker.git
cd Ftbl_Tracker- Install dependencies:
pip install -r requirements.txt-
Place your trained YOLO model (
best.pt) in themodels/directory -
Ensure your camera is properly connected and accessible
Ftbl_Tracker/
├── src/
│ ├── ball_tracker.py # Main application
│ ├── grid_utils.py # Goal grid utilities
│ └── sensor_test.py # Sensor testing script
├── models/
│ ├── best.pt # YOLO model (add your trained model here)
│ └── yolo11n.pt # Base YOLO model (optional)
├── images/
│ └── Goalpic.jpg # Reference goal image
├── archive/ # Backup and test files
├── requirements.txt # Python dependencies
├── LICENSE # License file
└── README.md # This file
Run the main ball tracker:
cd src
python ball_tracker.pyTest your vibration sensors:
cd src
python sensor_test.py- Initialization: The system initializes the LCD display, camera, and GPIO sensors
- Grid Setup: Press and hold button 1 (GPIO 22) for 1.3 seconds to start. The system captures a frame after 2 seconds and detects red corner markers
- Ball Detection: When a vibration sensor (GPIO 17 or 27) is triggered, the system captures frames and uses YOLO to detect the ball
- Coordinate Mapping: Detected ball positions are mapped to the 3x3 grid
- Classification: Each shot is classified based on its position in the grid
- Results: Press button 1 again to generate and save the final results plot
Edit src/ball_tracker.py to change GPIO pin assignments:
channel = 17 # Vibration sensor 1
channel2 = 27 # Vibration sensor 2
button = 22 # Control button 1
button2 = 21 # Control button 2Update the model path in src/ball_tracker.py:
model = YOLO("../models/best.pt")Change the output directory for processed frames:
output_folder = "/path/to/your/output/folder"- Button 1 (GPIO 22):
- Hold for 1.3+ seconds: Start session / Capture grid frame
- Press during session: Save results and exit
- Button 2 (GPIO 21): End session
The system generates:
- Processed frames saved in
output_folder/Run_X/ - Final result plot:
Result_Plot.png - Statistics table showing shot type distribution
- Ensure camera is connected and accessible
- Check camera permissions
- Verify camera index (default is 0)
- Verify I2C connection
- Check LCD address (default: 0x27)
- Ensure I2C is enabled on Raspberry Pi
- Ensure
best.ptis in themodels/directory - Check file permissions
- Ensure red markers are clearly visible
- Adjust lighting conditions
- Check HSV color range in
grid_utils.py
Contributions are welcome! Please feel free to submit a Pull Request.
See LICENSE file for details.
https://github.com/genecodAlan/Ftbl_Tracker.git
genecodAlan