Views
No views yet

sideline_top_left (0): Top-left corner of the fieldsideline_top_right (16): Top-right corner of the fieldsideline_bottom_left (9): Bottom-left corner of the fieldsideline_bottom_right (25): Bottom-right corner of the fieldbig_rect_left_* (1-4)big_rect_right_* (17-20)small_rect_left_* (5-8)small_rect_right_* (21-24)center_line_top (11), center_line_bottom (12)center_circle_* (13-14, 27-28)field_center (15)left_semicircle_right (10), right_semicircle_left (26)1KEYPOINT_NAMES = {
2 0: "sideline_top_left",
3 1: "big_rect_left_top_pt1",
4 2: "big_rect_left_top_pt2",
5 3: "big_rect_left_bottom_pt1",
6 4: "big_rect_left_bottom_pt2",
7 5: "small_rect_left_top_pt1",
8 6: "small_rect_left_top_pt2",
9 7: "small_rect_left_bottom_pt1",
10 8: "small_rect_left_bottom_pt2",
11 9: "sideline_bottom_left",
12 10: "left_semicircle_right",
13 11: "center_line_top",
14 12: "center_line_bottom",
15 13: "center_circle_top",
16 14: "center_circle_bottom",
17 15: "field_center",
18 16: "sideline_top_right",
19 17: "big_rect_right_top_pt1",
20 18: "big_rect_right_top_pt2",
21 19: "big_rect_right_bottom_pt1",
22 20: "big_rect_right_bottom_pt2",
23 21: "small_rect_right_top_pt1",
24 22: "small_rect_right_top_pt2",
25 23: "small_rect_right_bottom_pt1",
26 24: "small_rect_right_bottom_pt2",
27 25: "sideline_bottom_right",
28 26: "right_semicircle_left",
29 27: "center_circle_left",
30 28: "center_circle_right",
31}| Parameter | Value | Description |
|---|---|---|
| Input Size | 640×640 | Default input resolution |
| Batch Size | 32 | Training batch size |
| Epochs | 200 | Default training epochs |
| Confidence Threshold | 0.5 | Keypoint visibility threshold |
| Learning Rate | 0.01 | Initial learning rate |
| Dropout | 0.3 | Regularization dropout rate |
| Architecture | YOLOv11n-pose | Efficient pose estimation variant |
1keypoints: np.ndarray # Shape: (N, 29, 3)
2# N = number of field detections
3# 29 = number of keypoints per detection
4# 3 = (x_coordinate, y_coordinate, visibility_confidence)> 0.5: Keypoint is visible and reliable≤ 0.5: Keypoint is occluded or uncertain1corners = {
2 'top_left': (x, y), # Field corner coordinates
3 'top_right': (x, y), # in image pixel space
4 'bottom_left': (x, y),
5 'bottom_right': (x, y)
6}1dimensions = {
2 'width': field_width, # Calculated field width in pixels
3 'height': field_height, # Calculated field height in pixels
4 'area': field_area # Total field area
5}1from keypoint_detection import load_keypoint_model, get_keypoint_detections
2import cv2
3
4# Load the keypoint detection model
5model_path = "Models/Trained/yolov11_keypoints_29/First/weights/best.pt"
6model = load_keypoint_model(model_path)
7
8# Process a single frame
9frame = cv2.imread("soccer_field.jpg")
10detections, keypoints = get_keypoint_detections(model, frame)
11
12# Extract field information
13from keypoint_detection import extract_field_corners, calculate_field_dimensions
14corners = extract_field_corners(keypoints)
15dimensions = calculate_field_dimensions(corners)
16
17print(f"Detected {len(detections)} field(s)")
18print(f"Field corners: {corners}")
19print(f"Field dimensions: {dimensions}")1from pipelines import KeypointPipeline
2
3# Initialize pipeline
4pipeline = KeypointPipeline(model_path)
5
6# Process video with keypoint detection
7pipeline.detect_in_video(
8 video_path="input_match.mp4",
9 output_path="output_with_keypoints.mp4",
10 frame_count=1000
11)
12
13# Real-time keypoint detection
14pipeline.detect_realtime("live_stream.mp4")1from pipelines import TacticalPipeline
2
3# Complete tactical analysis with keypoint-based field mapping
4tactical_pipeline = TacticalPipeline(
5 keypoint_model_path=model_path,
6 detection_model_path=detection_model_path
7)
8
9# Generate tactical overlay
10tactical_pipeline.analyze_video(
11 input_path="match.mp4",
12 output_path="tactical_analysis.mp4",
13 output_mode="overlay" # Options: "overlay", "side-by-side", "tactical-only"
14)1from keypoint_detection.training import YOLOKeypointTrainer, TrainingConfig
2
3# Create custom training configuration
4config = TrainingConfig(
5 dataset_yaml_path="path/to/keypoint_dataset.yaml",
6 model_name="custom_keypoint_model",
7 epochs=100,
8 img_size=640,
9 batch_size=16
10)
11
12# Initialize trainer and start training
13trainer = YOLOKeypointTrainer(config)
14results = trainer.train_and_validate()Soccer_Analysis/
├── keypoint_detection/ # Core keypoint detection module
│ ├── detect_keypoints.py # Core detection functions
│ ├── keypoint_constants.py # Field specifications & keypoint mapping
│ └── training/ # Training utilities
│ ├── config.py # Training configuration
│ ├── trainer.py # Modular trainer class
│ └── main.py # Training entry point
├── pipelines/ # Pipeline coordination
│ ├── keypoint_pipeline.py # Keypoint detection pipeline
│ └── tactical_pipeline.py # Tactical analysis with keypoints
├── tactical_analysis/ # Field coordinate transformations
│ └── homography.py # Homography calculations using keypoints
└── main.py # Multi-analysis entry point