如何确定 ARFaceAnchor 是否未在 ARSession 中更新

How to determine if a ARFaceAnchor is not updated in a ARSession

我有一个应用程序,其中我使用了 ARSessionARFaceTrackingConfiguration。每当 session(_ session: ARSession, didUpdate anchors: [ARAnchor]) 更新时,我都会保存锚点的副本。

但是当脸部不再出现在画面中时,应用程序无法知道。因为这个函数不会被调用。

我试过在 session(_ session: ARSession, didRemove anchors: [ARAnchor]) 中写一个标志,但没有被调用,因为当面部不再从相机中时,锚点没有被移除。我使用会话的当前帧进行检查 frame.anchors.count.

我在ARSessionDelegate协议中没有发现其他相关功能。当应用程序在调试器中暂停时,我看到一个名为 detectedFaces 的当前帧的私有 属性,当您放下 phone 时它被正确设置为 0。但由于它是私有的,我无法访问它。

ARFaceAnchor 采用 ARTrackable protocol, whose sole purpose is to tell you whether an anchor is being updated automatically by ARKit. The isTracked 属性 如果锚点的变换已在当前帧中更新,则为 true,否则为 false。

知道当前不再跟踪锚点是解决问题的一半 - 您可能想知道的另一件事是什么时候.你有几个选择。

  1. 保留对您一直使用的面部锚点的引用。当你得到一个像 session(_ session: ARSession, didUpdate anchors: [ARAnchor]) 这样的委托回调时,任何不在更新列表中的锚点都可能是陈旧的,你可以检查他们的 isTracked 属性 来验证。

  2. 订阅 "first" 回调以获取 per-frame 更新,session(_ session: ARSession, didUpdate frame: ARFrame),或检查会话的 currentFrame,并遍历框架的 anchors 列表以查看哪些锚点符合 ARTrackable 但对于 isTracked.

  3. 报告错误