-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages_to_animation
79 lines (60 loc) · 2.19 KB
/
images_to_animation
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from smart_converter import SmartConverter
from fill_converter import FillConverter
import configparser
import os
import numpy as np
from os import path
import multiprocessing as mp
results = []
def process_file(converter, dirname, filename, time):
print("Processing file: %s" % filename)
image_path = path.join(dirname, filename)
slidercode = converter.convert(image_path, time, np.array((0, 0)))
return time, slidercode
def collect_code(result):
global results
if result[1] is not None:
results.append(result)
def main():
dir_name = "images/bad_apple"
t_start = -66
t_step = 40 * 1.5 # DT
config = configparser.ConfigParser()
config.read('config_animation.ini')
# Get all the frames from a directory
filelist = os.listdir(dir_name)
for fichier in filelist[:]: # filelist[:] makes a copy of filelist.
if not (fichier.endswith(".bmp") or fichier.endswith(".png") or fichier.endswith(".jpg")):
filelist.remove(fichier)
filelist.sort(key=lambda f: int(''.join(filter(str.isdigit, f))))
# Get a thread pool for the multi-processing
pool = mp.Pool(mp.cpu_count())
# Use loop to parallelize
for i, fn in enumerate(filelist):
t = t_start + i * t_step
# Animate in 2's
if i % 2 != 0:
continue
pool.apply_async(process_file, args=(FillConverter(config), dir_name, fn, t), callback=collect_code)
pool.close()
pool.join() # postpones the execution of next line of code until all processes in the queue are done.
# Sort results
results.sort(key=lambda x: x[0])
codes = [r for i, r in results]
# Single processor code
# last_time = t_start
# converter = SmartConverter2(config)
# for fn in filelist:
# print("Processing file: %s" % fn)
# image_path = path.join(dir_name, fn)
#
# slidercode = converter.convert(image_path, last_time, np.array((0, 0)))
# last_time += t_step
# if slidercode is not None:
# codes.append(slidercode)
with open("output.txt", "w+") as f:
f.writelines(codes)
print("Done!")
# input("Press enter to continue...")
if __name__ == "__main__":
main()