def ImageGetData(rec_filename, topic): all_avg = [] ok_percent = [] res = dict() data = importRosbag(rec_filename, importTopics=[topic], log='ERROR', disable_bar=True)[topic] for pyimg in data['frames']: ok_number = (pyimg != 0).sum() ok_percent.append(float(ok_number) / (pyimg.shape[0] * pyimg.shape[1])) all_avg.append(pyimg.sum() / ok_number) all_avg = np.array(all_avg) channels = pyimg.shape[2] if len(pyimg.shape) > 2 else 1 res['num_channels'] = channels res['shape'] = pyimg.shape res['avg'] = all_avg.mean() res['ok_percent'] = { 'value': (np.array(ok_percent).mean()) / channels, 'epsilon': 0.01 } res['epsilon'] = max(all_avg.max() - res['avg'], res['avg'] - all_avg.min()) res['reported_size'] = [ pyimg.shape[1], pyimg.shape[0], pyimg.shape[1] * pyimg.dtype.itemsize * channels ] return res
def __getitem__(self, index): """ Returns: tuple of (data, target), where data is another tuple of (events, imu, images) and target is the opti track ground truth """ filename = os.path.join(self.location_on_system, self.selection[index] + ".bag") topics = importRosbag(filename, log="ERROR") events = topics["/dvs/events"] events["ts"] -= events["ts"][0] events["ts"] *= 1e6 events = np.column_stack( (events["ts"], events["x"], events["y"], events["pol"])) events = np.lib.recfunctions.unstructured_to_structured( events, self.dtype) if "/dvs/imu" in topics.keys(): imu = topics["/dvs/imu"] imu["ts"] = ((imu["ts"] - imu["ts"][0]) * 1e6).astype(int) else: imu = None images = topics["/dvs/image_raw"] images["frames"] = np.stack(images["frames"]) images["ts"] = ((images["ts"] - images["ts"][0]) * 1e6).astype(int) data = (events, imu, images) target = topics["/optitrack/davis"] target["ts"] = ((target["ts"] - target["ts"][0]) * 1e6).astype(int) if self.transform is not None: data = self.transform(data) if self.target_transform is not None: target = self.target_transform(target) return data, target
def rosbag_to_events(filename, topic='/dvs_right/events'): try: from importRosbag.importRosbag import importRosbag except ImportError as exc: print("This function requires the importRosbag library from https://github.com/event-driven-robotics") raise(exc) all_events = [] data = importRosbag(filename)[topic] data['ts'] -= data['ts'][0] # align at 0 data['ts'] *= 1000000. # second to microsecond return data
def ImuGetData(rec_filename, topic): # res['value'] = first value of topic. # res['max_diff'] = max difference between returned value and all other values of topic in recording. res = dict() res['value'] = None res['max_diff'] = [0,0,0] data = importRosbag(rec_filename, importTopics=[topic], log='ERROR', disable_bar=True)[topic] res['value'] = data['acc'][0,:] res['max_diff'] = data['acc'].max(0) - data['acc'].min(0) return res
def __getitem__(self, index): """ Returns: a tuple of (data, target) where data is another tuple of (events, imu, images) and target is gps positional data. """ (bag_filename, _), (gps_filename, _) = self.recordings[index] file_path = os.path.join(self.location_on_system, bag_filename) topics = importRosbag(filePathOrName=file_path, log="ERROR") events = topics["/dvs/events"] events["ts"] -= events["ts"][0] events["ts"] *= 1e6 events = np.column_stack( (events["ts"], events["x"], events["y"], events["pol"])) events = np.lib.recfunctions.unstructured_to_structured( events, self.dtype) imu = topics["/dvs/imu"] imu["ts"] = ((imu["ts"] - imu["ts"][0]) * 1e6).astype(int) images = topics["/dvs/image_raw"] incorrect_shape_indices = [ i for i, image in enumerate(images["frames"]) if not (image.shape[0] == 260 and image.shape[1] == 346) ] for index in incorrect_shape_indices: # fix frame shapes that don't match for some reason shape_diff_x = self.sensor_size[0] - images["frames"][index].shape[ 1] shape_diff_y = self.sensor_size[1] - images["frames"][index].shape[ 0] images["frames"][index] = np.pad(images["frames"][index], [(0, shape_diff_y), (0, shape_diff_x), (0, 0)]) images["frames"] = np.stack( images["frames"]) # errors for some recordings images["ts"] = ((images["ts"] - images["ts"][0]) * 1e6).astype(int) data = events, imu, images targets = self.read_gps_file( os.path.join(self.location_on_system, gps_filename)) if self.transform is not None: data = self.transform(data) if self.target_transform is not None: targets = self.target_transform(targets) return data, targets
def __getitem__(self, index): """ Returns: tuple of (data, targets), where data is another tuple of (events_left, events_right, imu_left, imu_right, images_left, images_right) and targets is a tuple of (depth_rect_left, depth_rect_right, pose) for ground truths. """ # decode data file filename = os.path.join( self.location_on_system, self.scene, self.resources[self.scene][index * 2][0], ) topics = importRosbag(filename, log="ERROR") events_left = topics["/davis/left/events"] events_left["ts"] -= events_left["ts"][0] events_left["ts"] *= 1e6 events_left = np.column_stack((events_left["x"], events_left["y"], events_left["ts"], events_left["pol"])) events_left = np.lib.recfunctions.unstructured_to_structured( events_left, self.dtype) events_right = topics["/davis/right/events"] events_right["ts"] -= events_right["ts"][0] events_right["ts"] *= 1e6 events_right = np.column_stack(( events_right["x"], events_right["y"], events_right["ts"], events_right["pol"], )) events_right = np.lib.recfunctions.unstructured_to_structured( events_right, self.dtype) imu_left = topics["/davis/left/imu"] imu_right = topics["/davis/right/imu"] images_left = topics["/davis/left/image_raw"] images_left = np.stack(images_left["frames"]) images_right = topics["/davis/right/image_raw"] images_right = np.stack(images_right["frames"]) data = events_left, events_right, imu_left, imu_right, images_left, images_right # decode ground truth file filename = os.path.join( self.location_on_system, self.scene, self.resources[self.scene][index * 2 + 1][0], ) topics = importRosbag(filename, log="ERROR") depth_left = topics["/davis/left/depth_image_raw"] depth_left = np.stack(depth_left["frames"]) depth_right = topics["/davis/right/depth_image_raw"] depth_right = np.stack(depth_right["frames"]) depth_rect_left = topics["/davis/left/depth_image_rect"] depth_rect_left = np.stack(depth_rect_left["frames"]) depth_rect_right = topics["/davis/right/depth_image_rect"] depth_rect_right = np.stack(depth_rect_right["frames"]) pose = topics["/davis/left/pose"] targets = depth_rect_left, depth_rect_right, pose if self.transform is not None: data = self.transform(data) if self.target_transform is not None: targets = self.transform(targets) return data, targets