import open3d as o3d
import os
import numpy as np
from pyntcloud import PyntCloud
from pandas import DataFrame
# 功能:对点云进行voxel滤波
# 输入:
# point_cloud:输入点云
# leaf_size: voxel尺寸
def voxel_filter(point_cloud, leaf_size, random=False):
filtered_points = []
# 计算边界点
x_min, y_min, z_min = np.amin(point_cloud, axis=0) #计算x y z 三个维度的最值
x_max, y_max, z_max = np.amax(point_cloud, axis=0)
# 计算 voxel grid维度
Dx = (x_max - x_min)//leaf_size + 1
Dy = (y_max - y_min)//leaf_size + 1
Dz = (z_max - z_min)//leaf_size + 1
print("Dx x Dy x Dz is {} x {} x {}".format(Dx, Dy, Dz))
# 计算每个点的voxel索引
h = list() #h 为保存索引的列表
for i in range(len(point_cloud)):
hx = (point_cloud[i][0] - x_min)//leaf_size
hy = (point_cloud[i][1] - y_min)//leaf_size
hz = (point_cloud[i][2] - z_min)//leaf_size
h.append(hx &#