首页 文章

如何从3D点 Cloud 数据中提取深度信息?

提问于
浏览
3

我有rgb图像(让我们称之为test.png)和相应的3D Cloud 点(使用立体相机提取) . 现在,我想使用深度信息来训练我的神经网络 .

Format for 3D point cloud is

.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

如何从点 Cloud 中提取深度信息,而不是使用rgb图像我可以再添加一个深度通道并使用RGBD图像来训练我的网络?

例如:两个像素的点 Cloud 信息(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映射到第1行,第1列 .

row = floor(index / 640)1

col =(索引MOD 640)1

1 回答

  • 1

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

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

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

    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

相关问题