Skip to content

Repository files navigation

Soccer Ball Tracker

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.

Features

  • 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

image of example output

Hardware Requirements

  • 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)

Software Requirements

  • Python 3.8+
  • Raspberry Pi OS (or compatible Linux distribution)
  • All dependencies listed in requirements.txt

Installation

  1. Clone the repository:
git clone https://github.com/genecodAlan/Ftbl_Tracker.git
cd Ftbl_Tracker
  1. Install dependencies:
pip install -r requirements.txt
  1. Place your trained YOLO model (best.pt) in the models/ directory

  2. Ensure your camera is properly connected and accessible

Project Structure

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

Usage

Main Application

Run the main ball tracker:

cd src
python ball_tracker.py

Sensor Test

Test your vibration sensors:

cd src
python sensor_test.py

How It Works

  1. Initialization: The system initializes the LCD display, camera, and GPIO sensors
  2. 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
  3. Ball Detection: When a vibration sensor (GPIO 17 or 27) is triggered, the system captures frames and uses YOLO to detect the ball
  4. Coordinate Mapping: Detected ball positions are mapped to the 3x3 grid
  5. Classification: Each shot is classified based on its position in the grid
  6. Results: Press button 1 again to generate and save the final results plot

Configuration

GPIO Pin Configuration

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 2

Model Path

Update the model path in src/ball_tracker.py:

model = YOLO("../models/best.pt")

Output Directory

Change the output directory for processed frames:

output_folder = "/path/to/your/output/folder"

Button Controls

  • 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

Output

The system generates:

  • Processed frames saved in output_folder/Run_X/
  • Final result plot: Result_Plot.png
  • Statistics table showing shot type distribution

Troubleshooting

Camera Issues

  • Ensure camera is connected and accessible
  • Check camera permissions
  • Verify camera index (default is 0)

LCD Display Issues

  • Verify I2C connection
  • Check LCD address (default: 0x27)
  • Ensure I2C is enabled on Raspberry Pi

Model Not Found

  • Ensure best.pt is in the models/ directory
  • Check file permissions

Corner Detection Issues

  • Ensure red markers are clearly visible
  • Adjust lighting conditions
  • Check HSV color range in grid_utils.py

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

See LICENSE file for details.

Repository

https://github.com/genecodAlan/Ftbl_Tracker.git

Author

genecodAlan

About

Python and RPI 5 localized wireless soccer ball and goal tracker. Training data and score report.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages