# shrimpstanot/football_analysis architecture

> Architecture diagram of the GitHub repository shrimpstanot/football_analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shrimpstanot/football_analysis
- Repository: https://github.com/shrimpstanot/football_analysis

## Overview

This is a video-based football match analysis application. A user-provided match video is loaded, then the main workflow detects and tracks players, referees, and the ball; estimates camera motion and field perspective; computes player speed and distance; assigns teams and ball possession; and renders an annotated output video. The graph separates these domain stages while retaining the shared bounding-box and video I/O layer. Some README capabilities, such as interpolation, are represented where documented or directly visible; implementation details beyond the supplied excerpts are not inferred.

Main entry points: [`main.py`](https://github.com/shrimpstanot/football_analysis/blob/main/main.py) (Analysis coordinator), [`utils/video_utils.py`](https://github.com/shrimpstanot/football_analysis/blob/main/utils/video_utils.py) (Video I/O), [`utils/bbox_utils.py`](https://github.com/shrimpstanot/football_analysis/blob/main/utils/bbox_utils.py) (Bounding-box utilities), [`trackers/tracker.py`](https://github.com/shrimpstanot/football_analysis/blob/main/trackers/tracker.py) (Detection and tracking)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Analysis workflow"]
  node_main["Analysis coordinator<br/>[main.py]"]
  node_video_io["Video I/O<br/>[video_utils.py]"]
  node_bbox_utils["Bounding-box utilities<br/>[bbox_utils.py]"]
end

subgraph group_vision["Tracking and motion"]
  node_detector_tracker["Detection and tracking<br/>[tracker.py]"]
  node_track_positions["Track positions<br/>[tracker.py]"]
  node_camera_motion["Camera motion"]
end

subgraph group_metrics["Field metrics"]
  node_perspective["Perspective mapping"]
  node_speed_distance["Speed and distance"]
end

subgraph group_context["Match context"]
  node_team_assignment["Team assignment<br/>[team_assigner.py]"]
  node_ball_assignment["Ball possession"]
end

subgraph group_render["Video rendering"]
  node_track_overlay["Track annotations<br/>[tracker.py]"]
  node_motion_overlay["Motion overlay"]
  node_metrics_overlay["Metrics overlay"]
end

node_user(("Video analyst"))
node_input_video["Match video"]
node_output_video["Annotated video"]

node_user -->|"provides"| node_input_video
node_input_video -->|"read frames"| node_video_io
node_video_io -->|"returns frames"| node_main
node_main -->|"requests tracks"| node_detector_tracker
node_detector_tracker -->|"adds positions"| node_track_positions
node_main -->|"estimates motion"| node_camera_motion
node_main -->|"maps positions"| node_perspective
node_main -->|"calculates metrics"| node_speed_distance
node_main -->|"assigns teams"| node_team_assignment
node_main -->|"assigns possession"| node_ball_assignment
node_main -->|"draws tracks"| node_track_overlay
node_main -->|"draws motion"| node_motion_overlay
node_main -->|"draws metrics"| node_metrics_overlay
node_main -->|"saves frames"| node_video_io
node_video_io -->|"writes video"| node_output_video
node_user -->|"receives result"| node_output_video
node_detector_tracker -->|"uses geometry"| node_bbox_utils
node_camera_motion -->|"measures movement"| node_bbox_utils
node_speed_distance -->|"measures distance"| node_bbox_utils
node_ball_assignment -->|"measures proximity"| node_bbox_utils

click node_main "https://github.com/shrimpstanot/football_analysis/blob/main/main.py"
click node_video_io "https://github.com/shrimpstanot/football_analysis/blob/main/utils/video_utils.py"
click node_detector_tracker "https://github.com/shrimpstanot/football_analysis/blob/main/trackers/tracker.py"
click node_track_positions "https://github.com/shrimpstanot/football_analysis/blob/main/trackers/tracker.py"
click node_camera_motion "https://github.com/shrimpstanot/football_analysis/blob/main/camera_movement_estimator/camera_movement_estimator.py"
click node_perspective "https://github.com/shrimpstanot/football_analysis/blob/main/view_transformer/view_transformer.py"
click node_speed_distance "https://github.com/shrimpstanot/football_analysis/blob/main/speed_and_distance_estimator/speed_and_distance_estimator.py"
click node_team_assignment "https://github.com/shrimpstanot/football_analysis/blob/main/team_assigner/team_assigner.py"
click node_ball_assignment "https://github.com/shrimpstanot/football_analysis/blob/main/player_ball_assigner/player_ball_assigner.py"
click node_track_overlay "https://github.com/shrimpstanot/football_analysis/blob/main/trackers/tracker.py"
click node_motion_overlay "https://github.com/shrimpstanot/football_analysis/blob/main/camera_movement_estimator/camera_movement_estimator.py"
click node_metrics_overlay "https://github.com/shrimpstanot/football_analysis/blob/main/speed_and_distance_estimator/speed_and_distance_estimator.py"
click node_bbox_utils "https://github.com/shrimpstanot/football_analysis/blob/main/utils/bbox_utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_video_io,node_bbox_utils toneBlue
class node_detector_tracker,node_track_positions,node_camera_motion toneAmber
class node_perspective,node_speed_distance toneMint
class node_team_assignment,node_ball_assignment toneRose
class node_track_overlay,node_motion_overlay,node_metrics_overlay,node_user,node_input_video,node_output_video toneIndigo
```

## Components

### Analysis workflow

- [Analysis coordinator](https://github.com/shrimpstanot/football_analysis/blob/main/main.py): `main.py`
- [Video I/O](https://github.com/shrimpstanot/football_analysis/blob/main/utils/video_utils.py): `utils/video_utils.py`
- [Bounding-box utilities](https://github.com/shrimpstanot/football_analysis/blob/main/utils/bbox_utils.py): `utils/bbox_utils.py`

### Tracking and motion

- [Detection and tracking](https://github.com/shrimpstanot/football_analysis/blob/main/trackers/tracker.py): `trackers/tracker.py`
- [Track positions](https://github.com/shrimpstanot/football_analysis/blob/main/trackers/tracker.py): `trackers/tracker.py`
- [Camera motion](https://github.com/shrimpstanot/football_analysis/blob/main/camera_movement_estimator/camera_movement_estimator.py): `camera_movement_estimator/camera_movement_estimator.py`

### Field metrics

- [Perspective mapping](https://github.com/shrimpstanot/football_analysis/blob/main/view_transformer/view_transformer.py): `view_transformer/view_transformer.py`
- [Speed and distance](https://github.com/shrimpstanot/football_analysis/blob/main/speed_and_distance_estimator/speed_and_distance_estimator.py): `speed_and_distance_estimator/speed_and_distance_estimator.py`

### Match context

- [Team assignment](https://github.com/shrimpstanot/football_analysis/blob/main/team_assigner/team_assigner.py): `team_assigner/team_assigner.py`
- [Ball possession](https://github.com/shrimpstanot/football_analysis/blob/main/player_ball_assigner/player_ball_assigner.py): `player_ball_assigner/player_ball_assigner.py`

### Video rendering

- [Track annotations](https://github.com/shrimpstanot/football_analysis/blob/main/trackers/tracker.py): `trackers/tracker.py`
- [Motion overlay](https://github.com/shrimpstanot/football_analysis/blob/main/camera_movement_estimator/camera_movement_estimator.py): `camera_movement_estimator/camera_movement_estimator.py`
- [Metrics overlay](https://github.com/shrimpstanot/football_analysis/blob/main/speed_and_distance_estimator/speed_and_distance_estimator.py): `speed_and_distance_estimator/speed_and_distance_estimator.py`

### Other components

- **Video analyst**
- **Match video**
- **Annotated video**

## Connections

- Video analyst → Match video: provides (evidence: `README.md`)
- Match video → Video I/O: read frames (evidence: `utils/video_utils.py`)
- Video I/O → Analysis coordinator: returns frames (evidence: `main.py`)
- Analysis coordinator → Detection and tracking: requests tracks (evidence: `main.py`)
- Detection and tracking → Track positions: adds positions (evidence: `trackers/tracker.py`)
- Analysis coordinator → Camera motion: estimates motion (evidence: `main.py`)
- Analysis coordinator → Perspective mapping: maps positions (evidence: `main.py`)
- Analysis coordinator → Speed and distance: calculates metrics (evidence: `main.py`)
- Analysis coordinator → Team assignment: assigns teams (evidence: `main.py`)
- Analysis coordinator → Ball possession: assigns possession (evidence: `main.py`)
- Analysis coordinator → Track annotations: draws tracks (evidence: `main.py`)
- Analysis coordinator → Motion overlay: draws motion (evidence: `main.py`)
- Analysis coordinator → Metrics overlay: draws metrics (evidence: `main.py`)
- Analysis coordinator → Video I/O: saves frames (evidence: `main.py`)
- Video I/O → Annotated video: writes video (evidence: `utils/video_utils.py`)
- Video analyst → Annotated video: receives result (evidence: `README.md`)
- Detection and tracking → Bounding-box utilities: uses geometry (evidence: `trackers/tracker.py`)
- Camera motion → Bounding-box utilities: measures movement (evidence: `camera_movement_estimator/camera_movement_estimator.py`)
- Speed and distance → Bounding-box utilities: measures distance (evidence: `speed_and_distance_estimator/speed_and_distance_estimator.py`)
- Ball possession → Bounding-box utilities: measures proximity (evidence: `player_ball_assigner/player_ball_assigner.py`)
