face_gesture_verifier.dart 1.56 KB
Newer Older
1 2 3 4 5 6 7 8 9
import 'package:myhr_facescan/active_liveness/enum.dart';

class FaceGestureVerifier {
  isMatch(double panOrSmile, double tilt, EFaceGesture gesture) {
    var match = false;
    var isExpression = gesture == EFaceGesture.smile;

    if (isExpression) {
      // const double SMILE_CONF_LEVEL_LOW = 0.3;
10
      const double SMILE_CONF_LEVEL_HIGH = 0.8;
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

      if (panOrSmile > SMILE_CONF_LEVEL_HIGH && gesture == EFaceGesture.smile) {
        match = true;
      }
    } else {
      if (gesture == EFaceGesture.turnLeft ||
          gesture == EFaceGesture.turnRight ||
          gesture == EFaceGesture.lookStraight) {
        const double HOR_CONF_LEVEL_LOW = 2;
        const double HOR_CONF_LEVEL_HIGH = 17;

        if (panOrSmile.abs() > HOR_CONF_LEVEL_HIGH) {
          if (panOrSmile > 0 && gesture == EFaceGesture.turnLeft) {
            match = true;
          } else if (panOrSmile <= 0 && gesture == EFaceGesture.turnRight) {
            match = true;
          }
        } else if (panOrSmile.abs() < HOR_CONF_LEVEL_LOW &&
            gesture == EFaceGesture.lookStraight) {
          match = true;
        }
      } else {
        // const double UP_CONF_LEVEL_LOW = 2;
        const double UP_CONF_LEVEL_HIGH = 6;
        // const double DOWN_CONF_LEVEL_LOW = -2;
        const double DOWN_CONF_LEVEL_HIGH = -3;

        if (tilt > UP_CONF_LEVEL_HIGH && gesture == EFaceGesture.lookUp) {
          match = true;
        } else if (tilt < DOWN_CONF_LEVEL_HIGH &&
            gesture == EFaceGesture.lookDown) {
          match = true;
        }
      }
    }

    return match;
  }
}