private float GetEyeClosedValue(FaceLandmarks landmarks, FaceElement eye) { if (eye != FaceElement.leftEye && eye != FaceElement.rightEye) #if DEBUG { throw new System.Exception(); } #else { return(0F); } #endif // 尺度扩大三倍,便于显示 return(Mathf.Clamp01((1 - GetEyeOpenSize(landmarks.getElement(eye)) / GetEyeOpenSize(originalLandmarks.getElement(eye))) * 3)); }
// 张嘴比例 private float GetMouthOpenValue(FaceLandmarks landmarks, FaceElement mouth) { if (mouth != FaceElement.mouth) #if DEBUG { throw new System.Exception(); } #else { return(0F); } #endif return(Mathf.Clamp01(GetMouthOpenSize(landmarks.getElement(mouth)))); }
// 上眼皮挑动的比例,以初始睁眼尺度的1/10为标准 private float GetEyeWideValue(FaceLandmarks landmarks, FaceElement eye) { if (eye != FaceElement.leftEye && eye != FaceElement.rightEye) #if DEBUG { throw new System.Exception(); } #else { return(0F); } #endif return(Mathf.Clamp01(GetEyeWideSize(landmarks.getElement(eye)) / (GetEyeOpenSize(originalLandmarks.getElement(eye)) / 10))); }
// 眉毛整体上移比例 private float GetEyebowUpValue(FaceLandmarks landmarks, FaceElement eyebow) { if (eyebow != FaceElement.leftEyeBrow && eyebow != FaceElement.rightEyeBrow) #if DEBUG { throw new System.Exception(); } #else { return(0F); } #endif List <Vector2> oriEyebow = originalLandmarks.getElement(eyebow); List <Vector2> curEyebow = landmarks.getElement(eyebow); Vector2 original = oriEyebow[4] - oriEyebow[0]; Vector2 current = curEyebow[4] - curEyebow[0]; return(Mathf.Clamp01(Vector2.Distance(current, original) / GetEyeOpenSize(originalLandmarks.points.GetRange(36, 6)))); }
// 悲伤时的眉尾下滑比例 private float GetEyebowSadValue(FaceLandmarks landmarks, FaceElement eyebow) { if (eyebow != FaceElement.leftEyeBrow && eyebow != FaceElement.rightEyeBrow) #if DEBUG { throw new System.Exception(); } #else { return(0F); } #endif List <Vector2> original = originalLandmarks.getElement(eyebow); List <Vector2> current = landmarks.getElement(eyebow); Vector2 vertial = Vector2.Perpendicular((original[0] - original[4])).normalized; Vector2 distance = current[0] - current[4]; return(Mathf.Clamp01(Vector2.Dot(distance, vertial))); }