carla_stereo_sample / data_io.py
wyddmw's picture
add carla sampled data
4636307
raw
history blame
1.72 kB
import numpy as np
import cv2
import os
class CarlaDataset(object):
def __init__(self, data_root='/data3/Carla_stereo'):
pass
self.data_root = data_root
fov = 90 # default setting for carla
self.height = 1080
self.width = 1920
self.focal_length = self.width / (2.0 * np.tan(fov * np.pi / 360.0))
self.baseline_left_to_right = 2.0 # in terms of meter
self.baseline_left_to_middle = 1.0
self.baseline_right_to_middle = 1.0
self.loc_idx = ['Middle', 'Left', 'Right']
self.sensor_idx = ['NormalizedDepth', 'RawDepth', 'RGB']
self.data_dict = {}
def read_data(self):
for loc in self.loc_idx:
for sensor in self.sensor_idx:
sensor_name = f'{loc}_{sensor}'
sensor_data = os.listdir(os.path.join(self.data_root, sensor_name))
self.data_dict['sensor_name'] = sensor_data
def get_intrinsics(self, fov, h, w):
pass
def read_depth(self, raw_depth, norm_depth):
'''
raw_depth: [H, W, 3] in RGB format
'''
depth = cv2.imread(raw_depth)
import pdb; pdb.set_trace()
depth_value = (depth[..., 0] + depth[..., 1] * 256 + depth[..., 2] * (256**2)) / (256**3 - 1)
norm_depth = cv2.imread(norm_depth)
valid_mask = norm_depth[..., 0] != 255
cv2.imwrite('./valid_mask.png', (valid_mask*255).astype(np.uint8))
return depth_value, valid_mask
if __name__ == '__main__':
carla_dataset = CarlaDataset()
raw_depth = 'Middle_RawDepth/000005.png'
norm_depth = 'Middle_NormalizedDepth/000005.png'
carla_dataset.read_depth(raw_depth, norm_depth)