|
|
from PIL import Image |
|
|
import numpy as np |
|
|
import cv2 |
|
|
import json |
|
|
|
|
|
|
|
|
split = "train" |
|
|
|
|
|
|
|
|
sample = 123 |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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) |