コード例 #1
0
  /**
   * 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);
  }
コード例 #2
0
 /**
  * Called when the face is assumed to be gone for good. Remove the googly eyes graphic from the
  * overlay.
  */
 @Override
 public void onDone() {
   mOverlay.remove(mEyesGraphic);
 }
コード例 #3
0
 /**
  * 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);
 }