summaryrefslogtreecommitdiff
path: root/crop-equirectangular.py
diff options
context:
space:
mode:
Diffstat (limited to 'crop-equirectangular.py')
-rw-r--r--crop-equirectangular.py66
1 files changed, 53 insertions, 13 deletions
diff --git a/crop-equirectangular.py b/crop-equirectangular.py
index 5927716..5222a59 100644
--- a/crop-equirectangular.py
+++ b/crop-equirectangular.py
@@ -3,6 +3,10 @@ import glob
import argparse
from shutil import rmtree
from PIL import Image
+from multiprocessing import Pool
+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")
@@ -10,9 +14,10 @@ from PIL import Image
# Setting a higher overlap means you can have taller vertical FOV.
parser = argparse.ArgumentParser()
-parser.add_argument('--folder', default="/media/ssd/sequences/venice_360/equi")
+parser.add_argument('--folder', default="./pix2pixhd/sequences/venice_360/equi")
parser.add_argument('--label', required=True)
parser.add_argument('--vertical_offset', type=int, default=983)
+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()
@@ -42,27 +47,39 @@ p0 = (x0, y0, x0 + crop_width, y0 + crop_height,)
p1 = (x1, y0, x1 + crop_width, y0 + crop_height,)
p2 = (x2, y0, x2 + crop_width, y0 + crop_height,)
-path_0 = os.path.join("sequences", opt.label + "_a")
-path_1 = os.path.join("sequences", opt.label + "_b")
-path_2 = os.path.join("sequences", opt.label + "_c")
+label_0 = opt.label + '_a'
+label_1 = opt.label + '_b'
+label_2 = opt.label + '_c'
-if os.path.exists(path_0):
- rmtree(path_0)
-if os.path.exists(path_1):
- rmtree(path_1)
-if os.path.exists(path_2):
- rmtree(path_2)
+labels = [label_0, label_1, label_2]
+
+path_0 = os.path.join("sequences", label_0)
+path_1 = os.path.join("sequences", label_1)
+path_2 = os.path.join("sequences", label_2)
+
+if opt.clobber:
+ if os.path.exists(path_0):
+ rmtree(path_0)
+ if os.path.exists(path_1):
+ rmtree(path_1)
+ if os.path.exists(path_2):
+ rmtree(path_2)
os.makedirs(path_0)
os.makedirs(path_1)
os.makedirs(path_2)
-for i, fn in enumerate(glob.glob(os.path.join(opt.folder, '*.png'))):
- if not opt.clobber and os.path.exists(path_0):
+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(path_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))
- out_fn = "frame_{:05d}.png".format(i + 1)
canvas = Image.new('RGB', (int(src_width * 3/2), src_height,))
image = Image.open(fn)
@@ -73,3 +90,26 @@ for i, fn in enumerate(glob.glob(os.path.join(opt.folder, '*.png'))):
canvas.crop(p1).resize((1024, 512,), Image.ANTIALIAS).save(os.path.join(path_1, out_fn))
canvas.crop(p2).resize((1024, 512,), Image.ANTIALIAS).save(os.path.join(path_2, out_fn))
+agents = multiprocessing.cpu_count()
+chunksize = 3
+with Pool(processes=agents) as pool:
+ pool.starmap(build_thumbnail, dataset, chunksize)
+
+if opt.folder_id > 0:
+ endpoint = os.getenv('API_REMOTE') + '/api/folder/{}/'.format(opt.folder_id)
+ 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
+ ])
+