Open3D从RGB图与depth图产生RGB-D点云(采坑记录)

Open3D

Open3D是一个开源库,它支持处理3D数据的软件的快速开发。Open3D前端在C++和Python中公开了一组精心选择的数据结构和算法。后端经过高度优化,并设置为并行化。
前期也用了一段时间的PCL,但是C++真的啃不动,转而寻求python版的点云处理库,就找到了Open3D。Open3D国内的相关资源还是比较少的,因此我准备在学习过程中,在CSDN上记录遇到的问题以及解决方法,方便后续查找。

下面代码可以利用Open3D生成RGB-D数据

import open3d as o3d
import numpy as np
from matplotlib import pyplot as plt

color_raw = o3d.io.read_image("F:/Depth_image_C++/open_and_save/open_and_save/3Dprintcarrot/rgb/(1).png")
depth_raw = o3d.io.read_image("F:/Depth_image_C++/open_and_save/open_and_save/3Dprintcarrot/depth/(1).png")
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(color_raw, depth_raw, convert_rgb_to_intensity=False)
print(rgbd_image)

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()

inter = o3d.camera.PinholeCameraIntrinsic()
inter.set_intrinsics(1280, 720, 599.795593, 599.633118, 645.792786, 372.238983)
pcd = o3d.geometry.PointCloud().create_from_rgbd_image(
    rgbd_image, inter)

# 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])

遇到的问题

因为我使用的是Azure kinect SDK获取的rgb图与深度图,所以相机的内参需要自己设定下。
内参获取我看相关资料可以在Azure-Kinect-Sensor-SDK/examples/calibration at develop · microsoft/Azure-Kinect-Sensor-SDK · 找到。只需在Visual Studio 2017中加载CmakeList.txt并进行构建,将生成Calibration_info.exe。连接并执行Azure Kinect后,输出如下。

C:\GitHub\Azure-Kinect-Sensor-SDK\build\Win-x64-Release-Ninja\bin>calibration_info.exe  > out.txt

下面是Azure kinect sdk的一些内参,供大家参考
图像尺寸为640×576的内参,格式为K4A_DEPTH_MODE_NFOV_UNBINNED

Found 1 connected devices:

===== Device 0: {DeviceID:XXXXXX} =====
resolution width: 640
resolution height: 576
principal point x: 309.301086
principal point y: 330.656738
focal length x: 505.119751
focal length y: 505.163605
radial distortion coefficients:
k1: 3.063722
k2: 1.988396
k3: 0.102371
k4: 3.397454
k5: 2.984188
k6: 0.544097
center of distortion in Z=1 plane, x: 0.000000
center of distortion in Z=1 plane, y: 0.000000
tangential distortion coefficient x: -0.000098
tangential distortion coefficient y: 0.000048
metric radius: 0.000000

也可以进行自动校准

auto calib = calibration.depth_camera_calibration

auto calib = calibration.color_camera_calibration

这是1080p的内参

Found 1 connected devices:

===== Device 0: {DeviceID:XXXXXX} =====
resolution width: 1920
resolution height: 1080
principal point x: 968.939209
principal point y: 558.608459
focal length x: 899.693420
focal length y: 899.449646
radial distortion coefficients:
k1: 0.678679
k2: -2.779486
k3: 1.569404
k4: 0.554819
k5: -2.610379
k6: 1.500811
center of distortion in Z=1 plane, x: 0.000000
center of distortion in Z=1 plane, y: 0.000000
tangential distortion coefficient x: 0.000476
tangential distortion coefficient y: 0.000104
metric radius: 0.000000

这是720p内参

Found 1 connected devices:

===== Device 0: {DeviceID:XXXXXX} =====
resolution width: 1280
resolution height: 720
principal point x: 645.792786
principal point y: 372.238983
focal length x: 599.795593
focal length y: 599.633118
radial distortion coefficients:
k1: 0.678679
k2: -2.779486
k3: 1.569404
k4: 0.554819
k5: -2.610379
k6: 1.500811
center of distortion in Z=1 plane, x: 0.000000
center of distortion in Z=1 plane, y: 0.000000
tangential distortion coefficient x: 0.000476
tangential distortion coefficient y: 0.000104
metric radius: 0.000000

有了内参,怎么用Open3D读取内参并用于点云生成中

有两种方法
第一种

inter = o3d.camera.PinholeCameraIntrinsic()
inter.set_intrinsics(1280, 720, 599.795593, 599.633118, 645.792786, 372.238983)

这里要注意的是inter = o3d.camera.PinholeCameraIntrinsic(),括号一定不能少,否则会报错

inter.set_intrinsics(1280, 720, 599.795593, 599.633118, 645.792786, 372.238983)
TypeError: set_intrinsics(): incompatible function arguments. The following argument types are supported:
    1. (self: open3d.cpu.pybind.camera.PinholeCameraIntrinsic, width: int, height: int, fx: float, fy: float, cx: float, cy: float) -> None

Invoked with: 1280, 720, 599.795593, 599.633118, 645.792786, 372.238983

第二种

inter= o3d.camera.PinholeCameraIntrinsic(1280, 720, 599.795593, 599.633118, 645.792786, 372.238983)

保存、读取内参

o3d.io.write_pinhole_camera_intrinsic('./file.json', inter)
pinholeCamera = o3d.io.read_pinhole_camera_intrinsic('./file.json')

最后放几张处理过程中的图片

rgb图与depth图
RGB-D点云图
最后的点云图有点失真,可能是因为我的彩色图是RGBA四通道图,转成RGB三通道图就可以正常显示了

  • 12
    点赞
  • 97
    收藏
    觉得还不错? 一键收藏
  • 24
    评论
RGBD像语义分割是指在同时考虑RGB像和深度像的基础上,将像中的每个像素分配给其对应的语义标签。其中,RGB像提供了颜色特征信息,深度像提供了物体的距离和形状信息。相比于仅使用RGB像进行语义分割,使用RGBD像可以提高模型对物体形状的理解和对遮挡物体的处理能力。 RGBD像语义分割的基础可以分为两个方面:1)像语义分割模型的基本架构;2)RGBD数据的获取和预处理。 1)像语义分割模型的基本架构 目前常用的RGBD像语义分割模型包括FCN、SegNet、UNet、DeepLab等。这些模型基于卷积神经网络(CNN)的架构,通过对输入的RGBD像进行卷积、池化等操作,最终输出每个像素对应的语义标签。其中的关键问题是如何将RGBD像信息融合到模型中,常见的方法包括将RGB深度信息分别输入到不同的卷积层中,或者将RGB深度信息按照一定的比例融合到同一层中。 2)RGBD数据的获取和预处理 在获取RGBD数据时,可以使用RGB相机和深度相机同时采集像,或者使用RGB-D传感器(如Kinect)直接获取RGBD像。在预处理时,需要对RGB深度像进行配准,将它们对齐到同一坐标系下,并进行归一化、裁剪等操作以提高模型的鲁棒性。 总的来说,RGBD像语义分割是一种基于深度学习的像分析方法,它可以提高模型对物体形状和遮挡物体的处理能力,为各种视觉应用如机器人导航、自动驾驶等提供了基础支持。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值