【问题标题】:How to extract depth information from the 3D point cloud data?如何从 3D 点云数据中提取深度信息?
【发布时间】:2017-07-14 19:17:31
【问题描述】:

我有 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 坐标 (相对于拍摄图像的机器人的底部,因此出于我们的目的,我们将其称为“全局空间”)。 (来自康奈尔掌握数据集)

您可以通过每行的最后一列(标记为“索引”)来判断每行所指的像素。
该数字是像素的行号和列号的编码。在我们所有的图像中, 有 640 列和 480 行。使用以下公式将索引映射到行、列对。 请注意,index = 0 映射到第 1 行,第 1 列。

row = floor(index / 640) + 1

col = (索引 MOD 640) + 1

【问题讨论】:

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

标签: 3d point-cloud-library point-clouds


【解决方案1】:

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

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

请注意,并非所有像素都有效 - 因此文件包含大约 80% 的数据,而不是 640x480 像素 - 导致“无组织的云”。

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

结果图片:

原始图像如下所示:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 2016-08-21
    • 2015-08-14
    • 1970-01-01
    • 2014-09-06
    • 2023-03-23
    相关资源
    最近更新 更多