关键代码:
dists = pcd.compute_point_cloud_distance(target=chair) # pcd, chair: PointCloud.
import open3d as o3d
import numpy as np
if __name__ == "__main__":
# 1. read pcd
sample_ply_data = o3d.data.DemoCropPointCloud()
pcd = o3d.io.read_point_cloud(sample_ply_data.point_cloud_path)
# 2. crop_point_cloud
vol = o3d.visualization.read_selection_polygon_volume(
sample_ply_data.cropped_json_path)
chair = vol.crop_point_cloud(pcd)
# 3. view
chair.paint_uniform_color([0, 0, 1])
pcd.paint_uniform_color([1, 0, 0])
print("Displaying the two point clouds used for calculating distance ...")
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
chair.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
o3d.visualization.draw([pcd, chair])
# 4. For each point in the source point cloud, compute the distance to the target point cloud.
dists = pcd.compute_point_cloud_distance(target=chair)
dists = np.asarray(dists)
print("Printing average distance between the two point clouds ...")
print(dists)
pcd中的所有点,到char点云之间的距离
Printing average distance between the two point clouds ...
[1.82659798 1.83171046 1.817216 ... 0.27083108 0.27181889 0.27301031]
![](https://img-blog.csdnimg.cn/3425b2615c504a1e948d481f98fb7f3e.png)