How abdelrahmanatef01/tactic_zone works
1. Overall shape
- This repository is a football match analysis pipeline with three output layers: computer-vision event extraction, recommendation generation, and LLM-based narration/chat.
- The architecture is centered on processing match video into structured match data, then feeding that data into downstream analytics and Gemini-powered text generation.
2. Primary entry points
- main.py appears to be the local orchestration entry point for the full pipeline.
- end_points.py is the API surface for running the project through endpoints.
- chat_bot/app.py is a separate Flask app focused on the coach chatbot experience.
- The repo therefore has two interaction modes: batch/offline processing and API/chat serving.
3. Computer vision backbone
- The trackers/ package is the core frame-by-frame object tracking layer for players, referees, ball, and goalkeepers.
- camera_movement_estimator/ compensates for broadcast camera motion so player positions can be interpreted consistently across frames.
- view_transformer/ converts image coordinates into a field-aware perspective, which is important for position, distance, and formation reasoning.
4. Detection and event extraction modules
- Specialized detectors live as separate packages: pass_detector/, shot_detector/, substitution_detector/, formation_detector/, team_process/, goal_and_line_processor/, and event_process/.
- These modules likely consume tracked objects and frame metadata to produce event-level outputs such as passes, shots, substitutions, formations, and match state.
- new_data_handler/ looks like the event-model input adapter for less common classes like dribbles, tackles, injuries, and substitution-board signals.
5. Team identity and player association
- team_assigner/ classifies players into teams using jersey-color segmentation and clustering.
- player_ball_assigner/ links the ball to the nearest/most likely player and team on a per-frame basis.
- player_number_detector/ uses OCR/object detection to identify jersey numbers, which is crucial for merging tracks and mapping events to specific players.
6. Player-level analytics
- speed_and_distance_estimator/ computes movement metrics from tracked positions and perspective-transformed coordinates.
- player_stats/ aggregates per-player outputs across the pipeline and merges tracks that share the same shirt number.
- This package acts as a boundary between raw CV outputs and higher-level team analytics.
7. Team-level analytics
- team_stats/ combines player stats, team identity, and formation-related features into a team summary dataset.
- team_process/ determines match result state such as win, loss, or draw.
- These modules produce the structured team-facing data that the recommendation layer consumes.
8. Recommendation subsystem
- recommendation_systems/ is a separate analytical engine that uses processed team data plus historical football datasets.
- The README indicates it recommends formation, play style, starting XI, and bench players.
- This subsystem is decoupled from the video pipeline and depends on cleaned tabular inputs in recommendation_systems_input_files/.
9. LLM and prompt generation layer
- generate_prompt/ prepares the prompt content sent to Gemini for summary-style outputs.
- utils/Gemini_utils.py and chat_bot/ contain the LLM integration and interactive coach assistant.
- The LLM layer sits on top of the structured analytics and translates them into human-readable opponent weakness analysis, training plans, and summaries.
10. Shared utilities
- utils/ contains supporting code for bounding-box handling, recommendation helpers, main workflow utilities, and Gemini helpers.
- These utilities are cross-cutting and likely reduce duplication between detection, analytics, and LLM preparation layers.
11. Data and model assets
- The project ships with input folders such as input_videos/ and CSV datasets under recommendation_systems_input_files/.
- download_models.sh and the README’s model links indicate external trained YOLO weights are required for deployment.
- fire_base/fire_base.json suggests a Firebase credential or integration artifact, but the repo’s main architecture is not Firebase-centric.
12. Output boundaries
- Outputs are organized into separate directories for computer vision and recommendation artifacts, which keeps raw analytics distinct from decision-making outputs.
- The likely flow is: video in → detections/tracking → event and player stats → team stats → recommendations and LLM-generated reports → CSV/JSON/chat outputs.
13. Key architectural dependency chain
- The most important data flow is: frame/video processing → tracking and perspective correction → event detectors and team/player attribution → aggregation into stats → recommendations and LLM narration.
- This layered design means failures or inaccuracies in early CV stages propagate into all downstream outputs.
14. Implementation stack that materially affects architecture
- The project is Python-based and depends on Flask for serving, OpenCV for video processing, Ultralytics YOLO for detection, supervision for tracking, pandas/numpy for analytics, Pulp for optimization, pytesseract for OCR, and google-generativeai for Gemini integration.
- Those libraries define the system boundaries: real-time-ish video analytics on one side, tabular recommendation and text generation on the other.
Main entry points: main.py Main run · event_process.py Event process · tracker.py Trackers · team_stats.py Team stats
Components 28
Video Intelligence
Frame processing, tracking, and event extraction from match video.
- Trackers · Core player, ball, referee, and goalkeeper tracking.
trackers/tracker.py - Camera motion · Estimates broadcast camera movement for stable coordinates.
camera_movement_estimator/camera_movement_estimator.py - Field view · Maps image coordinates into field-aware space.
view_transformer/view_transformer.py - Team assigner · Assigns players to teams from appearance cues.
team_assigner/team_assigner.py - Ball assigner · Links the ball to likely players and teams.
player_ball_assigner/player_ball_assigner.py - Number OCR · Detects jersey numbers for player identity merging.
player_number_detector/player_number_detector.py - Event process · General event processing for match actions and state.
event_process/event_process.py - Pass detector · Detects passing events from tracked play.
pass_detector/pass_detector.py - Shot detector · Detects shot attempts and related actions.
shot_detector/shot_detector.py - Substitution · Detects substitution events and board signals.
substitution_detector/substitution_detector.py - Goal/line · Handles goal-line and score-related processing.
goal_and_line_processor/goal_and_line_processor.py - New data · Adapts less common event classes into the pipeline.
new_data_handler/new_data_handler.py - Formation · Infers tactical formation from team structure.
formation_detector/formation_detector.py
Analytics & Recommendation
Aggregation layers and the recommendation engine built on structured match data.
- Speed stats · Computes distance and speed from tracked positions.
speed_and_distance_estimator/speed_and_distance_estimator.py - Player stats · Aggregates player-level metrics and merges same-number tracks.
player_stats/player_stats.py - Match state · Derives win/loss/draw state and team match context.
team_process/team_process.py - Team stats · Builds team summaries from player and formation data.
team_stats/team_stats.py - Recommendations · Generates formation, style, XI, and bench recommendations.
recommendation_systems/recommendation_systems.py
Serving & LLM
API, chatbot, and prompt generation for human-facing outputs.
- Main run · Local end-to-end pipeline entry point.
main.py - API routes · Project API surface for running pipeline actions.
end_points.py - Coach chat · Standalone chatbot service for interactive analysis.
chat_bot/app.py - Prompt builder · Assembles structured context for Gemini outputs.
generate_prompt/generate_prompt.py - Gemini utils · Shared helpers for Gemini-based generation and chat.
utils/Gemini_utils.py - Shared utils · Common utilities for bounding boxes, workflow, and recommendations.
utils/main_utils.py
Data & Assets
Input media, datasets, and generated output folders.
- Input videos · Video inputs for analysis runs.
input_videos/Atef.txt - Reco data · Cleaned tabular inputs for recommendation models.
recommendation_systems_input_files/data_cleaned.csv - CV outputs · Computer-vision output files and run artifacts.
output_files_computer_vision/Atef.txt - Reco outputs · Recommendation output files and run artifacts.
output_files_recommendation_systems/Atef.txt
Connections 32
- Main run → Trackers: orchestrates · Main pipeline starts tracking from match video.
- Main run → Camera motion: corrects motion · Compensates broadcast camera movement before analysis.
- Main run → Field view: projects field · Transforms positions into field-aware coordinates.
- Trackers → Team assigner: tracked players · Tracked detections feed team classification.
- Trackers → Ball assigner: tracked ball · Ball and player tracks support ball possession logic.
- Trackers → Number OCR: player crops · Cropped player images support jersey number OCR.
- Field view → Speed stats: coordinates · Perspective-correct positions drive movement metrics.
- Team assigner → Player stats: team labels · Team identity is used while aggregating player output.
- Number OCR → Player stats: identity merge · Shirt numbers help merge repeated player tracks.
- Speed stats → Player stats: movement metrics · Speed and distance are added to player summaries.
- Trackers → Event process: frame state · Event processing consumes tracking and match-state signals.
- Event process → Pass detector: detects · Pass detector extracts passing events.
- Event process → Shot detector: detects · Shot detector extracts shot events.
- Event process → Substitution: detects · Substitution detector extracts substitution events.
- Event process → Goal/line: detects · Goal-line processor handles score-related events.
- Event process → New data: adapts · New data handler normalizes additional event classes.
- Player stats → Team stats: roll up · Player-level summaries feed team-level analytics.
- Formation → Team stats: formation data · Formation inference contributes to team summaries.
- Match state → Team stats: match result · Match state informs team summary outputs.
- Team stats → Recommendations: structured team data · Recommendation engine uses aggregated team inputs.
- Reco data → Recommendations: historical data · Cleaned datasets support recommendation logic.
- Team stats → Prompt builder: summary inputs · Structured analytics are turned into LLM prompt context.
- Prompt builder → Gemini utils: Gemini payload · Prompt content is handed to Gemini helpers.
- Gemini utils → Coach chat: chat responses · Chat app uses Gemini integration for interactive outputs.
- Shared utils → Main run: shared workflow · Utilities support the main execution path.
- Shared utils → Recommendations: shared helpers · Recommendation helpers are reused across the pipeline.
- Input videos → Main run: video input · Main run consumes source match videos.
- Main run → CV outputs: writes · Computer vision pipeline emits artifacts.
- Recommendations → Reco outputs: writes · Recommendation engine emits output artifacts.
- API routes → Main run: invokes · API layer triggers the core pipeline.
- API routes → Recommendations: serves · API can expose recommendations directly.
- Coach chat → Prompt builder: builds context · Chat flow prepares structured prompts from analytics.