【问题标题】:How to improve accuracy of ARKit for measuring distances between two SCNNodes?如何提高 ARKit 测量两个 SCNNode 之间距离的准确性?
【发布时间】:2019-01-30 07:52:47
【问题描述】:

有人知道如何改进 ARKit 中的测量。

我目前的 ARConfiguration 是:

    let configuration = ARWorldTrackingConfiguration()
    configuration.maximumNumberOfTrackedImages = 10
    configuration.environmentTexturing = .automatic

    configuration.planeDetection = [.horizontal , .vertical]
    configuration.isLightEstimationEnabled = true
    configuration.worldAlignment = .gravity

我尝试计算两个 SCNNode 之间的距离。有什么方法可以改善这种情况吗?我尝试计算 2m - 10m 之间的距离。有时偏差对我来说太高了(30 cm+)。

是否可以使用平面来提高精度?还是有其他想法?

感谢您的帮助。

【问题讨论】:

    标签: ios swift ipad arkit


    【解决方案1】:

    SCNNodes 在 Vectors 中有位置见documentation

    根据两个场景节点的这两个属性,您可以用简单的物理方法计算它们之间的距离。例如,您可以计算 2D 中的距离和 3d 世界中的距离。可以用这两个扩展来做一个例子。

    extension SCNVector3 {
        static func distanceFrom(vector vector1: SCNVector3, toVector vector2: SCNVector3) -> Float {
            let x0 = vector1.x
            let x1 = vector2.x
            let y0 = vector1.y
            let y1 = vector2.y
            let z0 = vector1.z
            let z1 = vector2.z
    
            return sqrtf(powf(x1-x0, 2) + powf(y1-y0, 2) + powf(z1-z0, 2))
        }
    }
    

    然后在你的主类中你可以像这样调用静态函数

    let scnNode1 = SCNNode() //Your test node
    let scnNode2 = SCNNode() //Your test node
    let distance = SCNVector3.distanceFrom(vector: scnNode1.position, toVector: scnNode2.position)
    

    【讨论】:

    • 我已经有了计算距离的方法。问题是,准确度不够高
    • 你亲手核对过数字,发现差别很大吗?您的问题的答案是,您必须使用 .position Vector3 属性。现在,如果你有很大的不同,那是因为你的数学。如果你想把数字发给我告诉你
    • 计算是对的。我检查了它,其他人也检查了它。一个大问题是,当距离较高时,节点会移动。它们距离 ArKit 太远,无法将它们固定在所需位置。
    • 如果距离太大,您必须计算地球的弧度才能获得准确的距离,但如果我们以公里为单位,就会发生这种情况。
    • 远距离也有同样的问题。想知道您是否找到了解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 2019-03-29
    • 2018-02-15
    • 1970-01-01
    • 2020-04-13
    相关资源
    最近更新 更多