diff options
Diffstat (limited to 'crop-thirds.py')
| -rw-r--r-- | crop-thirds.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/crop-thirds.py b/crop-thirds.py index cd13768..e2809a2 100644 --- a/crop-thirds.py +++ b/crop-thirds.py @@ -10,8 +10,6 @@ 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/") @@ -24,7 +22,7 @@ parser.add_argument('--count', type=int, default=3) parser.add_argument('--max', type=int, default=99997) 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('--margin', type=int, default=16) parser.add_argument('--no_clobber', action='store_false') opt = parser.parse_args() @@ -34,7 +32,7 @@ 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 +y0 = opt.vertical_offset - dst_height / 2 - margin crops = [] paths = [] @@ -45,8 +43,10 @@ if not opt.no_clobber: rmtree(out_path) for i in range(opt.count): - x = int(i / opt.count * dst_width) - crops.append((x, y0, x + dst_width, y0 + dst_height,)) + 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) @@ -54,7 +54,7 @@ for i in range(opt.count): max_i = opt.max dataset = [] for i, fn in enumerate(sorted(glob.glob(os.path.join(opt.folder, '*.png')))): - if i > max_i: + 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)): @@ -66,8 +66,10 @@ def build_thumbnail(i, fn): if (i % 100) == 0: print("{}...".format(i)) - canvas = Image.new('RGB', (int(src_width), src_height,)) + 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)) |
