Java Code Examples for com.google.android.gms.vision.face.FaceDetector#Detections

The following examples show how to use com.google.android.gms.vision.face.FaceDetector#Detections . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FaceAnalyser.java    From UserAwareVideoView with Apache License 2.0 5 votes vote down vote up
/**
 * When new frame analysed.
 */
@Override
public void onUpdate(FaceDetector.Detections<Face> detectionResults, Face face) {
    Log.d("FaceTracker", "onUpdate" + face.getIsLeftEyeOpenProbability());

    //if left and right eyes are open. (Probability more than 10%)
    if (face.getIsLeftEyeOpenProbability() > 0.10 && face.getIsRightEyeOpenProbability() > 0.10) {
        isEyesClosedCount = 0;
        mUserAwareVideoView.onUserAttentionAvailable();
    } else {
        isEyesClosedCount++;
        if (isEyesClosedCount > 2) mUserAwareVideoView.onUserAttentionGone();
    }
}
 
Example 2
Source File: FaceAnalyser.java    From Prevent-Screen-Off with Apache License 2.0 5 votes vote down vote up
/**
 * Update the position/characteristics of the face within the overlay.
 */
@Override
public void onUpdate(FaceDetector.Detections<Face> detectionResults, Face face) {
    Log.d(getClass().getSimpleName(), "onUpdate" + face.getIsLeftEyeOpenProbability());

    if (face.getIsLeftEyeOpenProbability() > 0.10 && face.getIsRightEyeOpenProbability() > 0.10) {
        isEyesClosedCount = 0;

       mWakelockManager.acquireWakelock();
    } else {
        isEyesClosedCount++;

        if (isEyesClosedCount > 2) mWakelockManager.releaseWakelock();
    }
}
 
Example 3
Source File: GooglyFaceTracker.java    From android-vision with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the positions and state of eyes to the underlying graphic, according to the most
 * recent face detection results.  The graphic will render the eyes and simulate the motion of
 * the iris based upon these changes over time.
 */
@Override
public void onUpdate(FaceDetector.Detections<Face> detectionResults, Face face) {
    mOverlay.add(mEyesGraphic);

    updatePreviousProportions(face);

    PointF leftPosition = getLandmarkPosition(face, Landmark.LEFT_EYE);
    PointF rightPosition = getLandmarkPosition(face, Landmark.RIGHT_EYE);

    float leftOpenScore = face.getIsLeftEyeOpenProbability();
    boolean isLeftOpen;
    if (leftOpenScore == Face.UNCOMPUTED_PROBABILITY) {
        isLeftOpen = mPreviousIsLeftOpen;
    } else {
        isLeftOpen = (leftOpenScore > EYE_CLOSED_THRESHOLD);
        mPreviousIsLeftOpen = isLeftOpen;
    }

    float rightOpenScore = face.getIsRightEyeOpenProbability();
    boolean isRightOpen;
    if (rightOpenScore == Face.UNCOMPUTED_PROBABILITY) {
        isRightOpen = mPreviousIsRightOpen;
    } else {
        isRightOpen = (rightOpenScore > EYE_CLOSED_THRESHOLD);
        mPreviousIsRightOpen = isRightOpen;
    }

    mEyesGraphic.updateEyes(leftPosition, isLeftOpen, rightPosition, isRightOpen);
}
 
Example 4
Source File: FaceFilterActivity.java    From Android-face-filters with Apache License 2.0 4 votes vote down vote up
/**
 * 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,typeFace);
}
 
Example 5
Source File: ARFilterActivity.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 4 votes vote down vote up
@Override
public void onUpdate(FaceDetector.Detections detectionResults, Face face) {
    mOverlay.add(mFaceGraphic);
    updatePreviousLandmarkPositions(face);

    // Get head angles.
    mFaceData.setEulerY(face.getEulerY());
    mFaceData.setEulerZ(face.getEulerZ());

    // Get face dimensions.
    mFaceData.setPosition(face.getPosition());
    mFaceData.setWidth(face.getWidth());
    mFaceData.setHeight(face.getHeight());

    // Get the positions of facial landmarks.
    mFaceData.setLeftEyePosition(getLandmarkPosition(face, Landmark.LEFT_EYE));
    mFaceData.setRightEyePosition(getLandmarkPosition(face, Landmark.RIGHT_EYE));
    mFaceData.setMouthBottomPosition(getLandmarkPosition(face, Landmark.LEFT_CHEEK));
    mFaceData.setMouthBottomPosition(getLandmarkPosition(face, Landmark.RIGHT_CHEEK));
    mFaceData.setNoseBasePosition(getLandmarkPosition(face, Landmark.NOSE_BASE));
    mFaceData.setMouthBottomPosition(getLandmarkPosition(face, Landmark.LEFT_EAR));
    mFaceData.setMouthBottomPosition(getLandmarkPosition(face, Landmark.LEFT_EAR_TIP));
    mFaceData.setMouthBottomPosition(getLandmarkPosition(face, Landmark.RIGHT_EAR));
    mFaceData.setMouthBottomPosition(getLandmarkPosition(face, Landmark.RIGHT_EAR_TIP));
    mFaceData.setMouthLeftPosition(getLandmarkPosition(face, Landmark.LEFT_MOUTH));
    mFaceData.setMouthBottomPosition(getLandmarkPosition(face, Landmark.BOTTOM_MOUTH));
    mFaceData.setMouthRightPosition(getLandmarkPosition(face, Landmark.RIGHT_MOUTH));

    // 1
    final float EYE_CLOSED_THRESHOLD = 0.4f;
    float leftOpenScore = face.getIsLeftEyeOpenProbability();
    if (leftOpenScore == Face.UNCOMPUTED_PROBABILITY) {
        mFaceData.setLeftEyeOpen(mPreviousIsLeftEyeOpen);
    } else {
        mFaceData.setLeftEyeOpen(leftOpenScore > EYE_CLOSED_THRESHOLD);
        mPreviousIsLeftEyeOpen = mFaceData.isLeftEyeOpen();
    }
    float rightOpenScore = face.getIsRightEyeOpenProbability();
    if (rightOpenScore == Face.UNCOMPUTED_PROBABILITY) {
        mFaceData.setRightEyeOpen(mPreviousIsRightEyeOpen);
    } else {
        mFaceData.setRightEyeOpen(rightOpenScore > EYE_CLOSED_THRESHOLD);
        mPreviousIsRightEyeOpen = mFaceData.isRightEyeOpen();
    }

    // 2
    // See if there's a smile!
    // Determine if person is smiling.
    final float SMILING_THRESHOLD = 0.8f;
    mFaceData.setSmiling(face.getIsSmilingProbability() > SMILING_THRESHOLD);

    mFaceGraphic.update(mFaceData);
}
 
Example 6
Source File: ARFilterActivity.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 4 votes vote down vote up
@Override
public void onMissing(FaceDetector.Detections<Face> detectionResults) {
    mOverlay.remove(mFaceGraphic);
}
 
Example 7
Source File: FaceFilterActivity.java    From FaceFilter with MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: MainActivity.java    From Camera2Vision with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: MainActivity.java    From Camera2Vision with Apache License 2.0 4 votes vote down vote up
/**
 * 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) {
    mFaceGraphic.goneFace();
    mOverlay.remove(mFaceGraphic);
}
 
Example 10
Source File: FaceTrackerActivity.java    From android-vision with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: FaceFilterActivity.java    From Android-face-filters with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: FaceFilterActivity.java    From FaceFilter with MIT License 2 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: FaceAnalyser.java    From UserAwareVideoView with Apache License 2.0 2 votes vote down vote up
/**
 * 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) {
    Log.d("onMissing","" );
}
 
Example 14
Source File: FaceAnalyser.java    From Prevent-Screen-Off with Apache License 2.0 2 votes vote down vote up
/**
 * 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) {
}
 
Example 15
Source File: GooglyFaceTracker.java    From android-vision with Apache License 2.0 2 votes vote down vote up
/**
 * 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(mEyesGraphic);
}
 
Example 16
Source File: FaceTrackerActivity.java    From android-vision with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}