import open3d as o3d
import numpy as np
pcd = o3d.io.read_point_cloud("chair.pcd")# 建立KD树
pcd_tree = o3d.geometry.KDTreeFlann(pcd)# 使用K近邻,将第1500个点最近的100个点设置为蓝色
k =100# 设置K的大小[nn_k, idx_k, _]= pcd_tree.search_knn_vector_3d(pcd.points[1500], k)# 返回邻域点的个数和索引
法向估计
import open3d as o3d
# Load your point cloud (assuming it's in a file called 'point_cloud.ply')
icloud = o3d.io.read_point_cloud("point_cloud.ply")# Estimate normals using the k-nearest neighbors method
k =30# Specify the number of neighbors you want to use
icloud.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamKNN(knn=k))# Save the point cloud with normals
o3d.io.write_point_cloud("point_cloud_with_normals.ply", icloud)