stray_visualize_8.py 1.3 KB

123456789101112131415161718192021222324252627282930
  1. def point_clouds(flags, data):
  2. """
  3. Converts depth maps to point clouds and merges them all into one global point cloud.
  4. flags: command line arguments
  5. data: dict with keys ['intrinsics', 'poses']
  6. returns: [open3d.geometry.PointCloud]
  7. """
  8. pcs = []
  9. intrinsics = get_intrinsics(data['intrinsics'])
  10. pc = o3d.geometry.PointCloud()
  11. meshes = []
  12. rgb_path = os.path.join(flags.path, 'rgb.mp4')
  13. video = skvideo.io.vreader(rgb_path)
  14. for i, (T_WC, rgb) in enumerate(zip(data['poses'], video)):
  15. if i % flags.every != 0:
  16. continue
  17. print(f"Point cloud {i}", end="\r")
  18. T_CW = np.linalg.inv(T_WC)
  19. confidence = load_confidence(os.path.join(flags.path, 'confidence', f'{i:06}.png'))
  20. depth_path = data['depth_frames'][i]
  21. depth = load_depth(depth_path, confidence, filter_level=flags.confidence)
  22. rgb = Image.fromarray(rgb)
  23. rgb = rgb.resize((DEPTH_WIDTH, DEPTH_HEIGHT))
  24. rgb = np.array(rgb)
  25. rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(
  26. o3d.geometry.Image(rgb), depth,
  27. depth_scale=1.0, depth_trunc=MAX_DEPTH, convert_rgb_to_intensity=False)
  28. pc += o3d.geometry.PointCloud.create_from_rgbd_image(rgbd, intrinsics, extrinsic=T_CW)
  29. return [pc]