-
Notifications
You must be signed in to change notification settings - Fork 10
/
downsize_skybox.py
71 lines (49 loc) · 2 KB
/
downsize_skybox.py
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
#!/usr/bin/env python3
''' Script for downsizing skybox images. '''
import os
import math
import cv2
import numpy as np
from multiprocessing import Pool
from depth_to_skybox import camera_parameters
NUM_WORKER_PROCESSES = 20
DOWNSIZED_WIDTH = 512
DOWNSIZED_HEIGHT = 512
# Constants
SKYBOX_WIDTH = 1024
SKYBOX_HEIGHT = 1024
base_dir = 'data/v1/scans'
skybox_template = '%s/%s/matterport_skybox_images/%s_skybox%d_sami.jpg'
skybox_small_template = '%s/%s/matterport_skybox_images/%s_skybox%d_small.jpg'
skybox_merge_template = '%s/%s/matterport_skybox_images/%s_skybox_small.jpg'
def downsizeWithMerge(scan):
# Load pano ids
intrinsics,_ = camera_parameters(scan)
pano_ids = list(set([item.split('_')[0] for item in intrinsics.keys()]))
print('Processing scan %s with %d panoramas' % (scan, len(pano_ids)))
for pano in pano_ids:
ims = []
for skybox_ix in range(6):
# Load and downsize skybox image
skybox = cv2.imread(skybox_template % (base_dir,scan,pano,skybox_ix))
ims.append(cv2.resize(skybox,(DOWNSIZED_WIDTH,DOWNSIZED_HEIGHT),interpolation=cv2.INTER_AREA))
# Save output
newimg = np.concatenate(ims, axis=1)
assert cv2.imwrite(skybox_merge_template % (base_dir,scan,pano), newimg)
def downsize(scan):
# Load pano ids
intrinsics,_ = camera_parameters(scan)
pano_ids = list(set([item.split('_')[0] for item in intrinsics.keys()]))
print('Processing scan %s with %d panoramas' % (scan, len(pano_ids)))
for pano in pano_ids:
for skybox_ix in range(6):
# Load and downsize skybox image
skybox = cv2.imread(skybox_template % (base_dir,scan,pano,skybox_ix))
newimg = cv2.resize(skybox,(DOWNSIZED_WIDTH,DOWNSIZED_HEIGHT),interpolation=cv2.INTER_AREA)
# Save output
assert cv2.imwrite(skybox_small_template % (base_dir,scan,pano,skybox_ix), newimg)
if __name__ == '__main__':
with open('connectivity/scans.txt') as f:
scans = [scan.strip() for scan in f.readlines()]
p = Pool(NUM_WORKER_PROCESSES)
p.map(downsizeWithMerge, scans)