3D Detection: 3D Box和点云 快速可视化

阅读: 评论:0

3D Detection: 3D Box和点云 快速可视化

3D Detection: 3D Box和点云 快速可视化

3D检测,用于3D box,点云快速可视化,辅助debug和分析:
(Nuscenes,mmdet3d,OpenPCDet等适用)

注意:代码适用于多种模型,但是注意BEVDet系列和FCOS3D(front View)系列要选用不同的box转换。

3D box投影到bev可视化:

import matplotlib.pyplot as plt
import torchdef box3d2x0y0wh(boxes_3d):# BEVDet/CenterPointsimport numpy as npn = boxes_3d.shape[0]box2d = np.zeros((n,4))# 3dbox --> xywhbox2d[:,:2] = boxes_3d[:,:2]box2d[:,2] = boxes_3d[:,3]box2d[:,3] = boxes_3d[:,4] # 2xywh# # xyxy = np.ones_like(box2d)box2d[:,0] = box2d[:, 0] - box2d[:, 2] / 2 box2d[:,1] = box2d[:, 1] + box2d[:, 3] / 2 # NOTE: 左下角点return box2ddef box3d2x0y0wh_2(boxes_3d):# FCOS3D: front view--> BEVimport numpy as npn = boxes_3d.shape[0]box2d = np.zeros((n,4))# 3dbox --> xywh 左下角点box2d[:, 0] = boxes_3d[:, 0]box2d[:, 1] = boxes_3d[:, 2]box2d[:, 2] = boxes_3d[:, 4]box2d[:, 3] = boxes_3d[:, 5] # 2xywh# # xyxy = np.ones_like(box2d)box2d[:,0] = box2d[:, 0] - box2d[:, 2] / 2 box2d[:,1] = box2d[:, 1] + box2d[:, 3] / 2 # NOTEreturn box2d# 根据坐标作图
def draw_boxes(pred_boxes_3d, target_boxes_3d, path):# pred_boxes xywhimport matplotlib.pyplot as pltimport matplotlib.patches as patchespred_boxes = box3d2x0y0wh(pred_boxes_3d)target_boxes = box3d2x0y0wh(target_boxes_3d)fig, ax = plt.subplots()ax.plot()# ax.add_patch(patches.Rectangle((1, 1),0.5,0.5,edgecolor = 'blue',facecolor = 'red',fill=True) )#for index, coord in enumerate(pred_boxes):rect = patches.Rectangle((coord[0], coord[1]), coord[2], coord[3], linewidth=1, edgecolor='r',facecolor='none')ax.add_patch(rect)for index, coord in enumerate(target_boxes):rect = patches.Rectangle((coord[0], coord[1]), coord[2], coord[3], linewidth=1, edgecolor='g',facecolor='none')ax.add_patch(rect)# plt.legend(loc='best',edgecolor='g')if ists(path):os.remove(path)fig.savefig(path, dpi=90, bbox_inches='tight')# print(0)plt.close(fig)print('Successfully saved')

点云快速可视化:

def draw_pts(points, save_path, show=False):'''points: [N,3+c]'''assert len(points.shape) == 2if isinstance(points, torch.Tensor):points = points.cpu().numpy()points = py()fig = plt.figure()ax = fig.add_subplot(111, projection='3d')# point_range = range(0, points.shape[0], skip) # skip points to prevent crashpoint_range = range(0, points.shape[0])ax.scatter(points[point_range, 0],   # xpoints[point_range, 1],   # ypoints[point_range, 2],   # zc=points[point_range, 2], # height data for colorcmap&#_cmap("Spectral"),marker="x")ax.axis('auto')  # {equal, scaled}if show:plt.show()if save_path is not None:fig.savefig(save_path, dpi=90, bbox_inches='tight')plt.close(fig)

本文发布于:2024-02-04 09:17:56,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170703922454302.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:快速   Detection   Box
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23