Adit-jain commited on
Commit
c4e14f8
Β·
verified Β·
1 Parent(s): 1d05b4d

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +300 -0
README.md ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ task_categories:
3
+ - object-detection
4
+ language:
5
+ - en
6
+ tags:
7
+ - soccer
8
+ - football
9
+ - pitch
10
+ - ground
11
+ - keypoints
12
+ - camera
13
+ - calibration
14
+ - homography
15
+ pretty_name: Soccana_keyp_v1
16
+ size_categories:
17
+ - 1K<n<10K
18
+ ---
19
+
20
+ # SoccerNet Keypoints Dataset
21
+
22
+ ---
23
+
24
+ ## Introduction
25
+
26
+ The SoccerNet Keypoints dataset is a comprehensive computer vision dataset for soccer field keypoint detection and pitch object localization. This dataset is derived from the SoccerNet calibration dataset and provides precise field keypoints extracted from line endpoints, enabling accurate field analysis, camera calibration, and tactical analysis in soccer videos.
27
+
28
+ In order to download the dataset, download Soccernet Calibration Dataset as given in [Soccernet Official Documentation](https://www.soccer-net.org/data). This repository contains keypoints and Object labels for the Soccernet data. (Soccernet by default provides edges.)
29
+
30
+ The dataset combines computer vision techniques including line intersection calculations, green area detection for pitch objects, and comprehensive keypoint extraction to create a robust dataset for Football Field Keypoint Detection
31
+
32
+ ## Dataset Details
33
+
34
+ ### Overview
35
+ - **Source**: SoccerNet Calibration Dataset
36
+ - **Task**: Keypoint Detection and Pitch Object Detection
37
+ - **Total Classes**: 1 (Pitch Object)
38
+ - **Total Keypoints**: 29 field keypoints per image
39
+ - **Coordinate System**: Normalized coordinates (0-1 range)
40
+ - **Annotation Format**: JSON + YOLO format
41
+ - **Dataset Splits**: Train, Validation, Test
42
+
43
+ ### Classes and Objects
44
+
45
+ #### Object Detection Classes
46
+ - **Class 0: Pitch Object**
47
+ - Complete green field area is termed at pitch object
48
+ - Bounding box encompasses entire visible pitch
49
+ - Normalized coordinates with center_x, center_y, width, height format
50
+
51
+ #### Keypoint Classes (29 Field Keypoints)
52
+ The dataset provides 29 precisely calculated field keypoints covering:
53
+
54
+ 1. **Field Boundaries (4 points)**
55
+ - `0_sideline_top_left`
56
+ - `9_sideline_bottom_left`
57
+ - `16_sideline_top_right`
58
+ - `25_sideline_bottom_right`
59
+
60
+ 2. **Penalty Areas - Big Box (8 points)**
61
+ - Left side: `1_big_rect_left_top_pt1`, `2_big_rect_left_top_pt2`, `3_big_rect_left_bottom_pt1`, `4_big_rect_left_bottom_pt2`
62
+ - Right side: `17_big_rect_right_top_pt1`, `18_big_rect_right_top_pt2`, `19_big_rect_right_bottom_pt1`, `20_big_rect_right_bottom_pt2`
63
+
64
+ 3. **Goal Areas - Small Box (8 points)**
65
+ - Left side: `5_small_rect_left_top_pt1`, `6_small_rect_left_top_pt2`, `7_small_rect_left_bottom_pt1`, `8_small_rect_left_bottom_pt2`
66
+ - Right side: `21_small_rect_right_top_pt1`, `22_small_rect_right_top_pt2`, `23_small_rect_right_bottom_pt1`, `24_small_rect_right_bottom_pt2`
67
+
68
+ 4. **Center Line and Circle (6 points)**
69
+ - `11_center_line_top`
70
+ - `12_center_line_bottom`
71
+ - `13_center_circle_top`
72
+ - `14_center_circle_bottom`
73
+ - `15_field_center`
74
+ - `27_center_circle_left`, `28_center_circle_right`
75
+
76
+ 5. **Semicircles (2 points)**
77
+ - `10_left_semicircle_right`
78
+ - `26_right_semicircle_left`
79
+
80
+ ---
81
+
82
+ ## Dataset Preparation
83
+
84
+ ### Download Process
85
+ View [downloader.py](https://github.com/Adit-jain/Soccer_Analysis/blob/main/Data_utils/SoccerNet_Keypoints/downloader.py) for reference on how to download Soccernet Data, or can refer official documentation at [Soccernet](https://www.soccer-net.org/data)
86
+
87
+ ### Processing Pipeline
88
+
89
+ The dataset preparation follows the following steps:
90
+
91
+ #### Line-to-Keypoint Conversion (`line_intersections.py`)
92
+ - **Class**: `LineIntersectionCalculator`
93
+ - **Input**: SoccerNet JSON files with line endpoints
94
+ - **Process**: Calculate 29 field keypoints from line intersections using geometric algorithms
95
+ - **Key Methods**:
96
+ - `line_intersection()`: Calculate intersection points between two lines
97
+ - `calculate_field_keypoints()`: Generate all 29 keypoints from line data
98
+ - `point_to_line_distance()`: Calculate perpendicular distances for circle keypoints
99
+
100
+ #### Pitch Object Detection (`get_pitch_object.py`)
101
+ - **Class**: `PitchDetector`
102
+ - **Process**: Detect complete green field area using HSV color segmentation
103
+ - **Key Methods**:
104
+ - `detect_green_area()`: HSV-based green area detection with morphological operations
105
+ - `find_largest_contour()`: Identify the largest contour as the pitch
106
+ - `get_pitch_bounding_box()`: Calculate normalized bounding box from contour
107
+
108
+ #### Unified Processing (`process_images.py`)
109
+ - **Function**: `process_unified_soccernet_dataset()`
110
+ - **Output Formats**:
111
+ - **JSON annotations**: Complete metadata with keypoints and pitch objects
112
+ - **YOLO labels**: Ultralytics-compatible format for training
113
+ - **Visualization images**: Annotated images showing detections
114
+
115
+ #### Dataset Configuration (`create_dataset_yaml.py`)
116
+ - Generate `dataset.yaml` for Ultralytics YOLO training
117
+ - Configure keypoint connections for visualization
118
+ - Set up dataset paths and class definitions
119
+
120
+ **[Github Repo](https://github.com/Adit-jain/Soccer_Analysis/tree/main/Data_utils/SoccerNet_Keypoints)**
121
+
122
+ ---
123
+
124
+ ## Dataset Format
125
+
126
+ ### Directory Structure
127
+ ```
128
+ unified_output/
129
+ β”œβ”€β”€ annotations_json/ # Complete JSON annotations
130
+ β”‚ β”œβ”€β”€ train/
131
+ β”‚ β”œβ”€β”€ valid/
132
+ β”‚ └── test/
133
+ β”œβ”€β”€ processed_images/ # Visualization images
134
+ β”‚ β”œβ”€β”€ train/
135
+ β”‚ β”œβ”€β”€ valid/
136
+ β”‚ └── test/
137
+ β”œβ”€β”€ yolo_labels/ # Ultralytics YOLO format
138
+ β”‚ β”œβ”€β”€ train/
139
+ β”‚ β”œβ”€β”€ valid/
140
+ β”‚ └── test/
141
+ β”œβ”€β”€ dataset.yaml # YOLO configuration
142
+ └── README.md # Usage instructions
143
+ ```
144
+
145
+ ### Annotation Formats
146
+
147
+ #### JSON Format (Complete Annotations)
148
+ ```json
149
+ {
150
+ "image_info": {
151
+ "file_name": "image.jpg",
152
+ "path": "/path/to/image.jpg",
153
+ "width": 1920,
154
+ "height": 1080
155
+ },
156
+ "pitch_object": {
157
+ "class_id": 0,
158
+ "class_name": "pitch",
159
+ "center_x": 0.5,
160
+ "center_y": 0.5,
161
+ "width": 0.8,
162
+ "height": 0.6,
163
+ "x_min": 0.1,
164
+ "y_min": 0.2,
165
+ "x_max": 0.9,
166
+ "y_max": 0.8,
167
+ "area": 0.48,
168
+ "contour_area": 0.45
169
+ },
170
+ "keypoints": {
171
+ "0_sideline_top_left": [0.1, 0.2],
172
+ "1_big_rect_left_top_pt1": [0.15, 0.25],
173
+ ...
174
+ },
175
+ "original_lines": {
176
+ "Side line top": [{"x": 0.1, "y": 0.2}, {"x": 0.9, "y": 0.2}],
177
+ ...
178
+ },
179
+ "dataset_split": "train",
180
+ "total_keypoints": 29,
181
+ "annotation_format": "SoccerNet_unified_v1"
182
+ }
183
+ ```
184
+
185
+ #### YOLO Format (Ultralytics Compatible)
186
+ ```
187
+ 0 0.500000 0.500000 0.800000 0.600000 0.100000 0.200000 2 0.150000 0.250000 2 ... (29 keypoints with visibility)
188
+ ```
189
+
190
+ Format: `<class-index> <center_x> <center_y> <width> <height> <kp1_x> <kp1_y> <kp1_visibility> <kp2_x> <kp2_y> <kp2_visibility> ...`
191
+
192
+ ### Keypoint Visibility
193
+ - **2**: Visible keypoint (calculated successfully)
194
+ - **0**: Not visible/not detected (coordinates set to 0.0, 0.0)
195
+
196
+ ### Coordinate System
197
+ - All coordinates normalized to [0, 1] range
198
+ - Origin (0,0) at top-left corner of image
199
+ - X-axis increases rightward, Y-axis increases downward
200
+
201
+ ---
202
+
203
+ ## Usage Examples
204
+
205
+ ### Training with Ultralytics YOLO
206
+ ```python
207
+ from ultralytics import YOLO
208
+
209
+ # Load pre-trained pose model
210
+ model = YOLO('yolov8n-pose.pt')
211
+
212
+ # Train on SoccerNet Keypoints
213
+ results = model.train(
214
+ data='dataset.yaml',
215
+ epochs=100,
216
+ imgsz=640,
217
+ batch=16,
218
+ name='soccernet_keypoints'
219
+ )
220
+ ```
221
+
222
+ ### Custom Processing
223
+ ```python
224
+ from get_pitch_object import PitchDetector
225
+ from line_intersections import LineIntersectionCalculator
226
+
227
+ # Initialize processors
228
+ pitch_detector = PitchDetector()
229
+ keypoint_calculator = LineIntersectionCalculator()
230
+
231
+ # Process single image
232
+ pitch_result = pitch_detector.detect_pitch_from_image('image.jpg')
233
+ keypoint_calculator.load_soccernet_data('annotations.json')
234
+ keypoints, lines = keypoint_calculator.calculate_field_keypoints()
235
+ ```
236
+
237
+ ### Visualization
238
+ ```python
239
+ from process_images import create_unified_visualization
240
+
241
+ create_unified_visualization(
242
+ image_path='image.jpg',
243
+ pitch_data=pitch_result['pitch_detection'],
244
+ keypoints=keypoints,
245
+ lines=lines,
246
+ output_path='annotated_image.jpg'
247
+ )
248
+ ```
249
+
250
+ ---
251
+
252
+ ## Technical Implementation
253
+
254
+ ### Core Algorithms
255
+
256
+ #### Line Intersection Mathematics
257
+ Using parametric line representation:
258
+ - Line 1: `P = P1 + t(P2 - P1)`
259
+ - Line 2: `Q = Q1 + u(Q2 - Q1)`
260
+ - Intersection calculated using determinant method with parallel line detection
261
+
262
+ #### HSV Color Segmentation
263
+ - Green detection optimized for grass fields
264
+ - Morphological operations for noise reduction
265
+ - Largest contour selection for pitch identification
266
+
267
+ #### Keypoint Validation
268
+ - Coordinate boundary checking [0,1]
269
+ - Distance-based point selection for circles
270
+ - Error handling for missing line data
271
+
272
+ ### Performance Optimizations
273
+ - Batch processing with progress tracking
274
+ - Efficient contour operations
275
+ - Optimized intersection calculations
276
+ - Memory-efficient image processing
277
+
278
+ ---
279
+
280
+ ## Repository Structure
281
+
282
+ **GitHub Repository**: [https://github.com/Adit-jain/Soccer_Analysis/tree/main/Data_utils/SoccerNet_Keypoints](https://github.com/Adit-jain/Soccer_Analysis/tree/main/Data_utils/SoccerNet_Keypoints)
283
+
284
+ ### Module Overview
285
+ - `constants.py`: Dataset configuration and field specifications
286
+ - `downloader.py`: SoccerNet data download utilities
287
+ - `get_pitch_object.py`: Pitch object detection using color segmentation
288
+ - `line_intersections.py`: Geometric keypoint calculation from line endpoints
289
+ - `process_images.py`: Unified processing pipeline for all formats
290
+ - `create_dataset_yaml.py`: YOLO configuration generation
291
+ - `transfer_json_files.py`: Data organization utilities
292
+
293
+ ### Integration
294
+ This dataset preparation module integrates seamlessly with the main Soccer Analysis project, providing field keypoints for:
295
+ - Camera calibration and homography estimation
296
+ - Tactical analysis and player positioning
297
+ - Field coordinate transformations
298
+ - Real-time field understanding in soccer videos
299
+
300
+ The dataset serves as a foundation for advanced soccer analysis applications including tactical analysis, player tracking calibration, and automated field understanding systems.