简体   繁体   English

如何提高ARKit测量两个SCNNode之间距离的准确性?

[英]How to improve accuracy of ARKit for measuring distances between two SCNNodes?

Do someone know how to improve measurement in ARKit. 有人知道如何改善ARKit中的测量。

My current ARConfiguration is: 我当前的ARConfiguration是:

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

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

I try to calculate the distance between two SCNNodes. 我尝试计算两个SCNNode之间的距离。 Are there any methods to improve this? 有什么方法可以改善这一点? I try to calculate distances between 2m - 10m. 我尝试计算2m-10m之间的距离。 Sometimes the deviation is too high for me (30 cm+). 有时偏差对我来说太高了(30 cm +)。

Is it possible to use the planes to improve the accuracy? 是否可以使用这些飞机来提高精度? Or any other ideas? 还是其他想法?

Thanks for help. 感谢帮助。

SCNNodes have positions in Vectors see documentation SCNNode在Vector中具有位置请参阅文档

From the these two properties of your two scenenodes you can compute the distance between them with simple physics. 从两个场景节点的这两个属性,您可以使用简单的物理方法计算它们之间的距离。 For example your can compute the distance in 2D and the distance in 3d world. 例如,您可以计算2D中的距离和3D世界中的距离。 An example can be done with these 2 extensions. 这两个扩展可以作为一个示例。

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))
    }
}

And then in your main class you can call the static function like that 然后在您的主类中,您可以像这样调用静态函数

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM