Open3D均值和中值滤波

一、代码

Python

import open3d as o3d
import numpy as np


def mean_filter(point_cloud, k=50):
    # 构建KDTree
    pcd_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_pcd


def median_filter(poin

猜你喜欢

转载自blog.csdn.net/qq_58060770/article/details/138227389