Open3d学习计划——6(RGBD图像)

Open3d学习计划——6(RGBD图像)

欢迎大家关注“点云PCL”公众号,进入群聊一起学习。

Open3d提供图像(images)数据结构。支持多种函数read_image,write_image,filter_image 和draw_geometries。Open3d的图像能够直接转化为numpy或者从numpy转化。
一个Open3d的RGBDImage由两幅图像组成,分别是RGBDImage.depth & RGBDImage.color。我们要求两幅图像能够通过相同的相机框架和相同的分辨率配准。下面的教程将会介绍如何从一些著名的RGBD数据集去读取和使用RGBD图像。

Redwood dataset

在这一节我们将会介绍从Redwood dataset[Choi2015]数据集中读取和可视化RGBD图像。
Redwood格式数据将深度存储在16-bit单通道图像中。整数值表示深度,以毫米为单位。它是Open3d解析深度图像的默认格式。

print("Read Redwood dataset")
color_raw = o3d.io.read_image("../../TestData/RGBD/color/00000.jpg")
depth_raw = o3d.io.read_image("../../TestData/RGBD/depth/00000.png")
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
    color_raw, depth_raw)
print(rgbd_image)

Read Redwood dataset
RGBDImage of size
Color image : 640x480, with 1 channels.
Depth image : 640x480, with 1 channels.
Use numpy.asarray to access buffer data.

默认的转换函数 create_rgbd_image_from_color_and_depth 从成对的彩色图(color image)和深度图(depth image)中生成RGBDImage 。Color图像被转换为灰度图,储存成[0,1]之间的float类型的数据。深度图像也通过float类型存储,表示深度值(单位:米)。
转换后的结果能够通过numpy数组表示。

plt.subplot(1, 2, 1)
plt.title('Redwood grayscale image')
plt.imshow(rgbd_image.color)
plt.subplot(1, 2, 2)
plt.title('Redwood depth image')
plt.imshow(rgbd_image.depth)
plt.show()

在这里插入图片描述给定一组相机参数,RGBD图像能够转换成点云。

pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
        rgbd_image,
        o3d.camera.PinholeCameraIntrinsic(
            o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
# Flip it, otherwise the pointcloud will be upside down
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
o3d.visualization.draw_geometries([pcd], zoom=0.5)

在这里插入图片描述
这里我们使用PinholeCameraIntrinsicParameters.PrimeSenseDefault 作为默认的相机参数,它的图像分辨率为640x480,焦距(fx,fy)=(525.0,525.0),光学中心(cx,cy)=(319.5,239.5)。使用单位矩阵作为默认的外部参数。pcd.transform在点云上应用上下翻转实现更好的可视化的目的。

SUN dataset

这一节我们将介绍如何从SUN数据集[Song2015]来读取和可视化RGBD图像。
这一节教程与上一节处理Redwood数据几乎相同。唯一的不同是我们使用create_rgbd_image_from_sun_format转换函数来从SUN数据集解析深度图像。

print("Read SUN dataset")
color_raw = o3d.io.read_image(
        "../../TestData/RGBD/other_formats/SUN_color.jpg")
depth_raw = o3d.io.read_image(
        "../../TestData/RGBD/other_formats/SUN_depth.png")
rgbd_image = o3d.geometry.RGBDImage.create_from_sun_format(
        color_raw, depth_raw)
print(rgbd_image)

Read SUN dataset
RGBDImage of size
Color image : 640x480, with 1 channels.
Depth image : 640x480, with 1 channels.
Use numpy.asarray to access buffer data.

plt.subplot(1, 2, 1)
plt.title('SUN grayscale image')
plt.imshow(rgbd_image.color)
plt.subplot(1, 2, 2)
plt.title('SUN depth image')
plt.imshow(rgbd_image.depth)
plt.show()

在这里插入图片描述

pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
        rgbd_image,
        o3d.camera.PinholeCameraIntrinsic(
            o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
# Flip it, otherwise the pointcloud will be upside down
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
o3d.visualization.draw_geometries([pcd], zoom=0.5)

在这里插入图片描述

NYU dataset

这一节我们将介绍如何从NYU数据集[Silberman2012]中读取和可视化RGBD图像。
这一节也与Redwood几乎相同,只有两处不一样。首先,NYU图像不是标准的jpg或者png格式,因此我们需要使用 mpimg.imread来读取一个color图像为一个numpy数组,并将其转化为Open3d图像。还需要使用一个额外的辅助函数read_nyu_pgm来从 NYU数据集使用的特殊大端模式(special big endian) pgm格式的数据中读取深度图像。其次我们使用create_rgbd_image_from_nyu_format转换函数来从NYU数据集中解析深度图。

import matplotlib.image as mpimg
import re

# This is special function used for reading NYU pgm format
# as it is written in big endian byte order.
def read_nyu_pgm(filename, byteorder='>'):
    with open(filename, 'rb') as f:
        buffer = f.read()
    try:
        header, width, height, maxval = re.search(
            b"(^P5\s(?:\s*#.*[\r\n])*"
            b"(\d+)\s(?:\s*#.*[\r\n])*"
            b"(\d+)\s(?:\s*#.*[\r\n])*"
            b"(\d+)\s(?:\s*#.*[\r\n]\s)*)", buffer).groups()
    except AttributeError:
        raise ValueError("Not a raw PGM file: '%s'" % filename)
    img = np.frombuffer(buffer,
                        dtype=byteorder + 'u2',
                        count=int(width) * int(height),
                        offset=len(header)).reshape((int(height), int(width)))
    img_out = img.astype('u2')
    return img_out


print("Read NYU dataset")
# Open3D does not support ppm/pgm file yet. Not using o3d.io.read_image here.
# MathplotImage having some ISSUE with NYU pgm file. Not using imread for pgm.
color_raw = mpimg.imread("../../TestData/RGBD/other_formats/NYU_color.ppm")
depth_raw = read_nyu_pgm("../../TestData/RGBD/other_formats/NYU_depth.pgm")
color = o3d.geometry.Image(color_raw)
depth = o3d.geometry.Image(depth_raw)
rgbd_image = o3d.geometry.RGBDImage.create_from_nyu_format(color, depth)
print(rgbd_image)

Read NYU dataset
RGBDImage of size
Color image : 640x480, with 1 channels.
Depth image : 640x480, with 1 channels.
Use numpy.asarray to access buffer data.

plt.subplot(1, 2, 1)
plt.title('NYU grayscale image')
plt.imshow(rgbd_image.color)
plt.subplot(1, 2, 2)
plt.title('NYU depth image')
plt.imshow(rgbd_image.depth)
plt.show()

在这里插入图片描述

pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
        rgbd_image,
        o3d.camera.PinholeCameraIntrinsic(
            o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
# Flip it, otherwise the pointcloud will be upside down
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
o3d.visualization.draw_geometries([pcd], zoom=0.5)

在这里插入图片描述

TUM dataset

这一节我们介绍TUM数据集[Strum2012]中RGBD图像的读取和可视化。
这一节和之前的Redwood数据集的介绍也几乎一样。只有一点不同是我们使用create_rgbd_image_from_tum_format函数去从TUM数据集中解析深度数据。

print("Read TUM dataset")
color_raw = o3d.io.read_image(
        "../../TestData/RGBD/other_formats/TUM_color.png")
depth_raw = o3d.io.read_image(
        "../../TestData/RGBD/other_formats/TUM_depth.png")
rgbd_image = o3d.geometry.RGBDImage.create_from_tum_format(
        color_raw, depth_raw)
print(rgbd_image)

Read TUM dataset
RGBDImage of size
Color image : 640x480, with 1 channels.
Depth image : 640x480, with 1 channels.
Use numpy.asarray to access buffer data.

plt.subplot(1, 2, 1)
plt.title('TUM grayscale image')
plt.imshow(rgbd_image.color)
plt.subplot(1, 2, 2)
plt.title('TUM depth image')
plt.imshow(rgbd_image.depth)
plt.show()

在这里插入图片描述

pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
        rgbd_image,
        o3d.camera.PinholeCameraIntrinsic(
            o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
# Flip it, otherwise the pointcloud will be upside down
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
o3d.visualization.draw_geometries([pcd], zoom=0.35)

在这里插入图片描述

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

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

在这里插入图片描述

  • 7
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值