RamziBm commited on
Commit
67c15c3
·
1 Parent(s): 41f1119

feat: Mise à jour du README pour inclure la détection de ballon, les modèles requis et les instructions d'utilisation pour l'application Gradio.

Browse files
Files changed (1) hide show
  1. README.md +48 -27
README.md CHANGED
@@ -13,20 +13,23 @@ pinned: false
13
 
14
  This project uses the TvCalib library to calculate the homography matrix for a football pitch image. This matrix allows mapping image points onto a standard 2D representation of the pitch (minimap).
15
 
16
- The project also includes a pose estimation step (ViTPose) to detect players and calculate the average color of their torso.
 
 
17
 
18
- **The main result is a minimap where each player is represented by their colored skeleton, drawn at a *dynamically* reduced scale around their projected position on the pitch.**
19
- The position is determined by projecting a reference point (feet/bottom of bbox) using the homography. The skeleton is then drawn using its relative coordinates (original image), scaled, and translated. The scale used depends on the **player's vertical position (Y) on the minimap** (higher on the minimap = smaller) and a base factor adjustable via the `--target_avg_scale` option.
20
 
21
  It is also possible to visualize a minimap with the projection of the original image for comparison.
22
 
23
  ## Features
24
 
25
  * Homography calculation from a single image via TvCalib.
 
26
  * Person detection (RT-DETR) and pose estimation (ViTPose).
27
  * Calculation of the filtered average torso color for each player.
28
- * Projection of each player's reference point (feet/bbox) onto the minimap.
29
- * Generation of a minimap with the **original skeletons (colored, dynamically scaled based on projected Y position, and offset) drawn around the projected point**.
30
  * (Optional) Generation of a minimap with the projected original image.
31
  * Possibility to save the calculated homography matrix.
32
 
@@ -39,13 +42,16 @@ It is also possible to visualize a minimap with the projection of the original i
39
  ├── common/ # Common Python modules (potentially)
40
  ├── data/ # Data (input images, etc.)
41
  ├── models/
 
 
42
  │ └── segmentation/
43
  │ └── train_59.pt # Pre-trained segmentation model (TO DOWNLOAD)
44
  ├── tvcalib/ # Source code of the TvCalib library (or a fork/adaptation)
45
  │ └── infer/
46
  │ └── module.py # Main module for TvCalib inference
47
  ├── .gitignore # Files ignored by Git
48
- ├── main.py # Main script entry point
 
49
  ├── requirements.txt # Python dependencies file
50
  ├── visualizer.py # Module for generating visualization minimaps
51
  ├── pose_estimator.py # Module for pose estimation and player data extraction
@@ -70,50 +76,65 @@ It is also possible to visualize a minimap with the projection of the original i
70
  ```powershell
71
  pip install -r requirements.txt
72
  ```
73
- *(Make sure to install PyTorch with appropriate CUDA support if needed.)*
74
 
75
- 4. **Download the segmentation model:**
76
- Place `train_59.pt` in `models/segmentation/`.
 
77
 
78
- 5. **(Automatic) Download detection/pose models:**
79
- The RT-DETR and ViTPose models will be downloaded automatically.
80
 
81
  ## Usage
82
 
83
- Run the `main.py` script providing the path to the image:
84
 
 
85
  ```powershell
86
  python main.py path/to/your/image.jpg [OPTIONS]
87
  ```
88
 
89
- **Options:**
 
 
 
 
 
 
90
 
91
  * `image_path`: Path to the input image (required).
92
  * `--output_homography PATH.npy`: Saves the calculated homography matrix.
93
- * `--optim_steps NUMBER`: Number of optimization steps for calibration (default: 500, was 1000 in original README example).
94
- * `--target_avg_scale FLOAT`: **Target average** scale factor for drawing skeletons (default: 0.35). The script attempts to adjust the internal base scale so that the resulting average scale (after inverse dynamic modulation) is close to this value.
95
 
96
  **Example:**
97
 
98
  ```powershell
99
- # Simple usage (target average size 0.35)
100
  python main.py data/img3.png
101
 
102
- # Aim for larger skeletons on average (target 0.5)
103
- python main.py data/img2.png --target_avg_scale 0.5
104
  ```
105
 
106
- The script will display:
107
- * Time taken and homography matrix.
108
- * Estimated internal base scale.
109
- * Requested TARGET average scale.
110
- * ACTUALLY applied FINAL average scale.
111
- * Window: **Minimap with Original Projection**.
112
- * Window: **Minimap with Offset Skeletons** (dynamically scaled inversely, targeting the average scale).
113
- * Press any key to close.
 
 
114
 
115
  ## Key Dependencies
116
 
117
  * PyTorch, OpenCV, NumPy, PyTorch Lightning
118
- * SoccerNet, Kornia, Hugging Face Transformers, Pillow
 
 
 
 
 
119
 
 
13
 
14
  This project uses the TvCalib library to calculate the homography matrix for a football pitch image. This matrix allows mapping image points onto a standard 2D representation of the pitch (minimap).
15
 
16
+ The project also includes:
17
+ * **Ball detection** using a YOLO model (`yolo_football.pt`).
18
+ * **Pose estimation** (ViTPose) to detect players and calculate the average color of their torso.
19
 
20
+ **The main result is a minimap where each player is represented by their colored skeleton, drawn at a *dynamically* reduced scale around their projected position on the pitch, and the ball is represented by a white circle.**
21
+ The position is determined by projecting a reference point (feet/bottom of bbox for players, bottom center for ball) using the homography. The skeleton is then drawn using its relative coordinates (original image), scaled, and translated. The scale used depends on the **player's vertical position (Y) on the minimap** (higher on the minimap = smaller) and a base factor adjustable via the `--target_avg_scale` option.
22
 
23
  It is also possible to visualize a minimap with the projection of the original image for comparison.
24
 
25
  ## Features
26
 
27
  * Homography calculation from a single image via TvCalib.
28
+ * Ball detection using YOLO (`yolo_football.pt`).
29
  * Person detection (RT-DETR) and pose estimation (ViTPose).
30
  * Calculation of the filtered average torso color for each player.
31
+ * Projection of each player's and the ball's reference point onto the minimap.
32
+ * Generation of a minimap with the **original skeletons (colored, dynamically scaled based on projected Y position, and offset) drawn around the projected player points, and a white marker for the projected ball position**.
33
  * (Optional) Generation of a minimap with the projected original image.
34
  * Possibility to save the calculated homography matrix.
35
 
 
42
  ├── common/ # Common Python modules (potentially)
43
  ├── data/ # Data (input images, etc.)
44
  ├── models/
45
+ │ ├── detection/
46
+ │ │ └── yolo_football.pt # YOLO model for ball detection (TO DOWNLOAD)
47
  │ └── segmentation/
48
  │ └── train_59.pt # Pre-trained segmentation model (TO DOWNLOAD)
49
  ├── tvcalib/ # Source code of the TvCalib library (or a fork/adaptation)
50
  │ └── infer/
51
  │ └── module.py # Main module for TvCalib inference
52
  ├── .gitignore # Files ignored by Git
53
+ ├── app.py # Gradio web application entry point
54
+ ├── main.py # Main script entry point (command line)
55
  ├── requirements.txt # Python dependencies file
56
  ├── visualizer.py # Module for generating visualization minimaps
57
  ├── pose_estimator.py # Module for pose estimation and player data extraction
 
76
  ```powershell
77
  pip install -r requirements.txt
78
  ```
79
+ *(Make sure to install PyTorch with appropriate CUDA support if needed, see comment in `requirements.txt`)*
80
 
81
+ 4. **Download the required models:**
82
+ * Place the segmentation model `train_59.pt` in `models/segmentation/`.
83
+ * Place the YOLO ball detection model `yolo_football.pt` in `models/detection/`. (You need to obtain this model separately).
84
 
85
+ 5. **(Automatic) Download other detection/pose models:**
86
+ The RT-DETR and ViTPose models will be downloaded automatically by the `transformers` library on first use.
87
 
88
  ## Usage
89
 
90
+ Run the `main.py` script (command line) or `app.py` (Gradio interface) providing the path to the image:
91
 
92
+ **Command Line:**
93
  ```powershell
94
  python main.py path/to/your/image.jpg [OPTIONS]
95
  ```
96
 
97
+ **Gradio App:**
98
+ ```powershell
99
+ python app.py
100
+ # Then open the provided local URL in your browser.
101
+ ```
102
+
103
+ **Options (for `main.py`):**
104
 
105
  * `image_path`: Path to the input image (required).
106
  * `--output_homography PATH.npy`: Saves the calculated homography matrix.
107
+ * `--optim_steps NUMBER`: Number of optimization steps for calibration (default: 500).
108
+ * `--target_avg_scale FLOAT`: **Target average** scale factor for drawing skeletons (default: 1.0). The script attempts to adjust the internal base scale so that the resulting average scale (after inverse dynamic modulation) is close to this value.
109
 
110
  **Example:**
111
 
112
  ```powershell
113
+ # Simple usage (target average size 1.0)
114
  python main.py data/img3.png
115
 
116
+ # Aim for larger skeletons on average (target 1.5)
117
+ python main.py data/img2.png --target_avg_scale 1.5
118
  ```
119
 
120
+ The script (`main.py`) or Gradio app (`app.py`) will display:
121
+ * Time taken for different steps (console output for `main.py`).
122
+ * Calculated homography matrix (console output for `main.py`).
123
+ * Information about detected ball and players (console output for `main.py`).
124
+ * Estimated internal base scale for skeletons (console output for `main.py`).
125
+ * Requested TARGET average scale (console output for `main.py`).
126
+ * ACTUALLY applied FINAL average scale (console output for `main.py`).
127
+ * Window/Image Output 1: **Minimap with Original Projection**.
128
+ * Window/Image Output 2: **Minimap with Offset Skeletons** (dynamically scaled inversely, targeting the average scale) **and Ball Marker**.
129
+ * (`main.py` only) Press any key to close the display windows.
130
 
131
  ## Key Dependencies
132
 
133
  * PyTorch, OpenCV, NumPy, PyTorch Lightning
134
+ * SoccerNet, Kornia, Hugging Face Transformers, Pillow
135
+ * `ultralytics` (for YOLO ball detection)
136
+ * `gradio` (for the web interface `app.py`)
137
+
138
+ ---
139
+ Note: Ensure the `tvcalib` directory is correctly structured or added to your PYTHONPATH if you encounter import errors related to it.
140