def get_number_of_radar_pc_dimensions() -> int: """ Returns the number of dimensions of the nuScenes radar point cloud data. The number of dimensions of the radar point cloud is equal to the number of radar sensor channels. """ return RadarPointCloud.nbr_dims()
def load_image(self, image_index): """ Returns the image plus from given image and radar samples. It takes the requested channels into account. :param sample_token: [str] the token pointing to a certain sample :returns: imageplus """ # Initialize local variables radar_name = self.radar_sensors[0] camera_name = self.camera_sensors[0] # Gettign data from nuscenes database sample_token = self.sample_tokens[image_index] sample = self.nusc.get('sample', sample_token) # Grab the front camera and the radar sensor. radar_token = sample['data'][radar_name] camera_token = sample['data'][camera_name] image_target_shape = (self.image_min_side, self.image_max_side) # Load the image image_sample = self.load_sample_data(sample, camera_name) # Add noise to the image if enabled if self.noisy_image_method is not None and self.noise_factor > 0: image_sample = noisy(self.noisy_image_method, image_sample, self.noise_factor) if self._is_image_plus_enabled() or self.camera_dropout > 0.0: # Parameters kwargs = { 'pointsensor_token': radar_token, 'camera_token': camera_token, 'height': (0, self.radar_projection_height), 'image_target_shape': image_target_shape, 'clear_radar': np.random.rand() < self.radar_dropout, 'clear_image': np.random.rand() < self.camera_dropout, } # Create image plus # radar_sample = self.load_sample_data(sample, radar_name) # Load samples from disk # Get filepath if self.noise_filter: required_sweep_count = self.n_sweeps + self.noise_filter.num_sweeps_required - 1 else: required_sweep_count = self.n_sweeps # sd_rec = self.nusc.get('sample_data', sample['data'][sensor_channel]) sensor_channel = radar_name pcs, times = RadarPointCloud.from_file_multisweep(self.nusc, sample, sensor_channel, \ sensor_channel, nsweeps=required_sweep_count, min_distance=0.0, merge=False) if self.noise_filter: # fill up with zero sweeps for _ in range(required_sweep_count - len(pcs)): pcs.insert( 0, RadarPointCloud( np.zeros(shape=(RadarPointCloud.nbr_dims(), 0)))) radar_sample = [radar.enrich_radar_data(pc.points) for pc in pcs] if self.noise_filter: ##### Filter the pcs ##### radar_sample = list( self.noise_filter.denoise(radar_sample, self.n_sweeps)) if len(radar_sample) == 0: radar_sample = np.zeros(shape=(len(radar.channel_map), 0)) else: ##### merge pcs into single radar samples array ##### radar_sample = np.concatenate(radar_sample, axis=-1) radar_sample = radar_sample.astype(dtype=np.float32) if self.perfect_noise_filter: cartesian_uncertainty = 0.5 # meters angular_uncertainty = math.radians(1.7) # degree category_selection = self.noise_category_selection nusc_sample_data = self.nusc.get('sample_data', radar_token) radar_gt_mask = calc_mask(nusc=self.nusc, nusc_sample_data=nusc_sample_data, points3d=radar_sample[0:3,:], \ tolerance=cartesian_uncertainty, angle_tolerance=angular_uncertainty, \ category_selection=category_selection) # radar_sample = radar_sample[:, radar_gt_mask.astype(np.bool)] radar_sample = np.compress(radar_gt_mask, radar_sample, axis=-1) if self.normalize_radar: # we need to noramlize # : use preprocess method analog to image preprocessing sigma_factor = int(self.normalize_radar) for ch in range( 3, radar_sample.shape[0] ): # neural fusion requires x y and z to be not normalized norm_interval = ( -127.5, 127.5 ) # caffee mode is default and has these norm interval for img radar_sample[ch, :] = radar.normalize( ch, radar_sample[ch, :], normalization_interval=norm_interval, sigma_factor=sigma_factor) img_p_full = self.image_plus_creation(self.nusc, image_data=image_sample, radar_data=radar_sample, **kwargs) # reduce to requested channels #self.channels = [ch - 1 for ch in self.channels] # Shift channels by 1, cause we have a weird convetion starting at 1 input_data = img_p_full[:, :, self.channels] else: # We are not in image_plus mode # Only resize, because in the other case this is contained in image_plus_creation input_data = cv2.resize(image_sample, image_target_shape[::-1]) return input_data