将.pcd文件可视化为鸟瞰图(俯视图)
程序员文章站
2022-07-14 21:15:05
...
首先,你可以用pcl库中的 pcl_viewer
3D可视化 .pcd
文件。
在做3D检测的时候可能需要用到鸟瞰图来检查效果,所以写了这么个功能:
这里需要注意的 .pcd
不能为二进制文件,否则不能直接读取。
import numpy as np
import cv2
def lidar_to_bird_view_img(lidar, factor=4):
# Input:
# lidar: (N', 4)
# factor: 越大清晰度越高
# Output:
# birdview: (w, l, 3)
birdview = np.zeros(
(INPUT_HEIGHT * factor, INPUT_WIDTH * factor, 1))
for point in lidar:
x, y = point[0:2]
if X_MIN < x < X_MAX and Y_MIN < y < Y_MAX:
x, y = int((x - X_MIN) / VOXEL_X_SIZE *
factor), int((y - Y_MIN) / VOXEL_Y_SIZE * factor)
birdview[y, x] += 1
birdview = birdview - np.min(birdview)
divisor = np.max(birdview) - np.min(birdview)
# TODO: adjust this factor
birdview = np.clip((birdview / divisor * 255) *
5 * factor, a_min=0, a_max=255)
birdview = np.tile(birdview, 3).astype(np.uint8)
return birdview
# 限定可视化范围
INPUT_HEIGHT = 400
INPUT_WIDTH = 352
X_MIN = 0
X_MAX = 70.4
Y_MIN = -40
Y_MAX = 40
VOXEL_X_SIZE = 0.2
VOXEL_Y_SIZE = 0.2
lidar = []
with open('000000.pcd','r') as f:
line = f.readline().strip()
while line:
linestr = line.split(" ")
if len(linestr) == 4:
# 将str类型转换为float类型
linestr_convert = list(map(float, linestr))
lidar.append(linestr_convert)
line = f.readline().strip()
bird_view = lidar_to_bird_view_img(lidar)
bird_view_path = '000000.jpg'
cv2.imwrite( bird_view_path, bird_view )
显示效果如下:
上一篇: R语言 数据处理 ARIMA预测
下一篇: Pycharm配置Flask无法启动,报No module named flask.__main__; ‘flask‘ is a package and cannot be direct
推荐阅读