一、代码
Python
import open3d as o3d
import numpy as np
import random
import math
# 方法一:体素格下采样
def voxel_cell_downsampling(point, voxel=10):
point = point.voxel_down_sample(voxel)
return point
# 方法二:随机下采样
def random_downsampling(point, size=20):
# 获取点云中点的数量
num_points = np.asarray(point.points).shape[0]
# 随机选取一半的点进行下采样
indices = np.random.choice(num_points, size=num_points // size, replace=False)
point = point.select_by_index(indices)
return point
# 方法三:最远点下采样
def farthest_point_downsampling(point, v=1000, batch=1):
points = np.asarray(point.points)
dump = np.zeros((v, 3))
ran_points = math.floor(len(points) / batch)