我从我的英特尔RealSense深度相机获取点云。我想要删除多余的点,我如何在代码中加入一个条件?
获取点云的代码:
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()
我想要删除的是:
发布于 2021-01-16 14:05:44
这个问题并没有确切说明要删除哪些点。假设您可以提供一个半径和中心位置已知的球体,下面的代码将删除该球体外部的任何点:
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)
https://stackoverflow.com/questions/65731659
复制相似问题