三维点云处理03-Radius Outlier Remove代码实现
半径滤波思想
设定一个固定的半径范围,对每个点在该半径范围内查找最近点,并设定最近点最低数量阈值,
如果某个点在该半径范围内的最近点的数量小于该最低数量阈值,则认为该点为离群点,去除
代码实现
import os
import numpy as np
import open3d as o3d
from pyntcloud import PyntCloud
def radius_outlier_remove(pcd,dis,k):
'''
半径滤波去除
'''
pcd_tree = o3d.geometry.KDTreeFlann(pcd)
N = len(pcd.points)
idxs = []
for i in range(N):
[k,idx,_] = pcd_tree.search_radius_vector_3d(pcd.points[i],dis)
num = len(idx)
if num >= k:
idxs.append(i)
points = pcd.points[idxs]
return points
def main(point_cloud_filename):
'''
主函数:
输入:点云文件名
'''
point_cloud_pynt = PyntCloud.from_file(point_cloud_filename)
point_cloud_o3d = point_cloud_pynt.to_instance("open3d",mesh=False)
points = point_cloud_pynt.points
filtered_points = radius_outlier_remove(point_cloud_o3d,dis,k)