如何将RGB深度图像转换为点云?

3
我有一个机器人地图研究想法,基本上最终目标是使用中等单眼相机(价格在20-50美元之间),并创建一个三维占据网格地图(有一个流行的C++库称为Octomap)。为了实现这一目标,我提出了以下步骤:
1. 使用卷积神经网络将RGB图像(从视频中获取)转换为深度图像。这部分已完成。 2. 取原始RGB图像和深度图像,并将其转换为点云。 3. 将点云转换为三维占据网格地图。
因此,在第二步中,我有些困惑,不知道我是否做得对或错。我采用了这个开源代码:
import argparse
import sys
import os
from PIL import Image

focalLength = 938.0
centerX = 319.5
centerY = 239.5
scalingFactor = 5000

def generate_pointcloud(rgb_file,depth_file,ply_file):

    rgb = Image.open(rgb_file)
    depth = Image.open(depth_file).convert('I')

    if rgb.size != depth.size:
        raise Exception("Color and depth image do not have the same 
resolution.")
    if rgb.mode != "RGB":
        raise Exception("Color image is not in RGB format")
    if depth.mode != "I":
        raise Exception("Depth image is not in intensity format")


    points = []    
    for v in range(rgb.size[1]):
        for u in range(rgb.size[0]):
            color = rgb.getpixel((u,v))
            Z = depth.getpixel((u,v)) / scalingFactor
            print(Z)
            if Z==0: continue
            X = (u - centerX) * Z / focalLength
            Y = (v - centerY) * Z / focalLength
            points.append("%f %f %f %d %d %d 0\n"% 

我认为points是实际存储点云的列表,我是对的吗?

所以我要问的重要问题是,使用深度学习算法创建的RGB图像和深度图像是否可以使用上述代码转换为点云?


只要你知道缩放因子和焦距,我认为你应该没问题。 - Abyl Ikhsanov
1个回答

0

如果您能够正确处理 RGB 和深度图像的比例,那么就没问题了。您最终得到的点云属性可能是 (x,y,z,r,g,b)


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