@@ -777,37 +777,38 @@ def render_sample_data(self,
777
777
778
778
if sensor_modality in ['lidar' , 'radar' ]:
779
779
sample_rec = self .nusc .get ('sample' , sd_record ['sample_token' ])
780
- lidar_token = sample_rec ['data' ]['LIDAR_TOP' ]
781
780
chan = sd_record ['channel' ]
782
781
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 )
783
784
784
785
if sensor_modality == 'lidar' :
785
786
# Get aggregated lidar point cloud in lidar frame.
786
787
pc , times = LidarPointCloud .from_file_multisweep (self .nusc , sample_rec , chan , ref_chan , nsweeps = nsweeps )
788
+ velocities = None
787
789
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.
790
792
pc , times = RadarPointCloud .from_file_multisweep (self .nusc , sample_rec , chan , ref_chan , nsweeps = nsweeps )
791
793
792
794
# Transform radar velocities (x is front, y is left), as these are not transformed when loading the
793
795
# point cloud.
794
796
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' ])
797
798
velocities = pc .points [8 :10 , :] # Compensated velocity
798
799
velocities = np .vstack ((velocities , np .zeros (pc .points .shape [1 ])))
799
800
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 )
801
802
velocities [2 , :] = np .zeros (pc .points .shape [1 ])
802
803
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.
805
806
# Using use_flat_vehicle_coordinates we can render the map in the ego frame instead.
806
807
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' ],
811
812
rotation = Quaternion (cs_record ["rotation" ]))
812
813
813
814
# Compute rotation between 3D vehicle pose and "flat" vehicle pose (parallel to global z plane).
@@ -817,7 +818,7 @@ def render_sample_data(self,
817
818
Quaternion (pose_record ['rotation' ]).inverse .rotation_matrix )
818
819
vehicle_flat_from_vehicle = np .eye (4 )
819
820
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 )
821
822
else :
822
823
viewpoint = np .eye (4 )
823
824
@@ -853,7 +854,7 @@ def render_sample_data(self,
853
854
ax .plot (0 , 0 , 'x' , color = 'red' )
854
855
855
856
# 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 ,
857
858
use_flat_vehicle_coordinates = use_flat_vehicle_coordinates )
858
859
859
860
# Show boxes.
0 commit comments