Open3d(Python),如何从 .ply 中删除点

Open3d(Python), How to remove points from .ply

我从我的英特尔实感深度相机获取点云。并且我想去除距离较远的多余点,如何在代码中添加条件?

点云获取代码:

import numpy as np
from open3d import *


def main():
    cloud = read_point_cloud("1.ply") # Read the point cloud
    draw_geometries([cloud]) # Visualize the point cloud


if __name__ == "__main__":
    main()

查看点云代码:

import pyrealsense2 as rs


pipe = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth)
pipe.start(config)
colorizer = rs.colorizer()

try:

    frames = pipe.wait_for_frames()
    colorized = colorizer.process(frames)

    ply = rs.save_to_ply("1.ply")
    ply.set_option(rs.save_to_ply.option_ply_binary, False)
    ply.set_option(rs.save_to_ply.option_ply_normals, True)
    ply.process(colorized)

    print("Done")

finally:
    pipe.stop()

我要删除的内容:

这个问题并没有说到底要删除哪些点。假设您可以提供已知半径和中心位置的球体,以下代码将删除该球体之外的所有点:

import numpy as np
import open3d

# Read point cloud from PLY
pcd1 = open3d.io.read_point_cloud("1.ply")
points = np.asarray(pcd1.points)

# Sphere center and radius
center = np.array([1.586, -8.436, -0.242])
radius = 0.5

# Calculate distances to center, set new points
distances = np.linalg.norm(points - center, axis=1)
pcd1.points = open3d.utility.Vector3dVector(points[distances <= radius])

# Write point cloud out
open3d.io.write_point_cloud("out.ply", pcd1)