Adit-jain commited on
Commit
394ca7d
Β·
verified Β·
1 Parent(s): ef30d3d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +269 -0
README.md CHANGED
@@ -19,3 +19,272 @@ tags:
19
  - homography
20
  ---
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  - homography
20
  ---
21
 
22
+ # ⚽ Soccer Field Keypoint Detection Model
23
+
24
+ <div align="center">
25
+
26
+ <p>
27
+ <img src="Keypoint_thumbnail.jpg" width="600"/>
28
+ </p>
29
+
30
+ [Demo Link](https://drive.google.com/file/d/1zrQ76-K3Dr0YYS_i3RUxoOGPowcCUiBE/view?usp=sharing)
31
+
32
+ *Advanced computer vision model for detecting and analyzing soccer field keypoints using YOLOv11 pose estimation*
33
+
34
+ [![GitHub](https://img.shields.io/badge/GitHub-Soccer_Analysis-blue?logo=github)](https://github.com/Adit-jain/Soccer_Analysis)
35
+ [![Python](https://img.shields.io/badge/Python-3.8%2B-green?logo=python)](https://www.python.org/)
36
+ [![YOLOv11](https://img.shields.io/badge/YOLOv11-Pose-orange)](https://github.com/ultralytics/ultralytics)
37
+
38
+ </div>
39
+
40
+ ## πŸ“– Introduction
41
+
42
+ The **Soccer Field Keypoint Detection Model** is a computer vision solution designed specifically for detecting and analyzing soccer field keypoints in video streams and images. Built on the YOLOv11 pose estimation architecture, this model can accurately identify 29 critical keypoints that define the geometry of a soccer field, including corners, penalty areas, goal areas, center circle, and other field markings.
43
+
44
+ This model is part of the comprehensive [Soccer Analysis](https://github.com/Adit-jain/Soccer_Analysis) project and enables advanced tactical analysis, field coordinate transformations, and homography calculations for professional soccer video analysis.
45
+
46
+ ### 🎯 Key Features
47
+
48
+ - **29-Point Field Detection**: Comprehensive keypoint coverage including all major field markings
49
+ - **Real-Time Performance**: Optimized for live video analysis and streaming applications
50
+ - **High Accuracy**: Robust detection across various camera angles, lighting conditions, and field qualities
51
+ - **FIFA Standards Compliant**: Keypoint mapping follows official FIFA field specifications
52
+ - **Tactical Analysis Ready**: Direct integration with homography transformations and tactical overlays
53
+
54
+ The model demonstrates exceptional performance across diverse scenarios:
55
+
56
+ #### βœ… **Multi-Scenario Detection**
57
+ - **Various Camera Angles**: From broadcast to close-up perspectives
58
+ - **Different Field Conditions**: Natural grass, artificial turf, various lighting
59
+ - **Partial Field Visibility**: Robust detection even with incomplete field views
60
+ - **Real-Time Processing**: 30+ FPS on standard hardware
61
+
62
+ #### πŸ“Š **Detection Examples**
63
+ - Corner detection with sub-pixel accuracy
64
+ - Penalty area boundary identification
65
+ - Center circle and center line detection
66
+ - Goal area precise mapping
67
+ - Sideline boundary recognition
68
+
69
+ ## πŸ—οΈ Model Details and Architecture
70
+
71
+ ### Base Architecture
72
+ - **Model Type**: YOLOv11 Pose Estimation
73
+ - **Input Resolution**: 640Γ—640 pixels (configurable)
74
+ - **Keypoint Count**: 29 field-specific keypoints
75
+ - **Output Format**: (x, y, visibility) for each keypoint
76
+ - **Framework**: Ultralytics YOLOv11 with PyTorch backend
77
+
78
+ ### Keypoint Mapping (29 Points)
79
+
80
+ The model detects 29 strategically placed keypoints covering all major field elements:
81
+
82
+ #### 🏁 **Field Boundaries (4 points)**
83
+ - `sideline_top_left` (0): Top-left corner of the field
84
+ - `sideline_top_right` (16): Top-right corner of the field
85
+ - `sideline_bottom_left` (9): Bottom-left corner of the field
86
+ - `sideline_bottom_right` (25): Bottom-right corner of the field
87
+
88
+ #### ⚽ **Penalty Areas (8 points)**
89
+ - Left penalty area: `big_rect_left_*` (1-4)
90
+ - Right penalty area: `big_rect_right_*` (17-20)
91
+
92
+ #### πŸ₯… **Goal Areas (8 points)**
93
+ - Left goal area: `small_rect_left_*` (5-8)
94
+ - Right goal area: `small_rect_right_*` (21-24)
95
+
96
+ #### 🎯 **Center Elements (9 points)**
97
+ - Center line: `center_line_top` (11), `center_line_bottom` (12)
98
+ - Center circle: `center_circle_*` (13-14, 27-28)
99
+ - Field center: `field_center` (15)
100
+ - Semicircles: `left_semicircle_right` (10), `right_semicircle_left` (26)
101
+
102
+ ```python
103
+ KEYPOINT_NAMES = {
104
+ 0: "sideline_top_left",
105
+ 1: "big_rect_left_top_pt1",
106
+ 2: "big_rect_left_top_pt2",
107
+ 3: "big_rect_left_bottom_pt1",
108
+ 4: "big_rect_left_bottom_pt2",
109
+ 5: "small_rect_left_top_pt1",
110
+ 6: "small_rect_left_top_pt2",
111
+ 7: "small_rect_left_bottom_pt1",
112
+ 8: "small_rect_left_bottom_pt2",
113
+ 9: "sideline_bottom_left",
114
+ 10: "left_semicircle_right",
115
+ 11: "center_line_top",
116
+ 12: "center_line_bottom",
117
+ 13: "center_circle_top",
118
+ 14: "center_circle_bottom",
119
+ 15: "field_center",
120
+ 16: "sideline_top_right",
121
+ 17: "big_rect_right_top_pt1",
122
+ 18: "big_rect_right_top_pt2",
123
+ 19: "big_rect_right_bottom_pt1",
124
+ 20: "big_rect_right_bottom_pt2",
125
+ 21: "small_rect_right_top_pt1",
126
+ 22: "small_rect_right_top_pt2",
127
+ 23: "small_rect_right_bottom_pt1",
128
+ 24: "small_rect_right_bottom_pt2",
129
+ 25: "sideline_bottom_right",
130
+ 26: "right_semicircle_left",
131
+ 27: "center_circle_left",
132
+ 28: "center_circle_right",
133
+ }
134
+ ```
135
+
136
+ ### Technical Specifications
137
+
138
+ | Parameter | Value | Description |
139
+ |-----------|-------|-------------|
140
+ | **Input Size** | 640Γ—640 | Default input resolution |
141
+ | **Batch Size** | 32 | Training batch size |
142
+ | **Epochs** | 200 | Default training epochs |
143
+ | **Confidence Threshold** | 0.5 | Keypoint visibility threshold |
144
+ | **Learning Rate** | 0.01 | Initial learning rate |
145
+ | **Dropout** | 0.3 | Regularization dropout rate |
146
+ | **Architecture** | YOLOv11n-pose | Efficient pose estimation variant |
147
+
148
+ ## πŸ“€ Model Output
149
+
150
+ ### Detection Format
151
+ The model outputs keypoint detections in the following structure:
152
+
153
+ ```python
154
+ keypoints: np.ndarray # Shape: (N, 29, 3)
155
+ # N = number of field detections
156
+ # 29 = number of keypoints per detection
157
+ # 3 = (x_coordinate, y_coordinate, visibility_confidence)
158
+ ```
159
+
160
+ ### Visibility Confidence
161
+ - **Range**: 0.0 to 1.0
162
+ - **Threshold**: 0.5 (configurable)
163
+ - **Interpretation**:
164
+ - `> 0.5`: Keypoint is visible and reliable
165
+ - `≀ 0.5`: Keypoint is occluded or uncertain
166
+
167
+ ### Field Corner Extraction
168
+ ```python
169
+ corners = {
170
+ 'top_left': (x, y), # Field corner coordinates
171
+ 'top_right': (x, y), # in image pixel space
172
+ 'bottom_left': (x, y),
173
+ 'bottom_right': (x, y)
174
+ }
175
+ ```
176
+
177
+ ### Field Dimensions
178
+ ```python
179
+ dimensions = {
180
+ 'width': field_width, # Calculated field width in pixels
181
+ 'height': field_height, # Calculated field height in pixels
182
+ 'area': field_area # Total field area
183
+ }
184
+ ```
185
+
186
+ ## πŸš€ Usage and Implementation
187
+
188
+ ### Quick Start
189
+
190
+ ```python
191
+ from keypoint_detection import load_keypoint_model, get_keypoint_detections
192
+ import cv2
193
+
194
+ # Load the keypoint detection model
195
+ model_path = "Models/Trained/yolov11_keypoints_29/First/weights/best.pt"
196
+ model = load_keypoint_model(model_path)
197
+
198
+ # Process a single frame
199
+ frame = cv2.imread("soccer_field.jpg")
200
+ detections, keypoints = get_keypoint_detections(model, frame)
201
+
202
+ # Extract field information
203
+ from keypoint_detection import extract_field_corners, calculate_field_dimensions
204
+ corners = extract_field_corners(keypoints)
205
+ dimensions = calculate_field_dimensions(corners)
206
+
207
+ print(f"Detected {len(detections)} field(s)")
208
+ print(f"Field corners: {corners}")
209
+ print(f"Field dimensions: {dimensions}")
210
+ ```
211
+
212
+ ### Pipeline Integration
213
+
214
+ ```python
215
+ from pipelines import KeypointPipeline
216
+
217
+ # Initialize pipeline
218
+ pipeline = KeypointPipeline(model_path)
219
+
220
+ # Process video with keypoint detection
221
+ pipeline.detect_in_video(
222
+ video_path="input_match.mp4",
223
+ output_path="output_with_keypoints.mp4",
224
+ frame_count=1000
225
+ )
226
+
227
+ # Real-time keypoint detection
228
+ pipeline.detect_realtime("live_stream.mp4")
229
+ ```
230
+
231
+ ### Advanced Usage with Tactical Analysis
232
+
233
+ ```python
234
+ from pipelines import TacticalPipeline
235
+
236
+ # Complete tactical analysis with keypoint-based field mapping
237
+ tactical_pipeline = TacticalPipeline(
238
+ keypoint_model_path=model_path,
239
+ detection_model_path=detection_model_path
240
+ )
241
+
242
+ # Generate tactical overlay
243
+ tactical_pipeline.analyze_video(
244
+ input_path="match.mp4",
245
+ output_path="tactical_analysis.mp4",
246
+ output_mode="overlay" # Options: "overlay", "side-by-side", "tactical-only"
247
+ )
248
+ ```
249
+
250
+ ### Training Custom Models
251
+
252
+ ```python
253
+ from keypoint_detection.training import YOLOKeypointTrainer, TrainingConfig
254
+
255
+ # Create custom training configuration
256
+ config = TrainingConfig(
257
+ dataset_yaml_path="path/to/keypoint_dataset.yaml",
258
+ model_name="custom_keypoint_model",
259
+ epochs=100,
260
+ img_size=640,
261
+ batch_size=16
262
+ )
263
+
264
+ # Initialize trainer and start training
265
+ trainer = YOLOKeypointTrainer(config)
266
+ results = trainer.train_and_validate()
267
+ ```
268
+
269
+ ## πŸ“ GitHub Repository
270
+
271
+ **Repository**: [Soccer_Analysis](https://github.com/Adit-jain/Soccer_Analysis)
272
+
273
+ ### Project Structure
274
+ ```
275
+ Soccer_Analysis/
276
+ β”œβ”€β”€ keypoint_detection/ # Core keypoint detection module
277
+ β”‚ β”œβ”€β”€ detect_keypoints.py # Core detection functions
278
+ β”‚ β”œβ”€β”€ keypoint_constants.py # Field specifications & keypoint mapping
279
+ β”‚ └── training/ # Training utilities
280
+ β”‚ β”œβ”€β”€ config.py # Training configuration
281
+ β”‚ β”œβ”€β”€ trainer.py # Modular trainer class
282
+ β”‚ └── main.py # Training entry point
283
+ β”œβ”€β”€ pipelines/ # Pipeline coordination
284
+ β”‚ β”œβ”€β”€ keypoint_pipeline.py # Keypoint detection pipeline
285
+ β”‚ └── tactical_pipeline.py # Tactical analysis with keypoints
286
+ β”œβ”€β”€ tactical_analysis/ # Field coordinate transformations
287
+ β”‚ └── homography.py # Homography calculations using keypoints
288
+ └── main.py # Multi-analysis entry point
289
+ ```
290
+ ---