Open3d学习计划——高级篇 5(RGBD融合,RGBD integration)

Open3d学习计划——高级篇 5(RGBD融合)

(ps:感觉这章名字应该叫通过RGBD数据生成网格,关于这章的内容建议大家去百度搜一下关于TSDF算法的博客,或者直接看下面给出的参考论文,有助于大家理解)
Open3d实现了一种可扩展的RGBD图像融合算法。这个算法基于[Curless1996][Newcombe2011] 提出的技术。为了支持大尺度的场景,我们使用了Integrater in ElasticReconstruction.中介绍的分层哈希结构。

从 .log 文件中读取轨迹

该教程使用函数 read_trajectory从 .log 文件中读取相机轨迹。一个示例 .log文件如下:

# examples/TestData/RGBD/odometry.log
0   0   1
1   0   0   2
0   1   0   2
0   0   1 -0.3
0   0   0   1
1   1   2
0.999988  3.08668e-005  0.0049181  1.99962
-8.84184e-005  0.999932  0.0117022  1.97704
-0.0049174  -0.0117024  0.999919  -0.300486
0  0  0  1
class CameraPose:
    def __init__(self, meta, mat):
        self.metadata = meta
        self.pose = mat

    def __str__(self):
        return 'Metadata : ' + ' '.join(map(str, self.metadata)) + '\n' + \
            "Pose : " + "\n" + np.array_str(self.pose)

def read_trajectory(filename):
    traj = []
    with open(filename, 'r') as f:
        metastr = f.readline()
        while metastr:
            metadata = list(map(int, metastr.split()))
            mat = np.zeros(shape=(4, 4))
            for i in range(4):
                matstr = f.readline()
                mat[i, :] = np.fromstring(matstr, dtype=float, sep=' \t')
            traj.append(CameraPose(metadata, mat))
            metastr = f.readline()
    return traj
camera_poses = read_trajectory("../../TestData/RGBD/odometry.log")

TSDF空间融合(TSDF volume integration)

Open3d提供了两种类型的TSDF空间:UniformTSDFVolumeScalableTSDFVolume。推荐使用后一种的原因是因为使用了多层结构支持大尺度场景.
ScalableTSDFVolume有几个参数。voxel_length = 4.0 / 512.0表示TSDF空间中单个体素尺度是 4.0 m 512.0 = 7.8125 m m \frac{4.0m}{512.0} = 7.8125mm 512.04.0m=7.8125mm。减小这个值会得到高分辨率的TSDF空间,但是整合结果容易受到深度噪声的影响。sdf_trunc = 0.04指定符号距离函数(signed distance function ,SDF)的截断值。当 color_type = TSDFVolumeColorType.RGB8时,8位的RGB颜色也被整合作为TSDF空间的一部分。浮点类型强度也能够通过color_type = TSDFVolumeColorType.Gray32convert_rgb_to_intensity = True被整合在一起.颜色整合的灵感来自PCL.

volume = o3d.integration.ScalableTSDFVolume(
    voxel_length=4.0 / 512.0,
    sdf_trunc=0.04,
    color_type=o3d.integration.TSDFVolumeColorType.RGB8)

for i in range(len(camera_poses)):
    print("Integrate {:d}-th image into the volume.".format(i))
    color = o3d.io.read_image(
        "../../TestData/RGBD/color/{:05d}.jpg".format(i))
    depth = o3d.io.read_image(
        "../../TestData/RGBD/depth/{:05d}.png".format(i))
    rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(
        color, depth, depth_trunc=4.0, convert_rgb_to_intensity=False)
    volume.integrate(
        rgbd,
        o3d.camera.PinholeCameraIntrinsic(
            o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault),
        np.linalg.inv(camera_poses[i].pose))

Integrate 0-th image into the volume.
Integrate 1-th image into the volume.
Integrate 2-th image into the volume.
Integrate 3-th image into the volume.
Integrate 4-th image into the volume.

抽取网格

使用 [LorensenAndCline1987]中提出的marching cubes 算法进行网格绘制.

print("Extract a triangle mesh from the volume and visualize it.")
mesh = volume.extract_triangle_mesh()
mesh.compute_vertex_normals()
o3d.visualization.draw_geometries([mesh], front=[0.5297, -0.1873, -0.8272],
                                  lookat=[2.0712, 2.0312, 1.7251],
                                  up=[-0.0558, -0.9809, 0.1864], zoom=0.47)

Extract a triangle mesh from the volume and visualize it.

在这里插入图片描述

Note:
TSDF空间就像3D空间中的加权平均过滤器.如果有更多的帧被整合,那么空间就会产生更加平滑的网格.请去 Make fragments 中查看更多的例子.

关于翻译大家有更好的意见欢迎评论一起学习!!!

欢迎大家加入知识星球一起学习。

在这里插入图片描述

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值