Returns the data path as well as all annotations related to that sample_data. Note that the boxes are transformed into the current sensor's coordinate frame. :param sample_data_token: Sample_data token. :param box_vis_level: If sample_data is an image, this sets required visibility
(sample_data_token: str,
box_vis_level: BoxVisibility = BoxVisibility.ANY,
selected_anntokens=None,
use_flat_vehicle_coordinates: bool = False)
| 146 | |
| 147 | |
| 148 | def get_sample_data(sample_data_token: str, |
| 149 | box_vis_level: BoxVisibility = BoxVisibility.ANY, |
| 150 | selected_anntokens=None, |
| 151 | use_flat_vehicle_coordinates: bool = False): |
| 152 | """ |
| 153 | Returns the data path as well as all annotations related to that sample_data. |
| 154 | Note that the boxes are transformed into the current sensor's coordinate frame. |
| 155 | :param sample_data_token: Sample_data token. |
| 156 | :param box_vis_level: If sample_data is an image, this sets required visibility for boxes. |
| 157 | :param selected_anntokens: If provided only return the selected annotation. |
| 158 | :param use_flat_vehicle_coordinates: Instead of the current sensor's coordinate frame, use ego frame which is |
| 159 | aligned to z-plane in the world. |
| 160 | :return: (data_path, boxes, camera_intrinsic <np.array: 3, 3>) |
| 161 | """ |
| 162 | |
| 163 | # Retrieve sensor & pose records |
| 164 | sd_record = nusc.get('sample_data', sample_data_token) |
| 165 | cs_record = nusc.get('calibrated_sensor', sd_record['calibrated_sensor_token']) |
| 166 | sensor_record = nusc.get('sensor', cs_record['sensor_token']) |
| 167 | pose_record = nusc.get('ego_pose', sd_record['ego_pose_token']) |
| 168 | |
| 169 | data_path = nusc.get_sample_data_path(sample_data_token) |
| 170 | |
| 171 | if sensor_record['modality'] == 'camera': |
| 172 | cam_intrinsic = np.array(cs_record['camera_intrinsic']) |
| 173 | imsize = (sd_record['width'], sd_record['height']) |
| 174 | else: |
| 175 | cam_intrinsic = None |
| 176 | imsize = None |
| 177 | |
| 178 | # Retrieve all sample annotations and map to sensor coordinate system. |
| 179 | if selected_anntokens is not None: |
| 180 | boxes = list(map(nusc.get_box, selected_anntokens)) |
| 181 | else: |
| 182 | boxes = nusc.get_boxes(sample_data_token) |
| 183 | |
| 184 | # Make list of Box objects including coord system transforms. |
| 185 | box_list = [] |
| 186 | for box in boxes: |
| 187 | if use_flat_vehicle_coordinates: |
| 188 | # Move box to ego vehicle coord system parallel to world z plane. |
| 189 | yaw = Quaternion(pose_record['rotation']).yaw_pitch_roll[0] |
| 190 | box.translate(-np.array(pose_record['translation'])) |
| 191 | box.rotate(Quaternion(scalar=np.cos(yaw / 2), vector=[0, 0, np.sin(yaw / 2)]).inverse) |
| 192 | else: |
| 193 | # Move box to ego vehicle coord system. |
| 194 | box.translate(-np.array(pose_record['translation'])) |
| 195 | box.rotate(Quaternion(pose_record['rotation']).inverse) |
| 196 | |
| 197 | # Move box to sensor coord system. |
| 198 | box.translate(-np.array(cs_record['translation'])) |
| 199 | box.rotate(Quaternion(cs_record['rotation']).inverse) |
| 200 | |
| 201 | if sensor_record['modality'] == 'camera' and not \ |
| 202 | box_in_image(box, cam_intrinsic, imsize, vis_level=box_vis_level): |
| 203 | continue |
| 204 | |
| 205 | box_list.append(box) |
nothing calls this directly
no outgoing calls
no test coverage detected