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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
import os
import glob
import argparse
from shutil import rmtree
from PIL import Image
from multiprocessing import Pool, cpu_count
from dotenv import load_dotenv, find_dotenv
import subprocess
load_dotenv(find_dotenv())
# This script generates crops with a specific aspect ratio from a 360 video.
# It creates three sequences (identified by "--label")
# The default is a 24 degree overlap (equivalent to 1/6 of the 3:1 output image)
# Setting a higher overlap means you can have taller vertical FOV.
parser = argparse.ArgumentParser()
parser.add_argument('--folder', default="./results/wood/")
parser.add_argument('--out_dir', default="./thirds/")
parser.add_argument('--label', required=True)
parser.add_argument('--vertical_offset', type=int, default=512)
# parser.add_argument('--dst_width', type=int, default=1024)
# parser.add_argument('--dst_height', type=int, default=512)
parser.add_argument('--count', type=int, default=3)
parser.add_argument('--aspect', type=float, default=3.0)
# parser.add_argument('--folder_id', type=int, required=True)
parser.add_argument('--overlap', type=float, default=0.5)
parser.add_argument('--clobber', action='store_false')
opt = parser.parse_args()
src_width = 1024
src_height = 512
dst_width = int(src_width / opt.count)
dst_height = int(dst_width / opt.aspect)
dst_size = (dst_width, dst_height,)
crops = []
paths = []
for i in range(opt.count):
x = int(i / opt.count * dst_width)
crops.append((x, y0, x + dst_width, y0 + dst_height,))
paths.append(os.path.join(opt.out_dir, opt.label, chr(97 + i)))
y0 = opt.vertical_offset - dst_height / 2
for path in paths:
if opt.clobber:
if os.path.exists(path):
rmtree(path)
os.makedirs(path)
dataset = []
for i, fn in enumerate(sorted(glob.glob(os.path.join(opt.folder, '*.png')))):
out_fn = "frame_{:05d}.png".format(i + 1)
if not opt.clobber and os.path.exists(os.path.join(paths[0], out_fn)):
continue
dataset.append((i, fn,))
def build_thumbnail(i, fn):
out_fn = "frame_{:05d}.png".format(i + 1)
if (i % 100) == 0:
print("{}...".format(i))
canvas = Image.new('RGB', (int(src_width), src_height,))
image = Image.open(fn)
for n, path in enumerate(paths):
image.crop(crops[n]).save(os.path.join(path, out_fn))
chunksize = 3
with Pool(processes=cpu_count()) as pool:
pool.starmap(build_thumbnail, dataset, chunksize)
# if opt.folder_id > 0:
# endpoint = os.getenv('API_REMOTE') + '/api/file/'
# for label in labels:
# subprocess.call([
# "curl",
# "-X", "POST",
# "-d", "folder_id={}".format(opt.folder_id),
# "-d", "module=pix2pixhd",
# "-d", "name={}.mov".format(label),
# "-d", "url=https://s3.amazonaws.com/i.asdf.us/cortex/lens/data/{}/{}.mov".format(opt.folder_id, label),
# "-d", "dataset={}".format(label),
# "-d", "activity=splice",
# "-d", "generated=0",
# "-d", "processed=1",
# "-d", "datatype=video",
# endpoint
# ])
|