从点云生成图像个人理解有很多种方式,可以虚拟相机的位置,然后就可以生成图像了,但是经常使用的可能就是看一下BEV的图,
我这里写了一个简单的函数,用于从pcd点云文件生成bev的图
def pcl2bev(pcl_path, ratio=10, width=80, height=120):
"""
pcl点云中的一般都是m的坐标,
ratio: 1m代表几个像素的意思.
比如width5m ,height,10m的一个范围
"""
img_width = int(ratio * width)
img_height = int(ratio * height)
img = np.zeros((img_height, img_width, 3))
pcd, pcl_points = read_pcd(pcl_path)
colors = np.asarray(pcd.colors) * 255
colors = colors.astype("uint8")
for i, pt in enumerate(pcl_points):
x, y, z = pt
u = int(x*ratio) - (- img_width//2)
v = int(y*ratio) - (- img_height//2)
if (u>=0 and u<= img_width-1) and (v>=0 and v<= img_height-1):
img[v,u] = colors[i]
img = np.flip(img, 0)
cv2.imwrite("pcl2bev.jpg", img.astype("uint8"))
这样写,容易理解。仅作参考.
下面是可视化,
原点云如图
俯视图看的点云如下
转成图片之后的结果如下
我这里是把激光雷达作为图片的中心点来考虑的。