Java Code Examples for com.google.android.gms.vision.face.Face#getIsRightEyeOpenProbability()

The following examples show how to use com.google.android.gms.vision.face.Face#getIsRightEyeOpenProbability() . 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: FaceOverlayView.java    From Eye-blink-detector with MIT License 6 votes vote down vote up
private boolean isEyeBlinked(){

        if(mFaces.size()==0)
            return false;

        Face face = mFaces.valueAt(0);
        float currentLeftEyeOpenProbability = face.getIsLeftEyeOpenProbability();
        float currentRightEyeOpenProbability = face.getIsRightEyeOpenProbability();
        if(currentLeftEyeOpenProbability== -1.0 || currentRightEyeOpenProbability == -1.0){
            return false;
        }

        if(leftEyeOpenProbability>0.9 || rightEyeOpenProbability > 0.9){
            boolean blinked = false;
            if(currentLeftEyeOpenProbability<0.6 || rightEyeOpenProbability< 0.6){
                blinked = true;
            }
            leftEyeOpenProbability = currentLeftEyeOpenProbability;
            rightEyeOpenProbability = currentRightEyeOpenProbability;
            return blinked;
        }else{
            leftEyeOpenProbability = currentLeftEyeOpenProbability;
            rightEyeOpenProbability = currentRightEyeOpenProbability;
            return false;
        }
    }
 
Example 2
Source File: FaceOverlayView.java    From Eye-blink-detector with MIT License 6 votes vote down vote up
private void logFaceData() {
    float smilingProbability;
    float leftEyeOpenProbability;
    float rightEyeOpenProbability;
    float eulerY;
    float eulerZ;
    for( int i = 0; i < mFaces.size(); i++ ) {
        Face face = mFaces.valueAt(i);
        smilingProbability = face.getIsSmilingProbability();
        leftEyeOpenProbability = face.getIsLeftEyeOpenProbability();
        rightEyeOpenProbability = face.getIsRightEyeOpenProbability();
        eulerY = face.getEulerY();
        eulerZ = face.getEulerZ();
        Log.e( "Tuts+ Face Detection", "Smiling: " + smilingProbability );
        Log.d( "Tuts+ Face Detection", "Left eye open: " + leftEyeOpenProbability );
        Log.d( "Tuts+ Face Detection", "Right eye open: " + rightEyeOpenProbability );
        Log.e( "Tuts+ Face Detection", "Euler Y: " + eulerY );
        Log.e( "Tuts+ Face Detection", "Euler Z: " + eulerZ );
    }
}
 
Example 3
Source File: FaceOverlayView.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void logFaceData() {
    float smilingProbability;
    float leftEyeOpenProbability;
    float rightEyeOpenProbability;
    float eulerY;
    float eulerZ;
    for( int i = 0; i < mFaces.size(); i++ ) {
        Face face = mFaces.valueAt(i);

        smilingProbability = face.getIsSmilingProbability();
        leftEyeOpenProbability = face.getIsLeftEyeOpenProbability();
        rightEyeOpenProbability = face.getIsRightEyeOpenProbability();
        eulerY = face.getEulerY();
        eulerZ = face.getEulerZ();

        Log.e( "Tuts+ Face Detection", "Smiling: " + smilingProbability );
        Log.e( "Tuts+ Face Detection", "Left eye open: " + leftEyeOpenProbability );
        Log.e( "Tuts+ Face Detection", "Right eye open: " + rightEyeOpenProbability );
        Log.e( "Tuts+ Face Detection", "Euler Y: " + eulerY );
        Log.e( "Tuts+ Face Detection", "Euler Z: " + eulerZ );
    }
}
 
Example 4
Source File: MyFace.java    From flutter_mobile_vision with MIT License 5 votes vote down vote up
public MyFace(Face face) {
    this.id = face.getId();
    this.x = face.getPosition().x;
    this.y = face.getPosition().y;
    this.width = face.getWidth();
    this.height = face.getHeight();
    this.eulerY = face.getEulerY();
    this.eulerZ = face.getEulerZ();
    this.leftEyeOpenProbability = face.getIsLeftEyeOpenProbability();
    this.rightEyeOpenProbability = face.getIsRightEyeOpenProbability();
    this.smilingProbability = face.getIsSmilingProbability();
}
 
Example 5
Source File: FaceOverlayView.java    From Eye-blink-detector with MIT License 5 votes vote down vote up
private boolean isEyeToggled() {

        if (mFaces.size() == 0)
            return false;

        Face face = mFaces.valueAt(0);
        float currentLeftEyeOpenProbability = face.getIsLeftEyeOpenProbability();
        float currentRightEyeOpenProbability = face.getIsRightEyeOpenProbability();
        if (currentLeftEyeOpenProbability == -1.0 || currentRightEyeOpenProbability == -1.0) {
            return false;
        }

        double currentLeftOpenRatio = currentLeftEyeOpenProbability / currentRightEyeOpenProbability;
        if (currentLeftOpenRatio > 3) currentLeftOpenRatio = 3;
        if (currentLeftOpenRatio < 0.33) currentLeftOpenRatio = 0.33;

        Log.d("probs",currentLeftOpenRatio+" "+leftopenRatio );
        if(currentLeftOpenRatio==0.33|| currentLeftOpenRatio ==3.0){
            if(leftopenRatio==1){
                leftopenRatio = currentLeftOpenRatio;
            }

            if(leftopenRatio*currentLeftOpenRatio==0.99){
                leftopenRatio = currentLeftOpenRatio;
                return true;
            }
        }

        return false;
    }
 
Example 6
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 7
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 8
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 9
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 10
Source File: FaceGraphic.java    From Camera2Vision with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    Face face = mFace;
    if(face == null) {
        canvas.drawColor(0, PorterDuff.Mode.CLEAR);
        isSmilingProbability = -1;
        eyeRightOpenProbability= -1;
        eyeLeftOpenProbability = -1;
        return;
    }

    facePosition = new PointF(translateX(face.getPosition().x), translateY(face.getPosition().y));
    faceWidth = face.getWidth() * 4;
    faceHeight = face.getHeight() * 4;
    faceCenter = new PointF(translateX(face.getPosition().x + faceWidth/8), translateY(face.getPosition().y + faceHeight/8));
    isSmilingProbability = face.getIsSmilingProbability();
    eyeRightOpenProbability = face.getIsRightEyeOpenProbability();
    eyeLeftOpenProbability = face.getIsLeftEyeOpenProbability();
    eulerY = face.getEulerY();
    eulerZ = face.getEulerZ();
    //DO NOT SET TO NULL THE NON EXISTENT LANDMARKS. USE OLDER ONES INSTEAD.
    for(Landmark landmark : face.getLandmarks()) {
        switch (landmark.getType()) {
            case Landmark.LEFT_EYE:
                leftEyePos = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.RIGHT_EYE:
                rightEyePos = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.NOSE_BASE:
                noseBasePos = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.LEFT_MOUTH:
                leftMouthCorner = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.RIGHT_MOUTH:
                rightMouthCorner = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.BOTTOM_MOUTH:
                mouthBase = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.LEFT_EAR:
                leftEar = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.RIGHT_EAR:
                rightEar = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.LEFT_EAR_TIP:
                leftEarTip = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.RIGHT_EAR_TIP:
                rightEarTip = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.LEFT_CHEEK:
                leftCheek = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
            case Landmark.RIGHT_CHEEK:
                rightCheek = new PointF(translateX(landmark.getPosition().x), translateY(landmark.getPosition().y));
                break;
        }
    }

    Paint mPaint = new Paint();
    mPaint.setColor(Color.WHITE);
    mPaint.setStrokeWidth(4);
    if(faceCenter != null)
        canvas.drawBitmap(marker, faceCenter.x, faceCenter.y, null);
    if(noseBasePos != null)
        canvas.drawBitmap(marker, noseBasePos.x, noseBasePos.y, null);
    if(leftEyePos != null)
        canvas.drawBitmap(marker, leftEyePos.x, leftEyePos.y, null);
    if(rightEyePos != null)
        canvas.drawBitmap(marker, rightEyePos.x, rightEyePos.y, null);
    if(mouthBase != null)
        canvas.drawBitmap(marker, mouthBase.x, mouthBase.y, null);
    if(leftMouthCorner != null)
        canvas.drawBitmap(marker, leftMouthCorner.x, leftMouthCorner.y, null);
    if(rightMouthCorner != null)
        canvas.drawBitmap(marker, rightMouthCorner.x, rightMouthCorner.y, null);
    if(leftEar != null)
        canvas.drawBitmap(marker, leftEar.x, leftEar.y, null);
    if(rightEar != null)
        canvas.drawBitmap(marker, rightEar.x, rightEar.y, null);
    if(leftEarTip != null)
        canvas.drawBitmap(marker, leftEarTip.x, leftEarTip.y, null);
    if(rightEarTip != null)
        canvas.drawBitmap(marker, rightEarTip.x, rightEarTip.y, null);
    if(leftCheek != null)
        canvas.drawBitmap(marker, leftCheek.x, leftCheek.y, null);
    if(rightCheek != null)
        canvas.drawBitmap(marker, rightCheek.x, rightCheek.y, null);
}