File size: 1,609 Bytes
5b09670
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from PIL import Image
import numpy as np
import cv2
import json

# Choose split (train/test)
split = "train" 

# Choose sample number
sample = 123

# ------ Camera Parameters ------ #
def get_camera_intrinsics(fov_degrees, resolution):
    fov_rads = fov_degrees * np.pi / 180
    left_focal_length = resolution / (np.tan(fov_rads / 2) * 2)
    right_focal_length = resolution / (np.tan(fov_rads / 2) * 2)

    left_intrinsic = np.array([[left_focal_length, 0.000000000000000000e+00, 256],
                                [0.000000000000000000e+00,left_focal_length, 256],
                                [0.000000000000000000e+00,0.000000000000000000e+00,1.000000000000000000e+00]])

    right_intrinsic = np.array([[right_focal_length, 0.000000000000000000e+00, 256],
                                [0.000000000000000000e+00,right_focal_length, 256],
                                [0.000000000000000000e+00,0.000000000000000000e+00,1.000000000000000000e+00]])
    
    return left_intrinsic, right_intrinsic

with open(f'{split}.json', 'r') as fp:
    meta = json.load(fp)
    
h, w = meta['h'], meta['w']
curr_frame = meta['frames'][sample]
fov_degrees = curr_frame['fov_x_y']

left_intrinsic, right_intrinsic = get_camera_intrinsics(fov_degrees, h)

# ---------- Load Data --------- #
left_img = np.array(Image.open(curr_frame['left_image_path']))
right_img = np.array(Image.open(curr_frame['right_image_path']))
disparity = cv2.imread(curr_frame['disparity_path'], cv2.IMREAD_UNCHANGED | cv2.IMREAD_ANYDEPTH)
opacity = cv2.imread(curr_frame['opacity_path'], cv2.IMREAD_UNCHANGED | cv2.IMREAD_ANYDEPTH)