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

3d 如何从三维点云数据中提取深度信息?,3d,point-cloud-library,point-clouds,3d,Point Cloud Library,Point Clouds,我有rgb图像(我们称之为test.png)和相应的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图像(我们称之为test.png)和相应的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图像来训练我的网络

例如:两个像素的点云信息(字段)如下所示:

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列

行=楼层(索引/640)+1


col=(index MOD 640)+1

文件似乎是以经过处理的方式保存的,而不是直接保存在(col、row、depth)中。 如文档所述,我们可以通过以下方式恢复与中心的距离:

row = floor(index / 640) + 1
col = (index MOD 640) + 1
请注意,并非所有像素都是有效的,因此文件中大约80%的数据不是640x480像素,而是“无组织的云”

结果图像:

其中原始图像如下所示:


浊点坐标{x,y,z}中z的值不等于深度值吗?@vcp我更新了有关数据点的更多信息。如果z是深度值,那么负值代表什么?x和y是什么?
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'))