我正在使用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