Download synthetic_dataset/read_data.py from jacoblin/cloud-stereo: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/datasets/jacoblin/cloud-stereo/resolve/main/synthetic_dataset/read_data.py
- Command line
-
hf download hf://datasets/jacoblin/cloud-stereo/synthetic_dataset/read_data.py
-
curl -L -o read_data.py https://huggingface.co/datasets/jacoblin/cloud-stereo/resolve/main/synthetic_dataset/read_data.py
1.61 kB
| 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) |