gpt4 book ai didi

python - 如何将深度图转换为 3D 点云?

转载 作者:太空宇宙 更新时间:2023-11-03 14:00:34 25 4
gpt4 key购买 nike

当我将深度图转换为 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"%

最佳答案

在此上下文中,“比例因子”是指深度图单位与米之间的关系;它与相机的焦距无关。

深度图通常存储在毫米级的 16 位无符号整数中,因此要获得以米为单位的 Z 值,深度图像素需要除以 1000。您有一个有点非常规的比例因子 5000,这意味着深度图的单位是 200 微米。

关于python - 如何将深度图转换为 3D 点云?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49598937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com