Spaces:
Runtime error
Runtime error
| 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 |