我Google Vision Api
用于人脸检测。我想在相机中检测到面部时启用捕获按钮,否则禁用。它工作正常,唯一的问题是当启用了面部按钮,但面部不可用时,按钮在 1/1.5 秒后禁用,因为在 1 或 1.5 秒后onDone
调用回调Tracker
。
private class GraphicFaceTracker extends Tracker<Face> {
private GraphicOverlay mOverlay;
private FaceGraphic mFaceGraphic;
GraphicFaceTracker(GraphicOverlay overlay) {
mOverlay = overlay;
mFaceGraphic = new FaceGraphic(overlay);
}
/**
* Start tracking the detected face instance within the face overlay.
*/
@Override
public void onNewItem(int faceId, Face item) {
mFaceGraphic.setId(faceId);
}
/**
* Update the position/characteristics of the face within the overlay.
*/
@Override
public void onUpdate(FaceDetector.Detections<Face> detectionResults, Face face) {
mOverlay.add(mFaceGraphic);
mFaceGraphic.updateFace(face);
iv.post(new Runnable() {
@Override
public void run() {
iv.setEnabled(true);
}
});
}
/**
* Hide the graphic when the corresponding face was not detected. This can happen for
* intermediate frames temporarily (e.g., if the face was momentarily blocked from
* view).
*/
@Override
public void onMissing(FaceDetector.Detections<Face> detectionResults) {
mOverlay.remove(mFaceGraphic);
}
/**
* Called when the face is assumed to be gone for good. Remove the graphic annotation from
* the overlay.
*/
@Override
public void onDone() {
iv.post(new Runnable() {
@Override
public void run() {
iv.setEnabled(false);
}
});
mOverlay.remove(mFaceGraphic);
}
}
如何快速获得面部不在相机中的回调,因此禁用该按钮。如何消除延迟?