stray_visualize_9.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. def integrate(flags, data):
  2. """
  3. Integrates collected RGB-D maps using the Open3D integration pipeline.
  4. flags: command line arguments
  5. data: dict with keys ['intrinsics', 'poses']
  6. Returns: open3d.geometry.TriangleMesh
  7. """
  8. volume = o3d.pipelines.integration.ScalableTSDFVolume(
  9. voxel_length=flags.voxel_size,
  10. sdf_trunc=0.05,
  11. color_type=o3d.pipelines.integration.TSDFVolumeColorType.RGB8)
  12. intrinsics = get_intrinsics(data['intrinsics'])
  13. rgb_path = os.path.join(flags.path, 'rgb.mp4')
  14. video = skvideo.io.vreader(rgb_path)
  15. for i, (T_WC, rgb) in enumerate(zip(data['poses'], video)):
  16. print(f"Integrating frame {i:06}", end='\r')
  17. depth_path = data['depth_frames'][i]
  18. depth = load_depth(depth_path)
  19. rgb = Image.fromarray(rgb)
  20. rgb = rgb.resize((DEPTH_WIDTH, DEPTH_HEIGHT))
  21. rgb = np.array(rgb)
  22. rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(
  23. o3d.geometry.Image(rgb), depth,
  24. depth_scale=1.0, depth_trunc=MAX_DEPTH, convert_rgb_to_intensity=False)
  25. volume.integrate(rgbd, intrinsics, np.linalg.inv(T_WC))
  26. mesh = volume.extract_triangle_mesh()
  27. mesh.compute_vertex_normals()
  28. return mesh