好吧,如果你知道如何将深度图像转换为点图(那是你的点云矩阵),我想你会反过来知道。
鉴于相关相机内在 http://ksimek.github.io/2013/08/13/intrinsic/, using 针孔相机模型 https://en.wikipedia.org/wiki/Pinhole_camera_model,我们可以使用以下 python 代码恢复点图:
import numpy as np
from imageio import imread, imwrite
# read depth image in
img = imread('depth.png')
img = np.asarray(img)
# camera intrinsics, for demonstration purposes only. change to your own.
fx, fy = 570.0, 570.0
cx, cy = 320, 240
# suppose your depth image is scaled 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)
现在回到你的问题。
假设你的点图位于相机坐标系中(您还没有平移或旋转pmap
),要将点图转换为深度图像,我们应该这样做:
# convert point map to depth image
# that is, we are only using the points' z coordinates values
depth = (pmap[:, :, 2] * 1000).astype(np.uint16)
# now we can save the depth image to disk
imwrite('output.png', depth)
希望能帮助到你 :)