当我把深度图转换成三维点云时,我发现有一个术语叫做比例因子。有人能告诉我什么是比例因子吗。缩放因子和焦距之间有什么关系吗。代码如下:
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微米。
相关问题 更多 >
编程相关推荐