gpt4 book ai didi

swift - 在 ARKit 3 中从 3D 骨架检索骨骼旋转

转载 作者:行者123 更新时间:2023-12-02 11:20:37 25 4
gpt4 key购买 nike

我试图获得与他们 parent 相关的骨骼旋转,但我最终得到了非常奇怪的角度。

我已经尝试了所有方法,矩阵乘法、偏移、轴交换,但没有运气。


guard let bodyAnchor = anchor as? ARBodyAnchor else { continue }

let skeleton = bodyAnchor.skeleton
let jointTransforms = skeleton.jointLocalTransforms

for (i, jointTransform) in jointTransforms.enumerated() {

//RETRIEVE ANGLES HERE
}

//RETRIEVE ANGLES HERE我尝试了不同的方法:
let n = SCNNode()
n.transform = SCNMatrix4(jointTransform)
print(n.eulerAngles)

在这次尝试中,我设置了 联合转型SCNNode.transform这样我就可以检索 欧拉角使它们具有人类可读性并尝试了解正在发生的事情。

我开始工作一些关节,但我认为这纯粹是巧合或运气,因为其余的骨骼旋转非常奇怪。

在其他尝试中,我使用 来获取它们JointModelTransforms (模型,而不是本地)所以所有的变换都是相对于骨架的根骨骼。

用这种方法我做矩阵乘法是这样的:
LocalMatrix = Inverse(JointModelMatrix) * (ParentJointModelMatrix)

为了获得相对于其父级的旋转,但同样的情况,一些骨骼旋转正常,其他旋转很奇怪。我敢打赌纯属巧合。

为什么我想要获得骨骼旋转?

我正在尝试使用我的手机构建一个 MoCap 应用程序,该应用程序将旋转传递给 Blender,尝试从中构建 .BVH 文件,以便我可以在 Blender 上使用它们。

这是我自己的装备:



我以前用 Kinect 做过这件事,但我已经尝试了好几天在 ARKit 3 上做到这一点,但没有运气:(

最佳答案

使用 simd_quatf(from:to:) 使用正确的输入应该这样做。在我开始对向量进行归一化之前,我遇到了奇怪的角度问题:

guard let bodyAnchor = anchor as? ARBodyAnchor else { continue }

let skeleton = bodyAnchor.skeleton
let jointTransforms = skeleton.jointLocalTransforms

for (i, jointTransform) in jointTransforms.enumerated() {
// First i filter out the root (Hip) joint because it doesn't have a parent
let parentIndex = skeleton.definition.parentIndices[i]
guard parentIndex >= 0 else { continue } // root joint has parent index of -1

//RETRIEVE ANGLES HERE
let jointVectorFromParent = simd_make_float3(jointTransform.columns.3)
let referenceVector: SIMD3<Float>
if skeleton.definition.parentIndices[parentIndex] >= 0 {
referenceVector = simd_make_float3(jointTransforms[parentIndex].columns.3)
} else {
// The parent joint is the Hip joint which should have
// a vector of 0 going to itself
// It's impossible to calculate an angle from a vector of length 0,
// So we're using a vector that's just pointing up
referenceVector = SIMD3<Float>(x: 0, y: 1, z: 0)
}
// Normalizing is important because simd_quatf gives weird results otherwise
let jointNormalized = normalize(jointVectorFromParent)
let referenceNormalized = normalize(referenceVector)
let orientation = simd_quatf(from: referenceNormalized, to: jointNormalized)
print("angle of joint \(i) = \(orientation.angle)")
}

不过要记住一件重要的事情:
ARKit3 仅跟踪一些关节(AFAIK 中的命名关节 ARSkeleton.JointName)。其他关节是从使用标准化骨架的关节推断出来的。这意味着,例如,您获得的肘部角度不会是被跟踪人员肘部在那里的确切角度。

关于swift - 在 ARKit 3 中从 3D 骨架检索骨骼旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58056432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com