def convert_depth_from_source_to_agent( self, source: carla.Image) -> Union[DepthData, None]: """Convert CARLA raw Image to a Union with Depth numpy array.""" try: array = np.frombuffer(source.raw_data, dtype=np.dtype("uint8")) array = np.reshape(array, (source.height, source.width, 4)) # BGRA array = array[:, :, :3] # BGR array = array[:, :, ::-1] # RGB array = png_to_depth(array) return DepthData(data=array) except: return None
def convert_depth_from_source_to_agent( self, source: carla.Image ) -> Union[DepthData, None]: """Convert CARLA raw depth info to """ try: array = np.frombuffer(source.raw_data, dtype=np.dtype("uint8")) array = np.reshape(array, (source.height, source.width, 4)) # BGRA array = array[:, :, :3] # BGR array = array[:, :, ::-1] # RGB # array = array.swapaxes(0, 1) array = png_to_depth(array) # print(array[350][160], array[350][688]) return DepthData(data=array) except: return None