import copy
import open3d as o3d;
import numpy as np;
import matplotlib.pyplot as plt
mesh_coord_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.225, origin=[0, 0, 0])
mesh_coord_frame = mesh_coord_frame.translate((0.16, 0.15, 0))
#加载点云数据
ply = o3d.io.read_point_cloud("source/Foam1.ply")
#去除无效部分
plane_model, inliers = ply.segment_plane(distance_threshold=0.007,
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 = ply.select_by_index(inliers)
outlier_cloud = ply.select_by_index(inliers, invert=True)
o3d.visualization.draw_geometries([ outlier_cloud],window_name="3D有效数据")
#法线 定向
outlier_cloud.estimate_normals(
search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.1, max_nn=30))
o3d.visualization.draw_geometries([outlier_cloud], point_show_normal=True,window_name="法线")