Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have app where I used a ARSession with ARFaceTrackingConfiguration. I've save a copy of the anchor whenever it is updated in session(_ session: ARSession, didUpdate anchors: [ARAnchor]).

But when the face is no longer in the frame there is no way for the app to know. because this function won't be called.

I've tried writing a flag in session(_ session: ARSession, didRemove anchors: [ARAnchor]) but that is not called because the anchor is not removed when face is no longer in from of the camera. I checked using the current frame of the session frame.anchors.count.

I found no other relevant function in ARSessionDelegate protocol. When the app was paused in the debugger I saw a private property of current frame called detectedFaces which was correctly set to 0 when you put the phone down. But since it's private I can't access it.

like image 938
user14492 Avatar asked Feb 22 '18 21:02

user14492


1 Answers

ARFaceAnchor adopts the ARTrackable protocol, whose sole purpose is to tell you whether an anchor is being updated automatically by ARKit. The isTracked property is true if the anchor's transform has been updated in the current frame, and false otherwise.

Knowing that an anchor is no longer currently tracked is half the solution to your problem — the other thing you probably want to know is when. You have a couple of options there.

  1. Keep references to the face anchors you've been using. When you get a delegate callback like session(_ session: ARSession, didUpdate anchors: [ARAnchor]), any anchors not in the list of those updated are likely stale, and you can check their isTracked property to verify.

  2. Subscribe to the "first" callback for per-frame updates, session(_ session: ARSession, didUpdate frame: ARFrame), or inspect the session's currentFrame, and iterate through the frame's anchors list to see which anchors conform to ARTrackable but report false for isTracked.

like image 173
rickster Avatar answered Oct 20 '22 21:10

rickster