-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmeta_file_processing.py
55 lines (46 loc) · 2.3 KB
/
meta_file_processing.py
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
53
54
55
import numpy as np
# Initialize dictionaries and counters for tracking frame differences and lost frames
frame_diff_counts = {}
previous_frame_number = None
previous_frame_line = None
total_frames = 0
frames_lost = 0
first_timestamp = None
last_timestamp = None
# Open and read the metadata file generated by the frame capture script
with open("frames_meta_20240101_010101.txt", "r") as meta_file:
for line in meta_file:
# Extract frame number and timestamp from the line
frame_number, timestamp, _, _ = map(float, line.strip().split())
# Record the first and last timestamps for FPS calculation
if first_timestamp is None:
first_timestamp = timestamp
last_timestamp = timestamp
# Increment the total frame count
total_frames += 1
# Calculate the difference between consecutive frame numbers
if previous_frame_number is not None:
frame_diff = int(frame_number - previous_frame_number)
frame_diff_counts[frame_diff] = frame_diff_counts.get(frame_diff, 0) + 1
# If frames were lost (gap in frame numbers), increment the lost frames counter
if frame_diff > 1:
frames_lost += frame_diff - 1
print("Fields in the following lines represent: Frame Number, Timestamp, Delta First, Delta Previous")
print(previous_frame_line.strip())
print(line.strip())
print()
# Update the previous frame variables for the next iteration
previous_frame_number = frame_number
previous_frame_line = line
# Display a summary of frame differences and their frequencies
print("Difference between frame numbers | Percentage of instances")
print("----------------------------------+-----------------------")
total_frame_diffs = sum(frame_diff_counts.values())
for frame_diff, count in sorted(frame_diff_counts.items()):
percentage = (count / total_frame_diffs) * 100
print(f"{frame_diff:<32}| {percentage:<22}")
# Calculate the effective FPS based on the time span between the first and last frames
effective_fps = total_frames / ((last_timestamp - first_timestamp) / 1000)
print(f"\nEffective FPS: {effective_fps}")
print(f"\nTotal number of frames collected: {total_frames}")
print(f"\nNumber of frames lost: {frames_lost}")