You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何计算LiDAR点云的每立方英尺点密度?(Python方案优先)

计算LiDAR点云每立方英尺点密度的实现方案

核心需求

  • 计算多组无人机LiDAR点云的每立方英尺点密度,用于对比后统一降采样至最低密度,适配语义分割任务
  • 限定工具栈:numpy、laspy、open3d,避免额外引入依赖
  • 点云CRS为美制英尺,1单位=1英尺;数据量较大,无需绝对精确值
  • 部分点云已有供应商提供的密度值,其余需自行计算

实现方案

方案一:Open3D改进实现(利用体素索引统计)

Open3D的VoxelGrid不直接存储体素内点数,但可以通过给每个点分配体素索引,再统计索引频次实现需求:

import numpy as np
import open3d as o3d
from collections import Counter

# 读取点云(PLY格式直接读取;LAS/LAZ可先用laspy读取转numpy后再转Open3D)
ply_file = "lidar1.ply"
pcd = o3d.t.io.read_point_cloud(ply_file).to_legacy()

voxel_size = 1.0  # 对应1立方英尺体素
# 计算每个点所属的体素整数索引
voxel_indices = pcd.compute_voxel_grid_coordinates(voxel_size)
# 将三维索引转为可哈希的元组,统计每个体素内的点数
indices_tuple = tuple(map(tuple, voxel_indices.T))
voxel_point_counts = Counter(indices_tuple)

# 提取密度值并计算统计指标
density_values = list(voxel_point_counts.values())
mean_density = np.mean(density_values)
percentile_90 = np.percentile(density_values, 90)
max_density = np.max(density_values)

print(f"平均密度: {mean_density:.2f} 点/立方英尺")
print(f"90分位密度: {percentile_90:.2f} 点/立方英尺")
print(f"最大密度: {max_density} 点/立方英尺")

方案二:纯Numpy高效实现(适合大数据量)

直接用Numpy对坐标分箱统计,无需依赖Open3D,性能更优,适合超大规模点云:

import numpy as np
import laspy

# 读取LAS/LAZ文件(PLY文件可改用open3d读取后转numpy数组)
las_file = "lidar1.laz"
with laspy.open(las_file) as f:
    las = f.read()
    # 获取点云坐标(已为英尺单位)
    points = np.vstack([las.x, las.y, las.z]).T

voxel_size = 1.0
# 将连续坐标映射为离散体素的整数坐标(向下取整)
voxel_coords = np.floor(points / voxel_size).astype(np.int64)

# 生成体素唯一ID(避免元组哈希,提升统计效率)
# 注:若坐标范围极大,可调整系数避免ID冲突,例如用更大的基数
max_coord = np.max(voxel_coords)
voxel_ids = voxel_coords[:, 0] * (max_coord ** 2) + voxel_coords[:, 1] * max_coord + voxel_coords[:, 2]

# 统计每个体素的点数
unique_ids, counts = np.unique(voxel_ids, return_counts=True)

# 计算密度统计指标
mean_density = np.mean(counts)
percentile_90 = np.percentile(counts, 90)
max_density = np.max(counts)

print(f"平均密度: {mean_density:.2f} 点/立方英尺")
print(f"90分位密度: {percentile_90:.2f} 点/立方英尺")
print(f"最大密度: {max_density} 点/立方英尺")

实用优化建议

  • 大数据量采样:若点云规模过大,可随机采样10%-20%的点计算密度,结果足够满足对比需求
  • LAS/LAZ处理效率:用laspy直接读取转Numpy数组,无需转Open3D,节省内存开销
  • 统计指标选择:对比密度时优先用90分位密度,可规避极端稀疏/密集体素对结果的干扰,更适合作为统一降采样的基准

内容的提问来源于stack exchange,提问作者Rejexx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 20:39:50