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 read_depth(self, raw_depth, norm_depth): ''' raw_depth: path to raw_depth.png norm_depth: path to normalized_depth.png for valid mask ''' depth = np.load(raw_depth) 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, valid_mask if __name__ == '__main__': carla_dataset = CarlaDataset() raw_depth = 'Middle_RawDepth/000205.npy' norm_depth = 'Middle_NormalizedDepth/000205.png' carla_dataset.read_depth(raw_depth, norm_depth)