P
PHDqin
Guest
PHDqin Asks: Split multiple planes using ransac in 3D Pointcloud
How to split multiple planes using ransac in 3D Pointcloud?My code can only split one plane at present.
Right now I am working to do plane segmentation of 3D point cloud data using RANSAC.My code can only split one plane at present. I want to remove one plane after splitting it and continue to split other planes. How can I do this.
enter image description here
How to split multiple planes using ransac in 3D Pointcloud?My code can only split one plane at present.
Right now I am working to do plane segmentation of 3D point cloud data using RANSAC.My code can only split one plane at present. I want to remove one plane after splitting it and continue to split other planes. How can I do this.
Code:
`# -*-coding:utf-8 -*-
import os
import open3d as o3d
import numpy as np
test_data_dir = 'D:/test data'
point_cloud_file_name = 'Area6_office_5.pcd'
point_cloud_file_path = os.path.join(test_data_dir, point_cloud_file_name)
# 读取点云
pcd = o3d.io.read_point_cloud(point_cloud_file_path)
# 平面分割
plane_model, inliers = pcd.segment_plane(distance_threshold=0.03,
ransac_n=3,
num_iterations=1000)
# 模型参数
[a, b, c, d] = plane_model
print(f"Plane equation: {a:.2f}x + {b:.2f}y + {c:.2f}z + {d:.2f} = 0")
# 平面内的点
inlier_cloud = pcd.select_by_index(inliers)
inlier_cloud.paint_uniform_color([255.0, 0, 255.0])
# 平面外的点
outlier_cloud = pcd.select_by_index(inliers, invert=True)
# 可视化
o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud],
zoom=0.8,
front=[-0.4999, -0.1659, -0.8499],
lookat=[2.1813, 2.0619, 2.0999],
up=[0.1204, -0.9852, 0.1215])
`
enter image description here