我正在尝试将屏幕空间坐标(2D)转换为世界空间(3D),以便用python语言生成点云。给我的是投影矩阵、视图矩阵和深度图像。我正试图遵循以下步骤:Getting World Position from Depth Buffer Value
到目前为止,我已经提出了以下代码:
import random
import numpy as np
origin = camera[:-1]
clipSpaceLocation =[]
m_points = []
# Matrix multipication of projection and then view and finally inverse of it
IViewProj = np.linalg.inv(proj @ view)
for y in range(height):
for x in range(width):
# 4x1
# depth image with grayscale values from 0-255
clipSpaceLocation = np.array([(x / width) * 2 - 1,
(y / height) * 2 - 1,
depth[y,x] * 2 - 1,
1])
# 4x4 @ 4x1 -> 4x1
worldSpaceLocation = IViewProj @ clipSpaceLocation
# perspective division
worldSpaceLocation /= worldSpaceLocation[-1]
worldSpaceV3 = worldSpaceLocation[:-1]
m_points.append(worldSpaceV3)
m_points = np.array(m_points)
m_点是[xyz]位置,我最终在点云上绘制,但它没有给出正确的结果,它基本上给了我深度图像的点云。有人能帮我吗
我已经想出了解决办法。如果有人在用Python寻找答案,这就是解决方案:
相关问题 更多 >
编程相关推荐