【发布时间】:2020-07-01 09:49:42
【问题描述】:
任何人都可以使用 Python 帮助我解决以下问题吗?
我有一个从虚拟相机得到的点云矩阵,它的尺寸是 320x240x3,表示每个点的 x,y,z 坐标(相机视图中的点)。
所有值的范围从负到正。如何将此点云矩阵转换为存储每个像素的正深度值的 320x240x1 深度图?提前致谢。
【问题讨论】:
标签: image-processing computer-vision point-clouds
任何人都可以使用 Python 帮助我解决以下问题吗?
我有一个从虚拟相机得到的点云矩阵,它的尺寸是 320x240x3,表示每个点的 x,y,z 坐标(相机视图中的点)。
所有值的范围从负到正。如何将此点云矩阵转换为存储每个像素的正深度值的 320x240x1 深度图?提前致谢。
【问题讨论】:
标签: image-processing computer-vision point-clouds
好吧,如果您知道如何将深度图像转换为点图(即您的点云矩阵),我想您会反过来知道。
给定关联的camera intrinsics,使用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)
希望对你有帮助:)
【讨论】: