This repository contains the implementation of a data science project focused on real-time match analysis and metrics creation for football (soccer) matches. The project utilizes computer vision techniques to detect and track players, analyze their movements, and generate various metrics such as speed, distance covered, and possession time. The architecture is designed as a microservice-based system, allowing for modular development and deployment.
Ole Schildt |
Philipp Meyer |
Florian WΓΆlfel |
Laelia Chi |
Lukas Ihrig |
Yaren Erol |
- π€ Training of a custom object detection model for player detection
- πΉ Real-Time Video Streaming β Capture and stream live football matches
- π₯ Live Match Analysis β Real-time insights opf small-sided football games
- π§ AI-Based Player Detection β Object detection and tracking using computer vision
- ποΈβπ¨οΈ 2D Birdβs Eye View β Visual representation of player positions and movements
- π Player Metrics β Speed, distance covered, possession time, and more
- π Data Visualizations β Heatmaps, possession, distance covered, passes
- π₯οΈ Interactive Frontend β User interface for viewing metrics and controlling the analysis
The whole sturcture is based on a micro service architecture. Each component is a separate micro service which can be run independently. The whole architecture is based on Docker and Docker Compose to easily run and manage the services. For more information look into the docs folder.
Here is a brief overview of the final structure:
.
βββ .github/
β βββ ... for workflows and pipelines
βββ .vscode/
β βββ ... to unify our settings (vim is better)
βββ docs/
β βββ docs.md
βββ demo_stream/
β βββ ... demo stream to test the final architecture
βββ bff_api/
β βββ ... own micro service which exposes the metrics
β βββ ... here also as example a structure for a ms
β βββ src/
β β βββ logic.py
β βββ test/
β β βββ test.py
β βββ config.yaml
β βββ Dockerfile
β βββ main.py
β βββ pyproject.toml
βββ frontend/
β βββ ... based on the bff_api data
βββ inference/
β βββ ... mirco service live inference
βββ metrics/
β βββ ... scheduled etl job as micro service
βββ model_training/
β βββ ... here we independently train our model
βββ db_data/
β βββ ... dir to persist the postgres data (in .gitignore)
βββ docker-compose.yaml
βββ .env
βββ LICENSE
βββ README.md
βββ ruff.toml
Here are the vars you need to define:
NGINX_HOST=nginx
RTMP_PORT=1935
HTTP_PORT=5555
DATABASE_HOST=db
DATABASE_PORT=5432
DATABASE_NAME=mydatabase
DATABASE_USER=myuser
DATABASE_PSWD=mypwd
USER=test
PSWD=test
RTMP_URL=rtmp://nginx/hls
STREAM_NAME=demo
VIDEO_FILE_PATH=/app/demo.mp4
STREAM_URL=http://nginx:5555/hls/demo.m3u8
ROBOFLOW_API_KEY=your-roboflow-api-key
GOOGLE_CLIENT_ID=xxx
GOOGLE_CLIENT_SECRET=yyy
USER_MAIL=mail_which_you_want_to_use_for_sso( no db or hashmap to keep it simple )You also need to add your .mp4 file whoch you want to stream to folloing path:
demo_stream/trigger_api/demo.mp4
To enable Google Sign-In for the admin panel, follow these steps:
π https://console.cloud.google.com/
- Click the project dropdown at the top and select "New Project"
- Give your project a name (e.g.
Football Analytics SSO) - Click Create
- Navigate to APIs & Services > Library
- Search for "Google Identity Services"
- Click Enable
- Go to APIs & Services > OAuth consent screen
- Select External user type
- Fill in:
- App name
- Support email
- Developer contact info
- Scopes: Add the default scopes
openid,email,profile
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Choose Web application
- Under Authorized redirect URIs, add: http://localhost:8501
- After creation, copy your Client ID and Client Secret
- Add them to your
.envfile:
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
### Docker Compose - Final Architecture
Everything is based on the `docker-compose.yaml`. To run and build it use following:
```bash
docker-compose up --build -d
# to close
docker-compose downTo access the services look into the compose file to find the corresponding ports.
The micro services are all independent in their folder and cen be executed there.
cd micro_service
uv run main.pyTo finally test and run only one single artifact
cd micro_service
docke build -t my_container .
docker run -p 8000:8000 my_containerAfter starting the docker compose, you can start the stream witht the API under localhost:8000
The stream is available under http://localhost:5555. It simulates a real time stream which can then be procssed by our micro services.
The trigger API is available under http://localhost:8000. It allows you to start the stream processing by sending a POST request. The stream will be processed and the metrics will be generated.
The BFF API is available under http://localhost:8001. It provides endpoints to access the metrics and data processed from the stream.
The frontend is available under http://localhost:8501. It provides a user interface to visualize the metrics and data processed from the stream.
HELPWe use uv to manage testing, linting, and formatting.
# Run tests
uv run pytest
# Lint code
uvx ruff check .
# Format code
uvx ruff format .This project is licensed under the MIT License. See the LICENSE file for details.




