crop-demo-0.py 1.1 KB

123456789101112131415161718192021222324
  1. # ----------------------------------------------------------------------------
  2. # - Open3D: www.open3d.org -
  3. # ----------------------------------------------------------------------------
  4. # Copyright (c) 2018-2023 www.open3d.org
  5. # SPDX-License-Identifier: MIT
  6. # ----------------------------------------------------------------------------
  7. import open3d as o3d
  8. if __name__ == "__main__":
  9. print("Load a ply point cloud, crop it, and render it")
  10. sample_ply_data = o3d.data.DemoCropPointCloud()
  11. pcd = o3d.io.read_point_cloud(sample_ply_data.point_cloud_path)
  12. vol = o3d.visualization.read_selection_polygon_volume(
  13. sample_ply_data.cropped_json_path)
  14. chair = vol.crop_point_cloud(pcd)
  15. # Flip the pointclouds, otherwise they will be upside down.
  16. pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
  17. chair.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
  18. print("Displaying original pointcloud ...")
  19. o3d.visualization.draw([pcd])
  20. print("Displaying cropped pointcloud")
  21. o3d.visualization.draw([chair])