diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-01-09 23:12:19 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-01-09 23:12:19 +0100 |
| commit | 333a743e278dac3f0997bad1b6480ecbceb1d71c (patch) | |
| tree | 854c2b5ecedb0cf495526e96b1796a8674d76cb0 | |
| parent | fd022cafdc8a782e00bdb91fb2afb3f4d7893fec (diff) | |
uprez thirds
| -rw-r--r-- | crop-margin.py | 70 | ||||
| -rw-r--r-- | crop-moving.py | 3 | ||||
| -rw-r--r-- | crop-thirds.py | 22 | ||||
| -rw-r--r-- | uprez-thirds.py | 30 |
4 files changed, 104 insertions, 21 deletions
diff --git a/crop-margin.py b/crop-margin.py new file mode 100644 index 0000000..5183258 --- /dev/null +++ b/crop-margin.py @@ -0,0 +1,70 @@ +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") + +parser = argparse.ArgumentParser() +parser.add_argument('--folder', default="./uprez/venice_360_equi_1024/a/") +parser.add_argument('--out_dir', default="./uprez_results/") +parser.add_argument('--label', required=True) +parser.add_argument('--margin', type=int, default=16) +parser.add_argument('--no_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,) +y0 = opt.vertical_offset - dst_height / 2 - margin + +out_path = os.path.join(opt.out_dir, opt.label) + +if not opt.no_clobber: + if os.path.exists(out_path): + rmtree(out_path) + +for i in range(opt.count): + x = int(i / opt.count * dst_width) - margin + if x < 0: + x += dst_width + crops.append((x, y0, x + dst_width + margin + margin, y0 + dst_height + margin + margin,)) + path = os.path.join(out_path, chr(97 + i)) + os.makedirs(path) + paths.append(path) + +max_i = opt.max +dataset = [] +for i, fn in enumerate(sorted(glob.glob(os.path.join(opt.folder, '*.png')))): + if i >= max_i: + break + out_fn = "frame_{:05d}.png".format(i + 1) + if opt.no_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 + dst_width + margin), src_height,)) + image = Image.open(fn) + canvas.paste(image, (0, 0)) + canvas.paste(image, (src_width, 0)) + + 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) diff --git a/crop-moving.py b/crop-moving.py index 653dc72..2e895d1 100644 --- a/crop-moving.py +++ b/crop-moving.py @@ -60,7 +60,8 @@ for i in range(opt.count): if x < 0: x = 0 crops.append((x, y0, w, y0 + crop_height + y_margin + y_margin,)) - path = os.path.join(out_path, chr(97 + i)) + letter = chr(97 + i) + path = os.path.join(out_path, letter) os.makedirs(path) paths.append(path) diff --git a/crop-thirds.py b/crop-thirds.py index fddba9d..96653a3 100644 --- a/crop-thirds.py +++ b/crop-thirds.py @@ -60,7 +60,8 @@ for i in range(opt.count): if x < 0: x = 0 crops.append((x, y0, w, y0 + crop_height + y_margin + y_margin,)) - path = os.path.join(out_path, chr(97 + i)) + letter = chr(97 + i) + path = os.path.join(out_path, letter) os.makedirs(path) paths.append(path) @@ -87,22 +88,3 @@ def build_thumbnail(i, 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 -# ]) - diff --git a/uprez-thirds.py b/uprez-thirds.py new file mode 100644 index 0000000..ee22f26 --- /dev/null +++ b/uprez-thirds.py @@ -0,0 +1,30 @@ +import os +import subprocess + +datasets = "venice_nearby_building_201810131720 venice_short_alley_201810171907 venice_open_water_201810131823 venice_under_bridge_201810121631 venice_under_bridge_201810131715 smallbridgesvenice_full_sequence_20181014_201810171354 shortsanmarcodronevenice_by_drone_20181014_20181016_201810172111 canalegrandevenice_by_drone_20181014_201810301222 2sanmarcovenice_by_drone_20181030_201811020900".split(" ") + +for dataset in datasets: + folder = os.path.join('/media/lens/jules/results', dataset) + subprocess.call([ + '/home/lens/miniconda3/envs/py36/bin/python', + 'crop-thirds.py', + '--max', 750, + '--vertical_offset', '286', + '--crop_aspect', 1.5, + '--aspect', 3.0, + '--label', dataset, + '--folder', folder, + ]) + + subprocess.call([ + '/home/lens/miniconda3/envs/tf/bin/python', + 'test.py', + '--in_dir', folder + ]) + +subprocess.call([ + 'rsync', + '-a', + '/media/blue/uprez/renders/', + 'jules@lmno:asdf/neural/uprez/' +]) |
