forked from thornewolf-academic/cfc-simulation-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages_to_video.py
53 lines (48 loc) · 1.54 KB
/
images_to_video.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
import cv2
import numpy as np
import glob
import os
import logging
def images_to_video(base_name: str):
'''
Takes a set of images generated by the visualization code to make a video
in .avi format. Saves to current working directory.
Args:
base_name: the base name of the run that was used to generate the images originally.
Returns:
None:
'''
logger = logging.getLogger(f'AutomateSims.images_to_video.{base_name}')
img_array = []
root = os.getcwd()
matching_files = glob.glob(f'{base_name}*.jpg')
logger.info(f'Found {len(matching_files)} files corresponding to {base_name}.\n e.g. {matching_files[:1]}')
matching_file_numbers = [int(f.split('_')[-1].replace('.jpg','')) for f in matching_files]
ordered_files = sorted(zip(matching_file_numbers, matching_files))
for i,filename in ordered_files:
print(i, filename)
path = os.path.join(root,filename)
img = cv2.imread(path)
print(path)
height, width, layers = img.shape
size = (width,height)
img_array.append(img)
out = cv2.VideoWriter(f'{base_name}.avi',
cv2.VideoWriter_fourcc(*'MJPG'),
15,
size)
for i in range(len(img_array)):
out.write(img_array[i])
print(out)
out.release()
<<<<<<< HEAD
if __name__ == '__main__':
name = 'Run41_JetA0p01_JetF0p1'
images_to_video(name)
=======
def main():
base_name = "R14JetAmp0p01Freq0p06"
images_to_video(base_name)
if __name__ == '__main__':
main()
>>>>>>> 003b8617f3568abfab6bab291c24d274279e6b41