将320x240x3点云矩阵转换为320x240x1深度图

问题描述 投票:0回答:1

有人可以使用Python帮助我解决以下问题吗?

我有一个从虚拟摄像机获得的点云矩阵,其尺寸为320x240x3,它指示每个点(摄像机视图中的点)的x,y,z坐标。

所有值的范围从负到正。如何将此点云矩阵转换为存储每个像素的正深度值的320x240x1深度图?预先感谢。

image-processing computer-vision point-clouds
1个回答
0
投票

好吧,如果您知道如何将深度图像转换为点图(这就是您的点云矩阵),那么我想您会完全相反。

[给出深度图像和相关的camera intrinsics,使用pinhole camera model,我们可以使用以下Python代码恢复点图:

import numpy as np  
from imageio import imread


# read depth image in
img = imread('depth.png')  
img = np.asarray(img)

# camera intrinsics
fx, fy = 570.0, 570.0
cx, cy = 320, 240 

# suppose your depth image is scale by a factor of 1000
z = img.astype(float) / 1000.0  

# convert depth image of shape to point map 
# here we assume depth image is of shape (480, 640)
px, py = np.meshgrid(np.arange(640), np.arange(480))  # pixel_x, pixel_y
px, py = px.astype(float), py.astype(float)
x = ((px - cx) / fx) * z 
y = ((py - cy) / fy) * z 
pmap = np.concatenate([i[..., np.newaxis] for i in (x, y, z)], axis=-1)

假设您的点图在相机坐标系中,要将点图转换为深度图像,我们应该这样做:

# convert point map to depth image
depth = (pmap[:, :, 2] * 1000).astype(np.uint16)

希望有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.