点云外接bbox分两种:与坐标轴对齐的bbox,带方向旋转的bbox.
import open3d as o3d
if __name__ == "__main__":
# 1. read pcd
sample_ply_data = o3d.data.PLYPointCloud()
pcd = o3d.io.read_point_cloud(sample_ply_data.path)
# Flip it, otherwise the pointcloud will be upside down.
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
print(pcd)
# 2. AxisAlignedBoundingBox: 与坐标轴对其的bbox
axis_aligned_bounding_box = pcd.get_axis_aligned_bounding_box()
axis_aligned_bounding_box.color = (1, 0, 0)
# 3. OrientedBoundingBox: 与带方向的旋转bbox
oriented_bounding_box = pcd.get_oriented_bounding_box()
oriented_bounding_box.color = (0, 1, 0)
# 4. view
print(
"Displaying axis_aligned_bounding_box in red and oriented bounding box in green ..."
)
corr = o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5)
o3d.visualization.draw(
[pcd, corr, axis_aligned_bounding_box, oriented_bounding_box])