[英]How to convert the depth map to 3D point clouds?
当我将深度 map 转换为 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微米。
不是您问题的答案,但我相信您的代码有点错误,因为您直接将深度值用作 Z,但这不是真的depth_of_point!=z
。 更好的 function 可能是:
( pxToMetre
是你提到的系数。)
def convert_from_uvd(u, v, d):
d *= pxToMetre
x_over_z = (cx - u) / focalx
y_over_z = (cy - v) / focaly
z = d / np.sqrt(1. + x_over_z**2 + y_over_z**2)
x = x_over_z * z
y = y_over_z * z
return x, y, z
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.