This is a post-processing function on the bboxes from Mono-3D task. If we want to perform projection visualization, we need to: 1. rotate the box along x-axis for np.pi / 2 (roll) 2. change orientation from local yaw to global yaw 3. convert yaw by (np.pi / 2 - yaw)
(cam_box)
| 369 | |
| 370 | |
| 371 | def mono_cam_box2vis(cam_box): |
| 372 | """This is a post-processing function on the bboxes from Mono-3D task. If |
| 373 | we want to perform projection visualization, we need to: |
| 374 | |
| 375 | 1. rotate the box along x-axis for np.pi / 2 (roll) |
| 376 | 2. change orientation from local yaw to global yaw |
| 377 | 3. convert yaw by (np.pi / 2 - yaw) |
| 378 | |
| 379 | After applying this function, we can project and draw it on 2D images. |
| 380 | |
| 381 | Args: |
| 382 | cam_box (:obj:`CameraInstance3DBoxes`): 3D bbox in camera coordinate |
| 383 | system before conversion. Could be gt bbox loaded from dataset or |
| 384 | network prediction output. |
| 385 | |
| 386 | Returns: |
| 387 | :obj:`CameraInstance3DBoxes`: Box after conversion. |
| 388 | """ |
| 389 | warning.warn('DeprecationWarning: The hack of yaw and dimension in the ' |
| 390 | 'monocular 3D detection on nuScenes has been removed. The ' |
| 391 | 'function mono_cam_box2vis will be deprecated.') |
| 392 | from .cam_box3d import CameraInstance3DBoxes |
| 393 | assert isinstance(cam_box, CameraInstance3DBoxes), \ |
| 394 | 'input bbox should be CameraInstance3DBoxes!' |
| 395 | loc = cam_box.gravity_center |
| 396 | dim = cam_box.dims |
| 397 | yaw = cam_box.yaw |
| 398 | feats = cam_box.tensor[:, 7:] |
| 399 | # rotate along x-axis for np.pi / 2 |
| 400 | # see also here: https://github.com/open-mmlab/mmdetection3d/blob/master/mmdet3d/datasets/nuscenes_mono_dataset.py#L557 # noqa |
| 401 | dim[:, [1, 2]] = dim[:, [2, 1]] |
| 402 | # change local yaw to global yaw for visualization |
| 403 | # refer to https://github.com/open-mmlab/mmdetection3d/blob/master/mmdet3d/datasets/nuscenes_mono_dataset.py#L164-L166 # noqa |
| 404 | yaw += torch.atan2(loc[:, 0], loc[:, 2]) |
| 405 | # convert yaw by (-yaw - np.pi / 2) |
| 406 | # this is because mono 3D box class such as `NuScenesBox` has different |
| 407 | # definition of rotation with our `CameraInstance3DBoxes` |
| 408 | yaw = -yaw - np.pi / 2 |
| 409 | cam_box = torch.cat([loc, dim, yaw[:, None], feats], dim=1) |
| 410 | cam_box = CameraInstance3DBoxes(cam_box, |
| 411 | box_dim=cam_box.shape[-1], |
| 412 | origin=(0.5, 0.5, 0.5)) |
| 413 | |
| 414 | return cam_box |
| 415 | |
| 416 | |
| 417 | def get_proj_mat_by_coord_type(img_meta: dict, coord_type: str) -> Tensor: |