简体   繁体   English

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

[英]How can I convert RGB depth image to Point Cloud?

I have a research idea for the robot mapping.我有一个关于机器人映射的研究想法。 Basically, the end goal is to use a moderate monocular camera (for $20-50) and create a 3D occupancy grid map (there is a popular library written in c++ called Octomap).基本上,最终目标是使用中等单目相机(20-50 美元)并创建 3D 占用网格图(有一个用 C++ 编写的流行库,称为 Octomap)。 In order to do that, I have proposed myself these steps:为了做到这一点,我建议自己采取以下步骤:

  1. Take an rgb image (from the video) and convert to depth image using Convolutional Neural network.获取 rgb 图像(来自视频)并使用卷积神经网络转换为深度图像。 This part is done.这部分完成了。

  2. Take the original rgb image and created depth image and convert to Point Cloud.获取原始 rgb 图像并创建深度图像并转换为点云。

  3. Take the point cloud and convert it to 3D occupancy grid map.获取点云并将其转换为 3D 占用网格图。

So for the step 2, I am a bit confused, whether I am doing it right or wrong.所以对于第2步,我有点困惑,我做对了还是做错了。 I have taken this code, which is an open source:我已经采用了这个代码,这是一个开源:

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"% 

As I think points is the list that actually stores the point cloud, am I right?因为我认为points是实际存储点云的列表,对吗?

So the big question I am asking is, having RGB image and Depth image created using a deep learning algorithm is it possible to convert to point cloud using the code above?所以我要问的一个大问题是,使用深度学习算法创建 RGB 图像和深度图像是否可以使用上面的代码转换为点云?

If you can properly take care of the RGB and Depth images scale, you will be fine.如果您能妥善处理 RGB 和深度图像比例,您会没事的。 Your final point cloud attributes could be like (x,y,z,r,g,b) .您的最终点云属性可能类似于(x,y,z,r,g,b)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM