Visualizes a sample from BEV with annotations and detection results. :param nusc: NuScenes object. :param sample_token: The nuScenes sample token. :param gt_boxes: Ground truth boxes grouped by sample. :param pred_boxes: Prediction grouped by sample. :param nsweeps: Number o
(nusc: NuScenes,
sample_token: str,
gt_boxes: EvalBoxes,
pred_boxes: EvalBoxes,
nsweeps: int = 1,
conf_th: float = 0.15,
eval_range: float = 50,
verbose: bool = True,
savepath: str = None)
| 25 | |
| 26 | |
| 27 | def visualize_sample(nusc: NuScenes, |
| 28 | sample_token: str, |
| 29 | gt_boxes: EvalBoxes, |
| 30 | pred_boxes: EvalBoxes, |
| 31 | nsweeps: int = 1, |
| 32 | conf_th: float = 0.15, |
| 33 | eval_range: float = 50, |
| 34 | verbose: bool = True, |
| 35 | savepath: str = None) -> None: |
| 36 | """ |
| 37 | Visualizes a sample from BEV with annotations and detection results. |
| 38 | :param nusc: NuScenes object. |
| 39 | :param sample_token: The nuScenes sample token. |
| 40 | :param gt_boxes: Ground truth boxes grouped by sample. |
| 41 | :param pred_boxes: Prediction grouped by sample. |
| 42 | :param nsweeps: Number of sweeps used for lidar visualization. |
| 43 | :param conf_th: The confidence threshold used to filter negatives. |
| 44 | :param eval_range: Range in meters beyond which boxes are ignored. |
| 45 | :param verbose: Whether to print to stdout. |
| 46 | :param savepath: If given, saves the the rendering here instead of displaying. |
| 47 | """ |
| 48 | # Retrieve sensor & pose records. |
| 49 | sample_rec = nusc.get('sample', sample_token) |
| 50 | sd_record = nusc.get('sample_data', sample_rec['data']['LIDAR_TOP']) |
| 51 | cs_record = nusc.get('calibrated_sensor', sd_record['calibrated_sensor_token']) |
| 52 | pose_record = nusc.get('ego_pose', sd_record['ego_pose_token']) |
| 53 | |
| 54 | # Get boxes. |
| 55 | boxes_gt_global = gt_boxes[sample_token] |
| 56 | boxes_est_global = pred_boxes[sample_token] |
| 57 | |
| 58 | # Map GT boxes to lidar. |
| 59 | boxes_gt = boxes_to_sensor(boxes_gt_global, pose_record, cs_record) |
| 60 | |
| 61 | # Map EST boxes to lidar. |
| 62 | boxes_est = boxes_to_sensor(boxes_est_global, pose_record, cs_record) |
| 63 | |
| 64 | # Add scores to EST boxes. |
| 65 | for box_est, box_est_global in zip(boxes_est, boxes_est_global): |
| 66 | box_est.score = box_est_global.detection_score |
| 67 | |
| 68 | # Get point cloud in lidar frame. |
| 69 | pc, _ = LidarPointCloud.from_file_multisweep(nusc, sample_rec, 'LIDAR_TOP', 'LIDAR_TOP', nsweeps=nsweeps) |
| 70 | |
| 71 | # Init axes. |
| 72 | _, ax = plt.subplots(1, 1, figsize=(9, 9)) |
| 73 | |
| 74 | # Show point cloud. |
| 75 | points = view_points(pc.points[:3, :], np.eye(4), normalize=False) |
| 76 | dists = np.sqrt(np.sum(pc.points[:2, :] ** 2, axis=0)) |
| 77 | colors = np.minimum(1, dists / eval_range) |
| 78 | ax.scatter(points[0, :], points[1, :], c=colors, s=0.2) |
| 79 | |
| 80 | # Show ego vehicle. |
| 81 | ax.plot(0, 0, 'x', color='black') |
| 82 | |
| 83 | # Show GT boxes. |
| 84 | for box in boxes_gt: |
nothing calls this directly
no test coverage detected