当前位置:   article > 正文

open3d 深度图和点云数据互转,RGBD和点云互转_open3d深度图转点云

open3d深度图转点云

1. 深度图Image和点云

关键代码:

(1) 深度图转点云

pcd = o3d.t.geometry.PointCloud.create_from_depth_image(depth=depth,
                                                        intrinsics=intrinsic,
                                                        depth_scale=5000.0,
                                                        depth_max=10.0)

需要知道相机内外参数。 

(2) 点云转深度图

depth_reproj = pcd.project_to_depth_image(width=640,
                                          height=480,
                                          intrinsics=intrinsic,
                                          depth_scale=5000.0,
                                          depth_max=10.0)

 需要知道相机内外参数。 

point_cloud_to_depth.py

  1. import open3d as o3d
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. if __name__ == '__main__':
  5. # 1. read
  6. tum_data = o3d.data.SampleTUMRGBDImage()
  7. depth = o3d.t.io.read_image(tum_data.depth_path) # Image
  8. # 2. depth Image生成PointCloud
  9. """
  10. create PointCloud from a depth image and a camera model.
  11. depth (open3d.t.geometry.Image): The input depth image should be a uint16_t image.
  12. intrinsics (open3d.core.Tensor): Intrinsic parameters of the camera. 相机内参
  13. extrinsics (open3d.core.Tensor, optional): Extrinsic parameters of the camera. 相机外参
  14. depth_scale (float, optional, default=1000.0): The depth is scaled by 1 / depth_scale.
  15. depth_max (float, optional, default=3.0): Truncated at depth_max distance.
  16. ...params.
  17. """
  18. intrinsic = o3d.core.Tensor([[535.4, 0, 320.1], [0, 539.2, 247.6],
  19. [0, 0, 1]])
  20. pcd = o3d.t.geometry.PointCloud.create_from_depth_image(depth=depth,
  21. intrinsics=intrinsic,
  22. depth_scale=5000.0,
  23. depth_max=10.0)
  24. o3d.visualization.draw([pcd])
  25. # 3. PointCloud生成depth Image
  26. depth_reproj = pcd.project_to_depth_image(width=640,
  27. height=480,
  28. intrinsics=intrinsic,
  29. depth_scale=5000.0,
  30. depth_max=10.0)
  31. fig, axs = plt.subplots(1, 2)
  32. axs[0].imshow(np.asarray(depth.to_legacy())) # 原始depth
  33. axs[1].imshow(np.asarray(depth_reproj.to_legacy())) # depth->ointCloud->depth
  34. plt.show()

2. RGBD和点云

深度图-》RGBD-》点云

需要知道相机内外参数。

point_cloud_to_rgbd.py

  1. import open3d as o3d
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. if __name__ == '__main__':
  5. # 1. read depth and color image
  6. device = o3d.core.Device('CPU:0')
  7. tum_data = o3d.data.SampleTUMRGBDImage()
  8. depth = o3d.t.io.read_image(tum_data.depth_path).to(device)
  9. color = o3d.t.io.read_image(tum_data.color_path).to(device)
  10. # 2. depth and color 生成rgbd
  11. rgbd = o3d.t.geometry.RGBDImage(color, depth)
  12. # 3. rgbd生成pcd
  13. intrinsic = o3d.core.Tensor([[535.4, 0, 320.1], [0, 539.2, 247.6], [0, 0, 1]])
  14. pcd = o3d.t.geometry.PointCloud.create_from_rgbd_image(rgbd,
  15. intrinsic,
  16. depth_scale=5000.0,
  17. depth_max=10.0)
  18. o3d.visualization.draw([pcd])
  19. # 4. pcd生成rgbd
  20. rgbd_reproj = pcd.project_to_rgbd_image(640,
  21. 480,
  22. intrinsic,
  23. depth_scale=5000.0,
  24. depth_max=10.0)
  25. # 5. view
  26. fig, axs = plt.subplots(1, 2)
  27. axs[0].imshow(np.asarray(rgbd_reproj.color.to_legacy())) # 原始rgbd
  28. axs[1].imshow(np.asarray(rgbd_reproj.depth.to_legacy())) # rgbd->pcd->rgbd
  29. plt.show()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/603452
推荐阅读
相关标签
  

闽ICP备14008679号