open-mmlab / mmdetection3d

OpenMMLab's next-generation platform for general 3D object detection.
https://mmdetection3d.readthedocs.io/en/latest/
Apache License 2.0
5.26k stars 1.53k forks source link

[BUG] Potential BUG in visualization of function 'draw_camera_bbox3d_on_img' #2414

Open YangHan-Morningstar opened 1 year ago

YangHan-Morningstar commented 1 year ago

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

master branch https://github.com/open-mmlab/mmdetection3d

Environment

fatal: not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). sys.platform: linux Python: 3.8.16 (default, Mar 2 2023, 03:21:46) [GCC 11.2.0] CUDA available: True GPU 0,1,2,3,4,5,6,7: NVIDIA GeForce RTX 3090 CUDA_HOME: /usr/local/cuda-11.1 NVCC: Cuda compilation tools, release 11.1, V11.1.74 GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 PyTorch: 1.9.0+cu111 PyTorch compiling details: PyTorch built with:

TorchVision: 0.10.0+cu111 OpenCV: 4.7.0 MMCV: 1.5.2 MMCV Compiler: GCC 7.3 MMCV CUDA Compiler: 11.1 MMDetection: 2.28.2 MMSegmentation: 0.30.0 MMDetection3D: 1.0.0rc6+ spconv2.0: False

Reproduces the problem - code sample

pred_lidar_ins_3dbbox = LiDARInstance3DBoxes(pred_bboxes) 

pred_bboxes_in_cam = Box3DMode.convert(
    box=pred_lidar_ins_3dbbox,
    src=Box3DMode.LIDAR,
    dst=Box3DMode.CAM,
    rt_mat=cam_extrinsics.T  # cam_extrinsics.T is lidar2cam
)

drawed_img = draw_camera_bbox3d_on_img(
    pred_bboxes_in_cam, img, cam_intrinsics, img_metas={}, color=(241, 101, 72), thickness=1
)

mmcv.imwrite(drawed_img, args.out_dir + '/nuscenes_showed_img_coor.png')

# cam_extrinsics.T is lidar2cam, cam_intrinsics is cam2img
drawed_img = draw_lidar_bbox3d_on_img(
    pred_lidar_ins_3dbbox, img, np.dot(cam_intrinsics, cam_extrinsics.T), {}, color=(241, 101, 72), thickness=1
)

mmcv.imwrite(drawed_img, args.out_dir + '/nuscenes_showed_lidar_coor.png')

Reproduces the problem - command or script

python dets_inference.py

Reproduces the problem - error message

when I visualize CameraInstance3DBoxes converted by function Box3DMode.convert from LiDARInstance3DBoxes, I get a wrong visualization

image

but when I directly visualize LiDARInstance3DBoxes, I get a correct visualization

image

then in order to find the bug, I change the code1 to code2

####### code1 ######## drawed_img = draw_camera_bbox3d_on_img( pred_bboxes_in_cam, img, cam_intrinsics, img_metas={}, color=(241, 101, 72), thickness=1 ) ####################

####### code2 ######## drawed_img = draw_camera_bbox3d_on_img( pred_lidar_ins_3dbbox, img, np.dot(cam_intrinsics, cam_extrinsics.T), img_metas={}, color=(241, 101, 72), thickness=1 ) ####################

in my opinion, the transform_matrix in code2 can directly transform the points from lidar coordinate into img coordinate, which is similar with the transformation in code1, and interestingly, I get a correct visualization too

image

so I think the BUG is in Box3DMode.convert or draw_camera_bbox3d_on_img, but I read the source code of Box3DMode.convert, the transformation in code is correct, so I think there are something wrong in draw_camera_bbox3d_on_img.

please help me solve this bug, thanks a lot!

Additional information

No response

sunjiahao1999 commented 1 year ago

You can follow the unit test scripts in tests/test_utils/test_box3d.py to find out bug. I guess this is because wrong rt_mat=cam_extrinsics.T