File size: 1,769 Bytes
a422282
95ad9d6
 
a422282
 
 
 
cffadc9
95ad9d6
 
 
cffadc9
 
34aaec8
cffadc9
 
34aaec8
43be61b
 
34aaec8
43be61b
34aaec8
43be61b
34aaec8
 
 
 
 
 
43be61b
a422282
34aaec8
 
0723bf0
34aaec8
 
 
a422282
 
0723bf0
34aaec8
a422282
 
34aaec8
 
 
 
 
 
 
95ad9d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Simplified swing analyzer - contains only essential functions
Cleaned up to remove unused functions per user requirements
"""

import numpy as np


# One-liner frame mapping replacement
def to_processed_idx(original_idx, sample_rate): 
    return int(round(original_idx / max(1, sample_rate)))


def segment_swing_pose_based(pose_data, detections=None, sample_rate=1, frame_shape=None, **kwargs):
    """Legacy function - use analyze_swing_dtl for new analysis"""
    from .segmentation import segment_swing
    return segment_swing(pose_data, detections, sample_rate, frame_shape, **kwargs)


def analyze_trajectory(frames, detections, swing_phases, sample_rate=1, fps=30.0):
    """
    Simple trajectory analysis - just track ball movement after impact
    
    Args:
        frames: Video frames
        detections: Ball detections
        swing_phases: Swing phase data
        sample_rate: Frame sampling rate
        fps: Actual video FPS
    """
    trajectory_data = {}
    
    # Simple phase assignment without complex calculations
    for phase_name, frames_in_phase in swing_phases.items():
        # Skip non-phase keys like timing_unreliable
        if not isinstance(frames_in_phase, list):
            continue
        for frame_idx in frames_in_phase:
            trajectory_data[frame_idx] = {
                "phase": phase_name,
                "ball_detected": False
            }

    # Mark frames where ball is detected
    ball_detections = [d for d in detections if d.class_name == "sports ball"]
    for detection in ball_detections:
        frame_idx = to_processed_idx(detection.frame_idx, sample_rate)
        if frame_idx in trajectory_data:
            trajectory_data[frame_idx]["ball_detected"] = True

    return trajectory_data