File size: 1,487 Bytes
77bf120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os
from pathlib import Path

def create_output_dirs(dirs):
    """Create necessary directories if they don't exist"""
    for dir_path in dirs:
        Path(dir_path).mkdir(parents=True, exist_ok=True)

def save_trajectory_json(data, output_path):
    """Save trajectory data to JSON file"""
    with open(output_path, 'w') as f:
        json.dump(data, f, indent=2)

def load_trajectory_json(file_path):
    """Load trajectory data from JSON file"""
    with open(file_path, 'r') as f:
        return json.load(f)

def validate_video_file(filename):
    """Check if file is a valid video format"""
    valid_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv']
    return any(filename.lower().endswith(ext) for ext in valid_extensions)

def format_time(seconds):
    """Convert seconds to MM:SS format"""
    mins = int(seconds // 60)
    secs = int(seconds % 60)
    return f"{mins:02d}:{secs:02d}"

def get_trajectory_stats(trajectories):
    """Calculate statistics for trajectories"""
    stats = {
        'total_objects': len(trajectories),
        'avg_points': 0,
        'max_points': 0,
        'min_points': float('inf')
    }
    
    if trajectories:
        point_counts = [len(t['points']) for t in trajectories]
        stats['avg_points'] = sum(point_counts) / len(point_counts)
        stats['max_points'] = max(point_counts)
        stats['min_points'] = min(point_counts)
    
    return stats