open3d 深度图和点云数据互转,RGBD和点云互转
短信预约 -IT技能 免费直播动态提醒
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
import open3d as o3dimport numpy as npimport matplotlib.pyplot as pltif __name__ == '__main__': # 1. read tum_data = o3d.data.SampleTUMRGBDImage() depth = o3d.t.io.read_image(tum_data.depth_path) # Image # 2. depth Image生成PointCloud """ create PointCloud from a depth image and a camera model. depth (open3d.t.geometry.Image): The input depth image should be a uint16_t image. intrinsics (open3d.core.Tensor): Intrinsic parameters of the camera. 相机内参 extrinsics (open3d.core.Tensor, optional): Extrinsic parameters of the camera. 相机外参 depth_scale (float, optional, default=1000.0): The depth is scaled by 1 / depth_scale. depth_max (float, optional, default=3.0): Truncated at depth_max distance. ...params. """ intrinsic = o3d.core.Tensor([[535.4, 0, 320.1], [0, 539.2, 247.6], [0, 0, 1]]) pcd = o3d.t.geometry.PointCloud.create_from_depth_image(depth=depth, intrinsics=intrinsic, depth_scale=5000.0, depth_max=10.0) o3d.visualization.draw([pcd]) # 3. PointCloud生成depth Image depth_reproj = pcd.project_to_depth_image(width=640, height=480, intrinsics=intrinsic, depth_scale=5000.0, depth_max=10.0) fig, axs = plt.subplots(1, 2) axs[0].imshow(np.asarray(depth.to_legacy())) # 原始depth axs[1].imshow(np.asarray(depth_reproj.to_legacy())) # depth->ointCloud->depth plt.show()
2. RGBD和点云
深度图-》RGBD-》点云
需要知道相机内外参数。
point_cloud_to_rgbd.py
import open3d as o3dimport numpy as npimport matplotlib.pyplot as pltif __name__ == '__main__': # 1. read depth and color image device = o3d.core.Device('CPU:0') tum_data = o3d.data.SampleTUMRGBDImage() depth = o3d.t.io.read_image(tum_data.depth_path).to(device) color = o3d.t.io.read_image(tum_data.color_path).to(device) # 2. depth and color 生成rgbd rgbd = o3d.t.geometry.RGBDImage(color, depth) # 3. rgbd生成pcd intrinsic = o3d.core.Tensor([[535.4, 0, 320.1], [0, 539.2, 247.6], [0, 0, 1]]) pcd = o3d.t.geometry.PointCloud.create_from_rgbd_image(rgbd, intrinsic, depth_scale=5000.0, depth_max=10.0) o3d.visualization.draw([pcd]) # 4. pcd生成rgbd rgbd_reproj = pcd.project_to_rgbd_image(640, 480, intrinsic, depth_scale=5000.0, depth_max=10.0) # 5. view fig, axs = plt.subplots(1, 2) axs[0].imshow(np.asarray(rgbd_reproj.color.to_legacy())) # 原始rgbd axs[1].imshow(np.asarray(rgbd_reproj.depth.to_legacy())) # rgbd->pcd->rgbd plt.show()
来源地址:https://blog.csdn.net/jizhidexiaoming/article/details/130578591
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341