ios - 改进 ARKit iOS Swift 中的平面检测

标签 ios swift arkit arscnview

有什么方法可以改进 ARKit 平面检测并减少检测它所花费的时间? 在这里,我们正在检测一个水平面,如果我们保持相机稳定,它需要时间来检测,而且它在地板上不起作用。

对于 table 和其他类似表面,大约需要 5 到 6 秒。但对于楼层,它超过 20 分钟或半分钟,如果我们不移动相机,它根本不起作用。

这是我的代码:-

   override func viewDidLoad() {
    super.viewDidLoad()
    SVProgressHUD.show(withStatus: "Detecting Plane and Getting ready")
    sceneView.delegate = self
    sceneView.session.delegate = self
    sceneView.showsStatistics = false
    let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = .horizontal
    configuration.isLightEstimationEnabled = true

    sceneView.session.run(configuration)
    sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
}
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {

    if currentAnchor == nil {
        currentAnchor = anchor

        let light = SCNLight()
        light.type = .directional
        light.color = UIColor(white: 1.0, alpha: 1.0)
        light.shadowColor = UIColor(white: 0.0, alpha: 0.8).cgColor
        let lightNode = SCNNode()
        lightNode.eulerAngles = SCNVector3Make(-.pi / 3, .pi / 4, 0)
        lightNode.light = light
        sceneView.scene.rootNode.addChildNode(lightNode)

        let ambientLight = SCNLight()
        ambientLight.type = .ambient
        ambientLight.color = UIColor(white: 0.8, alpha: 1.0)
        let ambientNode = SCNNode()
        ambientNode.light = ambientLight
        sceneView.scene.rootNode.addChildNode(ambientNode)
    }
    }
}

最佳答案

我猜地板很光滑,但不够有质感。表面检测可能因多种原因而失败或耗时太长——光线不足、表面反射过度、表面细节不足或相机运动过多。

试着四处走动,打开更多的灯,并确保表面有足够的纹理。

光滑的表面让 ARKit 很难检测到它们。表面的纹理越多,ARKit 检测到它的速度就越快。

关于ios - 改进 ARKit iOS Swift 中的平面检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56089348/

相关文章:

ios - ARKit:如何正确检查支持的设备?

swift - RealityKit 和 ARKit – 当应用程序启动时,AR 项目在寻找什么?

ios - 在 ViewDidLoad 中从 NSUserDefaults 加载数据

ios - UIViewController 中的 UINavigationController 以编程方式在类中

ios - 为什么我们需要在成功解雇转换后从容器 View 中删除 toView?

ios - 如何从嵌入到 iPhone 肖像图片中的深度数据计算距离值?

swift - 如何在 tableViewCell 中快速添加一个 pickerView?

ios - arc4random_uniform 负 100 到正 100

ios - CATextLayer 文本字体随着文本大小的增加而消失

ios - 如何在 ARKit 中的 SCNPlane 上渲染具有透明背景的 UIView?