如何从三维点云数据中提取深度信息?

3
我是一位可以翻译文本的有用助手。
我有一张RGB图像(我们称之为test.png),以及对应的3D云点(使用立体相机提取)。现在,我想使用深度信息来训练我的神经网络。
3D点云的格式如下:
.PCD v.7 - Point Cloud Data file format
FIELDS x y z rgb index
SIZE 4 4 4 4 4
TYPE F F F F U
COUNT 1 1 1 1 1
WIDTH 253674
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 253674
DATA ascii

我该如何从点云中提取深度信息,并且在不使用RGB图像的情况下添加一个深度通道,使用RGBD图像来训练我的网络?

例如:给定两个像素的点云信息(FIELDS)如下:

1924.064 -647.111 -119.4176 0 25547  
1924.412 -649.678 -119.7147 0 25548

根据描述,它们是与该像素(来自test.png)相交的空间点,具有x、y和z坐标(相对于拍摄图像的机器人底座,因此我们称之为“全局空间”)。 (来自康奈尔抓握数据集)
您可以通过每行中的最后一列(标记为“index”)确定每行所指示的像素。
该数字是像素的行号和列号的编码。在我们所有的图像中, 都有640列和480行。使用以下公式将索引映射到行、列对。 请注意,index = 0映射到row 1,col 1。
行 = floor(index / 640)+1
列 =(index MOD 640)+1

云点坐标{x,y,z}中的z值不等于深度值吗? - vcp
@vcp 我已经更新了有关数据点的更多信息。如果 z 是深度值,那么负值代表什么?x 和 y 又是什么? - user3165156
1个回答

1

看起来文件是以处理过的方式保存的,而不是直接以(列、行、深度)的形式保存。 正如文档所述,我们可以通过以下方式从中心恢复距离

row = floor(index / 640) + 1
col = (index MOD 640) + 1

请注意,并非所有像素都是有效的 - 因此,文件的像素数约为640x480的80% - 导致出现“无组织云”。
import os
import math
import numpy as np
from PIL import Image


pcd_path = "/path/to/pcd file"
with open(pcd_path, "r") as pcd_file:
    lines = [line.strip().split(" ") for line in pcd_file.readlines()]

img_height = 480
img_width = 640
is_data = False
min_d = 0
max_d = 0
img_depth = np.zeros((img_height, img_widht), dtype='f8')
for line in lines:
    if line[0] == 'DATA':  # skip the header
        is_data = True
        continue
    if is_data:
        d = max(0., float(line[2]))
        i = int(line[4])
        col = i % img_width
        row = math.floor(i / img_width)
        img_depth[row, col] = d
        min_d = min(d, min_d)
        max_d = max(d, max_d)

max_min_diff = max_d - min_d


def normalize(x):
    return 255 * (x - min_d) / max_min_diff
normalize = np.vectorize(normalize, otypes=[np.float])
img_depth = normalize(img_depth)
img_depth_file = Image.fromarray(img_depth)
img_depth_file.convert('RGB').save(os.path.join("path/to/output", 'depth_img.png'))

结果图像:

enter image description here

原始图像如下所示:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接