forked from ZAP-FYP/YOLOPv2-1D_Coordinates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe_to_image.py
35 lines (27 loc) · 1.04 KB
/
frame_to_image.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
import numpy as np
import matplotlib.pyplot as plt
import os
def visualize_and_save_frames(coordinates_file, output_folder):
# Load coordinates from .npy file
coordinates = np.load(coordinates_file)
# Create output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)
# Visualize each set of coordinates and save as plots
for i, coords in enumerate(coordinates):
# Create an array of indices
indices = np.arange(len(coords))
# Plot index vs. value graph
plt.plot(indices, coords)
plt.xlabel('Index')
plt.ylabel('Value')
plt.title(f'Plot {i}')
plt.grid(True)
# Save the plot as an image
plt.savefig(os.path.join(output_folder, f'plot_{i}.png'))
# Clear the current plot to prepare for the next one
plt.clf()
# Example usage:
coordinates_file = 'train_data/00225f53-4200bde2_2.npy'
output_folder = 'output_folder'
# Visualize each set of coordinates and save as plots
visualize_and_save_frames(coordinates_file, output_folder)