根据点云高度赋色(附open3d python代码)

绘制点云图时用颜色来表征其高度,
我们先计算了点云的高度范围,然后把每个点的颜色根据高度来进行映射
稍微修改代码,我们也可以让高度颜色渐变转换为 X 轴距离颜色渐变:

根据点云高度赋色(附open3d python代码)_第1张图片

稍微修改代码,我们也可以让高度颜色渐变转换为 X 轴距离颜色渐变:

 根据点云高度赋色(附open3d python代码)_第2张图片


# coding:utf-8
import numpy as np
import open3d as o3d

cloud = o3d.io.read_point_cloud("kitti_p.pcd")
pts = np.asarray(cloud.points)

# 根据高度生成色彩
colors = np.zeros([pts.shape[0], 3])
height_max = np.max(pts[:, 2])
height_min = np.min(pts[:, 2])
delta_c = abs(height_max - height_min) / (255 * 2)
for j in range(pts.shape[0]):
    color_n = (pts[j, 2] - height_min) / delta_c
    if color_n <= 255:
        colors[j, :] = [0, 1 - color_n / 255, 1]
    else:
        colors[j, :] = [(color_n - 255) / 255, 0, 1]

cloud.colors = o3d.utility.Vector3dVector(colors)
o3d.visualization.draw_geometries([cloud], window_name="wechat 394467238 ")

 

你可能感兴趣的:(点云处理代码合集,python,开发语言,人工智能,算法,numpy)