/** * Draws the face annotations for position on the supplied canvas. */ @Override public void draw(Canvas canvas) { Face face = mFace; if (face == null) { return; } // Draws a circle at the position of the detected face, with the face's track id below. float x = translateX(face.getPosition().x + face.getWidth() / 2); float y = translateY(face.getPosition().y + face.getHeight() / 2); canvas.drawCircle(x, y, FACE_POSITION_RADIUS, mFacePositionPaint); canvas.drawText("id: " + mFaceId, x + ID_X_OFFSET, y + ID_Y_OFFSET, mIdPaint); canvas.drawText("happiness: " + String.format("%.2f", face.getIsSmilingProbability()), x - ID_X_OFFSET, y - ID_Y_OFFSET, mIdPaint); canvas.drawText("right eye: " + String.format("%.2f", face.getIsRightEyeOpenProbability()), x + ID_X_OFFSET * 2, y + ID_Y_OFFSET * 2, mIdPaint); canvas.drawText("left eye: " + String.format("%.2f", face.getIsLeftEyeOpenProbability()), x - ID_X_OFFSET*2, y - ID_Y_OFFSET*2, mIdPaint); // Draws a bounding box around the face. float xOffset = scaleX(face.getWidth() / 2.0f); float yOffset = scaleY(face.getHeight() / 2.0f); float left = x - xOffset; float top = y - yOffset; float right = x + xOffset; float bottom = y + yOffset; canvas.drawRect(left, top, right, bottom, mBoxPaint); } }
/** * 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); }
/** * 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(); } }
/** * 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(); } }
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 ); } } }
isSmilingProbability = face.getIsSmilingProbability(); eyeRightOpenProbability = face.getIsRightEyeOpenProbability(); eyeLeftOpenProbability = face.getIsLeftEyeOpenProbability(); eulerY = face.getEulerY(); eulerZ = face.getEulerZ();