当前位置:网站首页>3D Detection: 3D Box和点云 快速可视化
3D Detection: 3D Box和点云 快速可视化
2022-07-07 11:56:00 【烤粽子】
3D检测,用于3D box,点云快速可视化,辅助debug和分析:
(Nuscenes,mmdet3d,OpenPCDet等适用)
注意:代码适用于多种模型,但是注意BEVDet系列和FCOS3D(front View)系列要选用不同的box转换。
3D box投影到bev可视化:
import matplotlib.pyplot as plt
import torch
def box3d2x0y0wh(boxes_3d):
# BEVDet/CenterPoints
import numpy as np
n = boxes_3d.shape[0]
box2d = np.zeros((n,4))
# 3dbox --> xywh
box2d[:,: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 box2d
def box3d2x0y0wh_2(boxes_3d):
# FCOS3D: front view--> BEV
import numpy as np
n = 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 # NOTE
return box2d
# 根据坐标作图
def draw_boxes(pred_boxes_3d, target_boxes_3d, path):
# pred_boxes xywh
import matplotlib.pyplot as plt
import matplotlib.patches as patches
pred_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 os.path.exists(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) == 2
if isinstance(points, torch.Tensor):
points = points.cpu().numpy()
points = points.copy()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# point_range = range(0, points.shape[0], skip) # skip points to prevent crash
point_range = range(0, points.shape[0])
ax.scatter(points[point_range, 0], # x
points[point_range, 1], # y
points[point_range, 2], # z
c=points[point_range, 2], # height data for color
cmap=plt.get_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)
边栏推荐
- Deep understanding of array related problems in C language
- Navicat run SQL file import data incomplete or import failed
- LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
- 提升树莓派性能的方法
- Leetcode simple question sharing (20)
- Data refresh of recyclerview
- 2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
- Ways to improve the performance of raspberry pie
- [daily training -- Tencent select 50] 231 Power of 2
- ES日志报错赏析-Limit of total fields
猜你喜欢
Evolution of customer service hotline of dewu
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
Esp32 construction engineering add components
How to make join run faster?
The delivery efficiency is increased by 52 times, and the operation efficiency is increased by 10 times. See the compilation of practical cases of financial cloud native technology (with download)
Getting started with MySQL
flask session伪造之hctf admin
实现IP地址归属地显示功能、号码归属地查询
2022-7-6 使用SIGURG来接受外带数据,不知道为什么打印不出来
Esp32 ① compilation environment
随机推荐
Dry goods | summarize the linkage use of those vulnerability tools
[daily training] 648 Word replacement
Getting started with MySQL
Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
toRaw和markRaw
PHP - laravel cache
Learning breakout 2 - about effective learning methods
2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
Laravel5 call to undefined function openssl cipher iv length() 报错 PHP7开启OpenSSL扩展失败
Introduction and basic use of stored procedures
Show the mathematical formula in El table
Write it down once Net a new energy system thread surge analysis
Solve the cache breakdown problem
内存溢出和内存泄漏的区别
Enregistrement de la navigation et de la mise en service du robot ROS intérieur (expérience de sélection du rayon de dilatation)
2022-7-7 Leetcode 844.比较含退格的字符串
[dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
2022-7-6 beginner redis (I) download, install and run redis under Linux
室内ROS机器人导航调试记录(膨胀半径的选取经验)