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

Open3D是一个开源库,支持快速开发和处理3D数据。Open3D在c++和Python中公开了一组精心选择的数据结构和算法。后端是高度优化的,并且是为并行化而设置的。

本系列学习计划有Blue同学作为发起人,主要以Open3D官方网站的教程为主进行翻译与实践的学习计划。点云PCL公众号作为免费的3D视觉,点云交流社区,期待有使用Open3D或者感兴趣的小伙伴能够加入我们的翻译计划,贡献免费交流社区,为使用Open3D提供中文的使用教程。

Redwood dataset

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

在这一节我们将会介绍从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 downpcd.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 downpcd.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 mpimgimport 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

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 downpcd.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 downpcd.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)

如果你对Open3D感兴趣,或者正在使用该开源方案,就请加入我们,一起翻译,一起学习,贡献自己的力量,目前阶段主要以微信群为主,有意者发送“Open3D学习计划”到公众号后台,和更多热爱分享的小伙伴一起交流吧!如果翻译的有什么问题或者您有更好的意见,请评论交流!!!!

以上内容如有错误请留言评论,欢迎指正交流。如有侵权,请联系删除

扫描二维码

关注我们

让我们一起分享一起学习吧!期待有想法,乐于分享的小伙伴加入免费星球注入爱分享的新鲜活力。分享的主题包含但不限于三维视觉,点云,高精地图,自动驾驶,以及机器人等相关的领域。

(0)

相关推荐

  • 常见的图像处理技术

    重磅干货,第一时间送达 本期文章中,让我们一起来学习以下内容. 通过PIL和OpenCV来使用一些常见的图像处理技术,例如将RGB图像转换为灰度图像.旋转图像.对图像进行消噪.检测图像中的边缘以及裁剪 ...

  • 手把手教你用Matplotlib进行数据可视化

    导读:Matplotlib是建立在NumPy数组上的一个多平台数据可视化库.在2002年,约翰·亨特(John Hunter)提出Matplotlib,最初的构思是设计为IPython的一个补丁,以便 ...

  • 超全的人脸识别数据集汇总,附打包下载

    加入极市专业CV交流群,与10000+来自腾讯,华为,百度,北大,清华,中科院等名企名校视觉开发者互动交流! 同时提供每月大咖直播分享.真实项目需求对接.干货资讯汇总,行业技术交流.关注 极市平台 公 ...

  • Dataset之COCO数据集:COCO数据集的简介、下载、使用方法之详细攻略

    Dataset之COCO数据集:COCO数据集的简介.安装.使用方法之详细攻略COCO数据集的简介 MS COCO的全称是Microsoft Common Objects in Context,起源于 ...

  • 【百战GAN】如何使用GAN拯救你的低分辨率老照片

    大家好,欢迎来到专栏<百战GAN>,在这个专栏里,我们会进行算法的核心思想讲解,代码的详解,模型的训练和测试等内容. 作者&编辑 | 言有三 本文资源与生成结果展示 本文篇幅:52 ...

  • 使用OpenCV进行对象检测

    重磅干货,第一时间送达 目标检测是图像处理的重要组成部分.自动驾驶汽车必须检测车道,路面,其他车辆,人,标志和信号等.我们生活在一个动态的世界中,一切都在不断变化.对象检测的应用无处不在. 我们正在研 ...

  • 基于K-Means聚类算法的主颜色提取

    重磅干货,第一时间送达 01.简介 本期我们将一起实现基于K-Means聚类算法的主色提取.在深入研究代码之前,让我们先了解一下K-Means算法的背景知识. 02.K均值类聚算法 K-Means算法 ...

  • Paper:《First Order Motion Model for Image Animation》翻译与解读

    Paper:<First Order Motion Model for Image Animation>翻译与解读 更新中-- <First Order Motion Model f ...

  • 基于OpenCV的图像强度操作

    重磅干货,第一时间送达 01. 什么是图像强度操作 更改任何通道中的像素值 对图像的数学运算 亮度变化 对比度变化 伽玛操纵 直方图均衡 图像预处理中的滤波等增强 使用OpenCV加载图像 impor ...

  • 使用OpenCV和TesseractOCR进行车牌检测

    重磅干货,第一时间送达 目录 1)目的和简介 2)前言 3)使用OpenCV和Haar级联进行车牌检测 4)使用TesseractOCR识别和提取车牌号 目的与简介 当我们谈论AI时,计算机视觉绝对是 ...

  • 基于OpenCV的实用图像处理操作

    重磅干货,第一时间送达 图像处理适用于图像和视频.良好的图像处理结果会为后续的进一步处理带来很大的帮助,例如提取到图像中的直线有助于对图像中物体的结构进行分析,良好的特征提取会优化深度学习的结果等.今 ...

  • 使用OpenCV实现图像增强

    重磅干货,第一时间送达 本期将介绍如何通过图像处理从低分辨率/模糊/低对比度的图像中提取有用信息. 下面让我们一起来探究这个过程: 首先我们获取了一个LPG气瓶图像,该图像取自在传送带上运行的仓库.我 ...

  • OpenCV实战(1)

    如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice 最近 ...