我正在使用Google Vision Api
進行人臉檢測。我想在相機中檢測到臉部時啓用拍攝按鈕,否則禁用。它的工作正常,只有問題是當啓用了面部按鈕時,但面部不可用時,按鈕在1/1.5秒後禁用,因爲onDone
回調Tracker
在1或1.5秒後被調用。谷歌視力回調延遲
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);
}
}
我怎麼能很快發現,面對的是相機內沒有回調使 禁用按鈕。如何消除延遲?
我正在使用CameraSourcer.Builder,是否提供框架延遲發生在setMaxGapFrames的情況下,我認爲MaxGapFrames是提供即時回調,該面孔不在相機中的東西。我對嗎???如果是,那麼如何使用CameraSource.Builder實現這個? –
我在上面添加了一些代碼示例。相機源上未設置maxGapFrames;它在面部檢測完成後運行的「處理器」實例上設置。另請參閱此代碼示例以瞭解相機源,檢測器和處理器如何放在一起:https://github.com/googlesamples/android-vision/blob/master/visionSamples/FaceTracker/app/src/main/java/com /google/android/gms/samples/vision/face/facetracker/FaceTrackerActivity.java#L125 – pm0733464