繁体   English   中英

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM