-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathold_compute_video_flow.py
40 lines (32 loc) · 1.25 KB
/
old_compute_video_flow.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
import glob
import os
from subprocess import call
from tqdm import trange
from flo2img import convert_wrapper
from shutil import copyfile
NAMEs = sorted(map(lambda x: x[-13:], glob.glob('/home/yclin/frame_skate/*')))[:25]
DEBUG = False
if __name__ == '__main__':
cnt = 1
for name in NAMEs:
print "{}, {} / {}".format(name, cnt, len(NAMEs))
path = '/home/yclin/frame_skate/' + name + '/'
n_frames = len(glob.glob(path + '*.jpg'))
print "Resizing images"
cmd = 'mogrify -resize 25% -format ppm {}*.jpg'.format(path)
call(cmd, shell=True)
print "Extracting optical flow"
for i in trange(1, n_frames+1):
if i == n_frames:
copyfile('{}{:06d}'.format(path, i-1), '{}{:06d}'.format(path, i))
continue
cmd = './of {}{:06d} {}{:06d}'.format(path, i, path, i+1)
call(cmd, shell=True)
output_path = '/home/yclin/of_skate/' + name + '/'
if not os.path.isdir(output_path):
os.mkdir(output_path)
convert_wrapper(path, output_path, DEBUG)
cmd = 'mogrify -resize 400% {}*.png'.format(output_path)
call(cmd, shell=True)
cmd = 'rm -rf {}*.ppm'.format(path)
call(cmd, shell=True)