ios - ARKit 在 ARWorldTrackingConfiguration 和 ARFaceTrackingConfiguration 之间切换 - 后置和前置摄像头
问题描述
ARWorldTrackingConfiguration
在我的项目中,我想在和之间切换ARFaceTrackingConfiguration
。
我使用两种不同类型的视图 aARSCNView
使用后置摄像头和 aARView
进行面部跟踪。首先我启动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 之间正确切换?
提前致谢
解决方案
暂停会话时,请确保同时删除场景中添加的所有节点。在您暂停会话后添加以下代码self.sceneView.session.pause()
:
self.sceneView.scene.rootNode.enumerateChildNodes { (childNode, _) in
childNode.removeFromParentNode()
}
推荐阅读
- python - 获取电子邮件时的 Encode() 参数错误
- php - Laravel 5.8:分页似乎不起作用
- html - 角度容器大小
- database-connection - Microsoft Project Online 连接字符串
- c# - UWP MapControl 非托管内存泄漏
- sql - Postgres - 添加子查询计数以及返回的行。非常大的表 5B+ 行
- google-sheets - 如何在 Google 表格中将多列合并为一列?
- python - 抓取深度嵌套的 HTML 标签,Python
- sql - 更新视图中使用的新列时列名不明确
- python - 如何将 dict 转换为 pandas 多索引数据框