一、代码
Python
import numpy as np
import open3d as o3ddef mean_sampling(point_cloud, num_samples=None, depth=None, method='knn', k=10):"""对点云进行均值下采样。:param point_cloud: Open3D PointCloud对象:param num_samples: (仅当method='knn'时使用) 期望的采样点数:param depth: (仅当method='octree'时使用) 八叉树的深度,决定了下采样的粒度:param method: 采样方法,'knn' 或 'octree':param k: (仅当method='knn'时使用) 每个采样点的近邻数:return: 下采样后的Open3D PointCloud对象"""if method == 'knn':# 生成搜索树pcd_tree = o3d.geometry.KDTreeFlann(point_cloud)# 随机选择初始采样点points = np.asarray(point_cloud.points)if num_samples is None:raise ValueError("num_samples must be provided for knn method")sampled_indices = np.random.choice(len(points), num_samples, replac