本文主要是介绍Open3D均值和中值滤波,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、代码
Python
import open3d as o3d
import numpy as npdef mean_filter(point_cloud, k=50):# 构建KDTreepcd_tree = o3d.geometry.KDTreeFlann(point_cloud)# 为每个点搜索k近邻points = np.asarray(point_cloud.points)filtered_points = np.zeros_like(points)for i in range(points.shape[0]):[_, idx, _] = pcd_tree.search_knn_vector_3d(point_cloud.points[i], k + 1) # k+1,因为包含该点自身knn_points = points[idx, :] # 获取k近邻点坐标filtered_points[i] = np.mean(knn_points, axis=0) # 计算均值# 创建新的点云对象filtered_pcd = o3d.geometry.PointCloud()filtered_pcd.points = o3d.utility.Vector3dVector(filtered_points)return filtered_pcddef median_filter(point_cloud, k=20):pcd_tree = o3d.geometry.KDTreeFlann(point_cloud)filtered_points = np.copy(point_cloud.points)for i, point in enumerate(point_cloud.points):[k, idx,
这篇关于Open3D均值和中值滤波的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!