【问题标题】:ARKit switch between ARWorldTrackingConfiguration and ARFaceTrackingConfiguration - Rear and Front CameraARKit 在 ARWorldTrackingConfiguration 和 ARFaceTrackingConfiguration 之间切换 - 后置和前置摄像头
【发布时间】:2019-06-19 08:53:34
【问题描述】:

在我的项目中,我想在ARWorldTrackingConfigurationARFaceTrackingConfiguration 之间切换。

我使用两种不同类型的视图,ARSCNView 使用后置摄像头,ARView 进行面部跟踪。 首先我启动ARSCNView,然后,如果用户愿意,他可以切换到面部跟踪

我以这种模式启动视图控制器:

sceneView.delegate = self
sceneView.session.delegate = self

            // Set up scene content.
setupCamera()            
sceneView.scene.rootNode.addChildNode(focusSquare)

let configurationBack  = ARWorldTrackingConfiguration(
configurationBack.isAutoFocusEnabled = true
configurationBack.planeDetection = [.horizontal, .vertical]


sceneView.session.run(configurationBack, options: [.resetTracking, .removeExistingAnchors])

然后我加载我的对象 (.scn)

当我想切换到前置摄像头并传递给 ARView 时,我会这样做:

 let configurationFront  = ARFaceTrackingConfiguration()

  // here I stop my ARSCNView session
  self.sceneView.session.pause()

    self.myArView = ARView.init(frame: self.sceneView.frame)

    self.myArView!.session.run(configurationFront)
    self.myArView!.session.delegate = self

    self.view.insertSubview(self.myArView!, aboveSubview: self.sceneView)

然后我加载我的.rcproject

所以我的问题从这里开始,当我尝试返回后置摄像头并再次传递给 ARWorldTracking 时。

这是我的方法:

// remove my ARView with face tracking
        self.myArView?.session.pause()

        UIView.animate(withDuration: 0.2, animations: {
            self.myArView?.alpha = 0
        }) { (true) in
            self.myArView?.removeFromSuperview()
            self.myArView = nil

        }
// here I restart the initial ARSCNView
    let configurationBack  = ARWorldTrackingConfiguration(
        configurationBack.isAutoFocusEnabled = true
        configurationBack.planeDetection = [.horizontal, .vertical]


    session.run(configurationBack, options: [.resetTracking, .removeExistingAnchors])

当我切换到后置摄像头时,传感器无法正确跟踪飞机。

我该如何解决这个问题,那么如何在 ARWorldTrackingConfiguration 和 ARFaceTrackingConfiguration 之间正确切换?

提前致谢

【问题讨论】:

  • 您的代码似乎没问题。您是什么意思“传感器无法正确跟踪飞机”?你能解释一下具体的行为吗?
  • @MoRezaFarahani 例如,我在水平和垂直平面上放置了一个焦点方块,以向用户指示将放置对象的位置,但它不尊重表面。它在屏幕中间“飞”
  • 您需要同时进行水平和垂直检测吗?
  • 是的,但只有在应用返回使用带有 ARSCNView @MoRezaFarahani 的后置摄像头后才起作用

标签: ios swift augmented-reality arkit arscnview


【解决方案1】:

请确保在暂停会话时也删除所有添加到场景中的节点。在使用self.sceneView.session.pause() 暂停会话之后添加以下代码:

self.sceneView.scene.rootNode.enumerateChildNodes { (childNode, _) in
    childNode.removeFromParentNode()
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多