Skip to content

Commit c769c73

Browse files
committed
Adding onMissing handling
Adding handling of the onMissing event allows the graphic trackers to hide a temporarily missing item from view, which can happen occasionally during tracking. This can reduce the perception of "lag", since it won't show a stale detection on screen when the detection hasn't really occurred.
1 parent 2f173d0 commit c769c73

File tree

2 files changed

+22
-2
lines changed
  • face

2 files changed

+22
-2
lines changed

face/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face/facetracker/FaceTrackerActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,27 @@ private class GraphicFaceTracker extends Tracker<Face> {
162162
@Override
163163
public void onNewItem(int faceId, Face item) {
164164
mFaceGraphic.setId(faceId);
165-
mOverlay.add(mFaceGraphic);
166165
}
167166

168167
/**
169168
* Update the position/characteristics of the face within the overlay.
170169
*/
171170
@Override
172171
public void onUpdate(FaceDetector.Detections<Face> detectionResults, Face face) {
172+
mOverlay.add(mFaceGraphic);
173173
mFaceGraphic.updateFace(face);
174174
}
175175

176+
/**
177+
* Hide the graphic when the corresponding face was not detected. This can happen for
178+
* intermediate frames temporarily (e.g., if the face was momentarily blocked from
179+
* view).
180+
*/
181+
@Override
182+
public void onMissing(FaceDetector.Detections<Face> detectionResults) {
183+
mOverlay.remove(mFaceGraphic);
184+
}
185+
176186
/**
177187
* Called when the face is assumed to be gone for good. Remove the graphic annotation from
178188
* the overlay.

face/multi-tracker/app/src/main/java/com/google/android/gms/samples/vision/face/multitracker/GraphicTracker.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,27 @@ class GraphicTracker<T> extends Tracker<T> {
4040
@Override
4141
public void onNewItem(int id, T item) {
4242
mGraphic.setId(id);
43-
mOverlay.add(mGraphic);
4443
}
4544

4645
/**
4746
* Update the position/characteristics of the item within the overlay.
4847
*/
4948
@Override
5049
public void onUpdate(Detector.Detections<T> detectionResults, T item) {
50+
mOverlay.add(mGraphic);
5151
mGraphic.updateItem(item);
5252
}
5353

54+
/**
55+
* Hide the graphic when the corresponding face was not detected. This can happen for
56+
* intermediate frames temporarily, for example if the face was momentarily blocked from
57+
* view.
58+
*/
59+
@Override
60+
public void onMissing(Detector.Detections<T> detectionResults) {
61+
mOverlay.remove(mGraphic);
62+
}
63+
5464
/**
5565
* Called when the item is assumed to be gone for good. Remove the graphic annotation from
5666
* the overlay.

0 commit comments

Comments
 (0)