【问题标题】:ARKit session's currentFrame is always nilARKit 会话的 currentFrame 始终为 nil
【发布时间】:2017-07-04 09:57:26
【问题描述】:

我尝试从ARSessioncurrentFrame.camera 属性获取相机变换。

为什么我总是将sceneView.session.currentFrame? 设为nil

【问题讨论】:

    标签: ios augmented-reality arkit


    【解决方案1】:

    我刚刚进行了快速测试,发现 session.currentFrame 在前几次通过渲染循环时为零。延迟各不相同,可能是两个或十几个。但最终currentFrame 出现了。

    class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate, SCNSceneRendererDelegate {
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        // Create a session configuration
        let configuration = ARWorldTrackingSessionConfiguration()
        configuration.worldAlignment = .gravityAndHeading
        configuration.planeDetection = .horizontal
    
        sceneView.session.delegate = self
    
        // Run the view's session
        sceneView.session.run(configuration)
        print(#function, sceneView.session.currentFrame)
    
    }
    
    // MARK: - SCNSceneRendererDelegate
    func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
        print(#function, sceneView.session.currentFrame)
    }
    
    // MARK: - ARSessionDelegate
    func session(_ session: ARSession, didUpdate frame: ARFrame) {
        print(#function, sceneView.session.currentFrame)
    }
    

    给我们

    renderer(_:didRenderScene:atTime:) nil
    ...
    session(_:didUpdate:) Optional(<ARFrame: 0x1c42cff10 timestamp=6334.963644 capturedImage=0x1c0124d80 camera=0x1c41262c0 lightEstimate=0x1c4238640 | no anchors, 0 features>)
    ...
    renderer(_:didRenderScene:atTime:) Optional(<ARFrame: 0x1c02c9c30 timestamp=6334.996948 capturedImage=0x1c0124b00 camera=0x1c0124920 lightEstimate=0x1c02251a0 | no anchors, 0 features>)
    

    【讨论】:

      猜你喜欢
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      • 2021-02-27
      • 2019-09-21
      • 2023-04-02
      相关资源
      最近更新 更多