Skip to content

Commit f25a166

Browse files
Fixed visualization bug where radar returns were not rotated (nutonomy#243)
* Fixed visualization bug where radar returns where not rotated * Renamed variable
1 parent f3594b9 commit f25a166

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

python-sdk/nuscenes/nuscenes.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -777,37 +777,38 @@ def render_sample_data(self,
777777

778778
if sensor_modality in ['lidar', 'radar']:
779779
sample_rec = self.nusc.get('sample', sd_record['sample_token'])
780-
lidar_token = sample_rec['data']['LIDAR_TOP']
781780
chan = sd_record['channel']
782781
ref_chan = 'LIDAR_TOP'
782+
ref_sd_token = sample_rec['data'][ref_chan]
783+
ref_sd_record = self.nusc.get('sample_data', ref_sd_token)
783784

784785
if sensor_modality == 'lidar':
785786
# Get aggregated lidar point cloud in lidar frame.
786787
pc, times = LidarPointCloud.from_file_multisweep(self.nusc, sample_rec, chan, ref_chan, nsweeps=nsweeps)
788+
velocities = None
787789
else:
788-
# Get aggregated radar point cloud in lidar frame.
789-
# The point cloud is transformed to the lidar frame for visualization purposes.
790+
# Get aggregated radar point cloud in reference frame.
791+
# The point cloud is transformed to the reference frame for visualization purposes.
790792
pc, times = RadarPointCloud.from_file_multisweep(self.nusc, sample_rec, chan, ref_chan, nsweeps=nsweeps)
791793

792794
# Transform radar velocities (x is front, y is left), as these are not transformed when loading the
793795
# point cloud.
794796
radar_cs_record = self.nusc.get('calibrated_sensor', sd_record['calibrated_sensor_token'])
795-
lidar_sd_record = self.nusc.get('sample_data', lidar_token)
796-
lidar_cs_record = self.nusc.get('calibrated_sensor', lidar_sd_record['calibrated_sensor_token'])
797+
ref_cs_record = self.nusc.get('calibrated_sensor', ref_sd_record['calibrated_sensor_token'])
797798
velocities = pc.points[8:10, :] # Compensated velocity
798799
velocities = np.vstack((velocities, np.zeros(pc.points.shape[1])))
799800
velocities = np.dot(Quaternion(radar_cs_record['rotation']).rotation_matrix, velocities)
800-
velocities = np.dot(Quaternion(lidar_cs_record['rotation']).rotation_matrix.T, velocities)
801+
velocities = np.dot(Quaternion(ref_cs_record['rotation']).rotation_matrix.T, velocities)
801802
velocities[2, :] = np.zeros(pc.points.shape[1])
802803

803-
# By default we render the sample_data top down in the lidar frame.
804-
# This is slightly inaccurate when rendering the map as the lidar frame may not be perfectly upright.
804+
# By default we render the sample_data top down in the sensor frame.
805+
# This is slightly inaccurate when rendering the map as the sensor frame may not be perfectly upright.
805806
# Using use_flat_vehicle_coordinates we can render the map in the ego frame instead.
806807
if use_flat_vehicle_coordinates:
807-
# Compute transformation matrices for lidar point cloud.
808-
cs_record = self.nusc.get('calibrated_sensor', sd_record['calibrated_sensor_token'])
809-
pose_record = self.nusc.get('ego_pose', sd_record['ego_pose_token'])
810-
lid_to_ego = transform_matrix(translation=cs_record['translation'],
808+
# Retrieve transformation matrices for reference point cloud.
809+
cs_record = self.nusc.get('calibrated_sensor', ref_sd_record['calibrated_sensor_token'])
810+
pose_record = self.nusc.get('ego_pose', ref_sd_record['ego_pose_token'])
811+
ref_to_ego = transform_matrix(translation=cs_record['translation'],
811812
rotation=Quaternion(cs_record["rotation"]))
812813

813814
# Compute rotation between 3D vehicle pose and "flat" vehicle pose (parallel to global z plane).
@@ -817,7 +818,7 @@ def render_sample_data(self,
817818
Quaternion(pose_record['rotation']).inverse.rotation_matrix)
818819
vehicle_flat_from_vehicle = np.eye(4)
819820
vehicle_flat_from_vehicle[:3, :3] = rotation_vehicle_flat_from_vehicle
820-
viewpoint = np.dot(vehicle_flat_from_vehicle, lid_to_ego)
821+
viewpoint = np.dot(vehicle_flat_from_vehicle, ref_to_ego)
821822
else:
822823
viewpoint = np.eye(4)
823824

@@ -853,7 +854,7 @@ def render_sample_data(self,
853854
ax.plot(0, 0, 'x', color='red')
854855

855856
# Get boxes in lidar frame.
856-
_, boxes, _ = self.nusc.get_sample_data(lidar_token, box_vis_level=box_vis_level,
857+
_, boxes, _ = self.nusc.get_sample_data(ref_sd_token, box_vis_level=box_vis_level,
857858
use_flat_vehicle_coordinates=use_flat_vehicle_coordinates)
858859

859860
# Show boxes.

0 commit comments

Comments
 (0)