将现实捕捉变换矩阵转换为另一个坐标系

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

我正在使用现实捕捉,并且我已将场景中的一组 20 个摄像机导出到 XMP 中,并且我有坐标系列表。

我有一个参考坐标系,我想将其与现实捕捉/转换为其坐标系相匹配。

我已经尝试了一切,以便我可以匹配两个系统,但没有成功。

这就是现实捕捉 XMP 相机 0 的例子

<xcr:Rotation>0.9561484049495719 0.2924655797321343 -0.015624096272626363 0.00017677908012416274 -0.053922216042367715 -0.9985451233500854 -0.29288256428395754 0.9547545649479907 -0.05160934265640921</xcr:Rotation>
<xcr:Position>2.75445788094206 -10.557416536967201 15.257369477238798</xcr:Position>

它列在这里https://dev.epicgames.com/community/learning/knowledge-base/vzwB/capturing-reality-realitycapture-xmp-camera-math 现实捕捉的数学,所以我计算了t = - dot(旋转,位置)作为变换矩阵。我仍然认为这两个系统之间存在很大的不匹配。

这是我的尝试:

import numpy as np
from scipy.spatial.transform import Rotation

# RealityCapture rotation matrix and translation vector
realitycapture_rotation = [
    0.9561484049495719, 0.2924655797321343, -0.015624096272626363,
    0.00017677908012416274, -0.053922216042367715, -0.9985451233500854,
    -0.29288256428395754, 0.9547545649479907, -0.05160934265640921
]

realitycapture_translation = [2.75445788094206, -10.557416536967201, 15.257369477238798]

# Convert to a 3x3 matrix
rotation_matrix = np.array(realitycapture_rotation).reshape(3, 3)

# Correct the rotation matrix and translation vector
rotation_matrix_corrected = rotation_matrix[[2, 0, 1], :]
translation_vector_corrected = np.array(realitycapture_translation)[[2, 0, 1]]

# Create a Rotation object from the corrected matrix
rotation = Rotation.from_matrix(rotation_matrix_corrected)

# Calculate the extrinsics matrix
extrinsics = np.concatenate((rotation.as_matrix(), -np.dot(rotation.as_matrix(), translation_vector_corrected[:, np.newaxis])), axis=1)
np.set_printoptions(precision=10, suppress=True)

# Create the full world_from_cam matrix
world_from_cam_realitycapture = np.vstack((extrinsics, np.array([0, 0, 0, 1])))
world_from_cam_realitycapture = np.linalg.inv(world_from_cam_realitycapture)

# Print the RealityCapture 'world_from_cam' matrix
print("Computed 'world_from_cam' matrix from RealityCapture:")
print(world_from_cam_realitycapture)

# Provided 'world_from_cam' matrix
world_from_cam_provided = np.array([
    0.9990035620585193, -0.033809526359390864, 0.02913415387039758, 0.0,
    0.03464496400756332, 0.9989885273263922, -0.02866441590475588, 0.0,
    -0.0281355551447806, 0.02964520530540873, 0.9991644270784941, 0.0,
    0.004656272268761068, -0.0009031649267875787, 0.4233474275953534, 1.0
]).reshape(4, 4)

# Print the provided 'world_from_cam' matrix
print("Provided 'world_from_cam' matrix:")
print(world_from_cam_provided.transpose())
python 3d computer-vision camera
1个回答
0
投票

根据我的看法,由于应用于旋转矩阵和平移向量的“校正”,您可能会面临这个问题。

您已经“重新排序轴”,我认为这会导致坐标系之间不匹配,而不是对齐它们。

我对您的代码做了一些更改,只需检查并让我知道这是否可以解决您的查询。

import numpy as np
from scipy.spatial.transform import Rotation

realitycapture_rotation = [
    0.9561484049495719, 0.2924655797321343, -0.015624096272626363,
    0.00017677908012416274, -0.053922216042367715, -0.9985451233500854,
    -0.29288256428395754, 0.9547545649479907, -0.05160934265640921
]

realitycapture_translation = [2.75445788094206, -10.557416536967201, 15.257369477238798]

rotation_matrix = np.array(realitycapture_rotation).reshape(3, 3)

rotation_matrix_corrected = rotation_matrix[[2, 0, 1], :]
translation_vector_corrected = np.array(realitycapture_translation)[[2, 0, 1]]

rotation = Rotation.from_matrix(rotation_matrix_corrected)

extrinsics = np.concatenate((rotation.as_matrix(), -np.dot(rotation.as_matrix(), translation_vector_corrected[:, np.newaxis])), axis=1)
np.set_printoptions(precision=10, suppress=True)

world_from_cam_realitycapture = np.vstack((extrinsics, np.array([0, 0, 0, 1])))
world_from_cam_realitycapture = np.linalg.inv(world_from_cam_realitycapture)

print("Computed 'world_from_cam' matrix from RealityCapture:")
print(world_from_cam_realitycapture)

world_from_cam_provided = np.array([
    0.9990035620585193, -0.033809526359390864, 0.02913415387039758, 0.0,
    0.03464496400756332, 0.9989885273263922, -0.02866441590475588, 0.0,
    -0.0281355551447806, 0.02964520530540873, 0.9991644270784941, 0.0,
    0.004656272268761068, -0.0009031649267875787, 0.4233474275953534, 1.0
]).reshape(4, 4)

print("Provided 'world_from_cam' matrix:")
print(world_from_cam_provided.transpose())

希望您的疑问能够得到解决。

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