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
|
import os
import glob
import argparse
from PIL import Image
# 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="/media/ssd/sequences/venice_360/equi")
parser.add_argument('--label', required=True)
parser.add_argument('--vertical_offset', type=int, default=983)
parser.add_argument('--overlap', type=float, default=0.5)
opt = parser.parse_args()
src_width = 4096
src_height = 2048
count = 3
output_aspect = 3
overall_aspect = count * output_aspect
overlapped_aspect = overall_aspect - count * opt.overlap
crop_width = src_width * output_aspect / overlapped_aspect
crop_height = crop_width / output_aspect
c0 = 7/6 * crop_width
c1 = 3/6 * crop_width
c2 = 5/6 * crop_width
x0 = c0 - crop_width / 2
x1 = c1 - crop_width / 2
x2 = c2 - crop_width / 2
y0 = opt.vertical_offset - crop_height / 2
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")
for i, fn in enumerate(glob.glob(os.path.join(opt.folder, '*.png'))):
fn = "frame_{:04d}.png".format(i)
canvas = Image.new('RGB', (src_width, int(src_height * 3/2),))
image = Image.open(fn)
canvas.paste(image, (0, 0))
canvas.paste(image, (src_width, 0))
canvas.crop(p0).resize((1024, 512,), Image.ANTIALIAS).save(os.path.join(path_0, fn))
canvas.crop(p1).resize((1024, 512,), Image.ANTIALIAS).save(os.path.join(path_1, fn))
canvas.crop(p2).resize((1024, 512,), Image.ANTIALIAS).save(os.path.join(path_2, fn))
|