话不多说,直接上代码:
import open3d as o3d
import numpy as np
pcd = o3d.io.read_point_cloud("rabbit.pcd")
f = open('temp.txt', 'r')
lines = f.readlines()
f.close()
for line in lines:
result = np.array(list(map(int, line.split(',')))) # 字符串分割后转为数组
def display_inlier_outlier(cloud, ind):
inlier_cloud = cloud.select_by_index(ind)
outlier_cloud = cloud.select_by_index(ind, invert=True) # 设置为True表示保存ind之外的点
print("Showing outliers (red) and inliers : ")
outlier_cloud.paint_uniform_color([0, 1, 0])
inlier_cloud.paint_uniform_color([1, 0, 0])
o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud],width=600,height=600)
display_inlier_outlier(pcd, result)
rabbit.pcd 文件为斯坦福兔子,在网上有的下载
temp.txt 文件为想提取的点云索引,如下:
运行结果:
参考文章: