1. 深度圖Image和點(diǎn)云
關(guān)鍵代碼:
(1) 深度圖轉(zhuǎn)點(diǎn)云
pcd = o3d.t.geometry.PointCloud.create_from_depth_image(depth=depth, intrinsics=intrinsic, depth_scale=5000.0, depth_max=10.0)
需要知道相機(jī)內(nèi)外參數(shù)。?
(2) 點(diǎn)云轉(zhuǎn)深度圖
depth_reproj = pcd.project_to_depth_image(width=640, height=480, intrinsics=intrinsic, depth_scale=5000.0, depth_max=10.0)
?需要知道相機(jī)內(nèi)外參數(shù)。?
point_cloud_to_depth.py
import open3d as o3d
import numpy as np
import matplotlib.pyplot as plt
if __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. 相機(jī)內(nèi)參
extrinsics (open3d.core.Tensor, optional): Extrinsic parameters of the camera. 相機(jī)外參
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和點(diǎn)云
深度圖-》RGBD-》點(diǎn)云
需要知道相機(jī)內(nèi)外參數(shù)。
point_cloud_to_rgbd.py
import open3d as o3d
import numpy as np
import matplotlib.pyplot as plt
if __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()
文章來源:http://www.zghlxwxcb.cn/news/detail-513675.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-513675.html
到了這里,關(guān)于open3d 深度圖和點(diǎn)云數(shù)據(jù)互轉(zhuǎn),RGBD和點(diǎn)云互轉(zhuǎn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!