基于open3d将RGBD数据利用tsdf合成点云

  1. 初始化
volume = o3d.pipelines.integration.ScalableTSDFVolume(
     voxel_length=0.001, # 分辨率
     sdf_trunc=0.002,  # 截断SDF
     color_type=o3d.pipelines.integration.TSDFVolumeColorType.RGB8)
  1. 合成rgbd数据并加入到定义的volume
for i in range(self.c2w.shape[0]):
    c2w = self.c2w[i].numpy()
    color = self.color[i].numpy()*255
    depth = self.depth[i].numpy()
    rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(o3d.geometry.Image(np.asarray(color, order="C", dtype=np.uint8)), o3d.geometry.Image(depth), depth_scale=1, depth_trunc=0.5, convert_rgb_to_intensity=False)
    volume.integrate(rgbd, o3d.camera.PinholeCameraIntrinsic(self.W, self.H, self.fx, self.fy, self.cx, self.cy), np.linalg.inv(c2w)) 
  1. 输出成mesh或者point cloud
# point cloud
pcd = volume.extract_point_cloud()
o3d.io.write_point_cloud(os.path.join(self.input, 'gt.ply'), pcd)
# mesh
mesh = volume.extract_triangle_mesh()
o3d.io.write_triangle_mesh(os.path.join(self.input, 'mesh.ply'), mesh)

附加open3d的基本操作

# 读取
model_paths = glob.glob(os.path.join(self.input, '*.fbx'))[0]
mesh2 = o3d.io.read_triangle_mesh(model_paths)
# 采样
pcd2 = mesh2.sample_points_poisson_disk(10000)
# 缩放
pcd2.scale(0.003/(2*self.scale),center=[0,0,0])
# 旋转
R1 = pcd2.get_rotation_matrix_from_xyz((0, 0, np.pi))
pcd2.rotate(R1)
posted @ 2025-01-03 16:49  阿奘  阅读(388)  评论(0)    收藏  举报