如何将深度图转换为三维点云?

7

当我将深度图转换为3D点云时,我发现有一个称为缩放因子的术语。有人能否给我一些关于缩放因子实际上是什么的想法。缩放因子和焦距之间是否有任何关系。 代码如下:

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

你最终是如何解决这个问题的? - Lorenzo Sciuto
1个回答

10

在这里,“缩放因子”是指深度图单位与米之间的关系,与相机的焦距无关。

深度图通常以毫米为单位存储在16位无符号整数中,因此要得到以米为单位的Z值,需要将深度图像素除以1000。您具有有些非传统的缩放因子5000,这意味着您的深度图像的单位为200微米。


非常感谢。这真的很有帮助。 - d19911222
centerXcenterY 的值是如何确定的? - papabiceps
@papabiceps:centerX和centerY的值是从内部相机校准中获得的。 - Megha
1
@papabiceps 这篇文章可能对下一个想了解 centerX 和 centerY 的人有所帮助 https://medium.com/yodayoda/from-depth-map-to-point-cloud-7473721d3f - colin

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