public Bitmap DrawMarqueurs(FaceLandmarks faceLandmarks, Bitmap bitmap) { Bitmap result = new Bitmap(bitmap); result = DrawPointOnBitmap(faceLandmarks.EyebrowLeftInner.X, faceLandmarks.EyebrowLeftInner.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyebrowLeftOuter.X, faceLandmarks.EyebrowLeftOuter.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyebrowRightInner.X, faceLandmarks.EyebrowRightInner.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyebrowRightOuter.X, faceLandmarks.EyebrowRightOuter.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyeLeftBottom.X, faceLandmarks.EyeLeftBottom.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyeLeftInner.X, faceLandmarks.EyeLeftInner.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyeLeftOuter.X, faceLandmarks.EyeLeftOuter.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyeLeftTop.X, faceLandmarks.EyeLeftTop.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyeRightBottom.X, faceLandmarks.EyeRightBottom.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyeRightInner.X, faceLandmarks.EyeRightInner.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyeRightOuter.X, faceLandmarks.EyeRightOuter.Y, result); result = DrawPointOnBitmap(faceLandmarks.EyeRightTop.X, faceLandmarks.EyeRightTop.Y, result); result = DrawPointOnBitmap(faceLandmarks.MouthLeft.X, faceLandmarks.MouthLeft.Y, result); result = DrawPointOnBitmap(faceLandmarks.MouthRight.X, faceLandmarks.MouthRight.Y, result); result = DrawPointOnBitmap(faceLandmarks.NoseLeftAlarOutTip.X, faceLandmarks.NoseLeftAlarOutTip.Y, result); result = DrawPointOnBitmap(faceLandmarks.NoseLeftAlarTop.X, faceLandmarks.NoseLeftAlarTop.Y, result); result = DrawPointOnBitmap(faceLandmarks.NoseRightAlarOutTip.X, faceLandmarks.NoseRightAlarOutTip.Y, result); result = DrawPointOnBitmap(faceLandmarks.NoseRightAlarTop.X, faceLandmarks.NoseRightAlarTop.Y, result); result = DrawPointOnBitmap(faceLandmarks.NoseRootLeft.X, faceLandmarks.NoseRootLeft.Y, result); result = DrawPointOnBitmap(faceLandmarks.NoseRootRight.X, faceLandmarks.NoseRootRight.Y, result); result = DrawPointOnBitmap(faceLandmarks.NoseTip.X, faceLandmarks.NoseTip.Y, result); result = DrawPointOnBitmap(faceLandmarks.PupilLeft.X, faceLandmarks.PupilLeft.Y, result); result = DrawPointOnBitmap(faceLandmarks.PupilRight.X, faceLandmarks.PupilRight.Y, result); result = DrawPointOnBitmap(faceLandmarks.UnderLipBottom.X, faceLandmarks.UnderLipBottom.Y, result); result = DrawPointOnBitmap(faceLandmarks.UnderLipTop.X, faceLandmarks.UnderLipTop.Y, result); result = DrawPointOnBitmap(faceLandmarks.UpperLipBottom.X, faceLandmarks.UpperLipBottom.Y, result); result = DrawPointOnBitmap(faceLandmarks.UpperLipTop.X, faceLandmarks.UpperLipTop.Y, result); return(result); }
private static PointF[] convertLandmarkFormation( ref FaceLandmarks _landmarks, ref FaceRectangle _rectangle) { PointF[] retLandmarks = new PointF[27] { convertPointFormation(_landmarks.EyebrowLeftOuter, _rectangle), convertPointFormation(_landmarks.EyebrowLeftInner, _rectangle), convertPointFormation(_landmarks.EyebrowRightOuter, _rectangle), convertPointFormation(_landmarks.EyebrowRightInner, _rectangle), convertPointFormation(_landmarks.EyeLeftOuter, _rectangle), convertPointFormation(_landmarks.EyeLeftTop, _rectangle), convertPointFormation(_landmarks.EyeLeftInner, _rectangle), convertPointFormation(_landmarks.EyeLeftBottom, _rectangle), convertPointFormation(_landmarks.PupilLeft, _rectangle), convertPointFormation(_landmarks.EyeRightOuter, _rectangle), convertPointFormation(_landmarks.EyeRightTop, _rectangle), convertPointFormation(_landmarks.EyeRightInner, _rectangle), convertPointFormation(_landmarks.EyeRightBottom, _rectangle), convertPointFormation(_landmarks.PupilRight, _rectangle), convertPointFormation(_landmarks.NoseRootLeft, _rectangle), convertPointFormation(_landmarks.NoseLeftAlarTop, _rectangle), convertPointFormation(_landmarks.NoseLeftAlarOutTip, _rectangle), convertPointFormation(_landmarks.NoseTip, _rectangle), convertPointFormation(_landmarks.NoseRightAlarOutTip, _rectangle), convertPointFormation(_landmarks.NoseRightAlarTop, _rectangle), convertPointFormation(_landmarks.NoseRootRight, _rectangle), convertPointFormation(_landmarks.MouthLeft, _rectangle), convertPointFormation(_landmarks.UpperLipTop, _rectangle), convertPointFormation(_landmarks.MouthRight, _rectangle), convertPointFormation(_landmarks.UnderLipBottom, _rectangle), convertPointFormation(_landmarks.UpperLipBottom, _rectangle), convertPointFormation(_landmarks.UnderLipTop, _rectangle), }; return(retLandmarks); }
private void GetAngles(FaceLandmarks currentLandmarks) { currentPosture = new FacePosture(); currentPosture.updatePoints(currentLandmarks); currentPosture.GetAnglesAndPoints(model_points); print("roll:" + currentPosture.angles.roll + " yaw:" + currentPosture.angles.yaw + " pitch:" + currentPosture.angles.pitch); }
public DetectedFace(FaceRectangle faceRectangle, System.Guid?faceId = default(System.Guid?), string recognitionModel = default(string), FaceLandmarks faceLandmarks = default(FaceLandmarks), FaceAttributes faceAttributes = default(FaceAttributes)) { FaceId = faceId; RecognitionModel = recognitionModel; FaceRectangle = faceRectangle; FaceLandmarks = faceLandmarks; FaceAttributes = faceAttributes; }
public void InitFace() { originalLandmarks = null; currentLandmarks = null; currentPosture = null; }
// 张嘴比例 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 static void ProcessNose(FaceRectangle faceRectangle, FaceLandmarks faceLandmarks, FaceAttributes faceAttributes, List <Trait> traits) { if (Math.Abs(faceAttributes.HeadPose.Yaw) < 8.0) { var noseRootSize = GetDistance(faceLandmarks.NoseRootLeft, faceLandmarks.NoseRootRight); var noseAlarTopSize = GetDistance(faceLandmarks.NoseLeftAlarTop, faceLandmarks.NoseRightAlarTop); var noseAlartTipSize = GetDistance(faceLandmarks.NoseLeftAlarOutTip, faceLandmarks.NoseRightAlarTop); var noseHeight = GetDistance(faceLandmarks.NoseLeftAlarOutTip, faceLandmarks.NoseRootLeft); var noseRootProportion = noseRootSize / faceRectangle.Width; var noseAlarTopProportion = noseAlarTopSize / faceRectangle.Width; var noseAlarTipProportion = noseAlartTipSize / faceRectangle.Width; var noseHeightProportion = noseHeight / faceRectangle.Height; var numberOfHits = 0; if (noseRootProportion > 0.13) { numberOfHits++; } if (noseAlarTopProportion > 0.2) { numberOfHits++; } if (noseAlarTipProportion > 0.25) { numberOfHits++; } if (noseHeightProportion > 0.25) { numberOfHits++; } if (numberOfHits >= 2) { traits.Add(new Trait { Name = "bignose", Accuracy = 1.0 }); } } else { var noseLeftLength = GetDistance(faceLandmarks.NoseTip, faceLandmarks.NoseLeftAlarOutTip); var noseRightLength = GetDistance(faceLandmarks.NoseTip, faceLandmarks.NoseRightAlarOutTip); var noseLength = Math.Max(noseLeftLength, noseRightLength); var noseLengthProportion = noseLength / (faceRectangle.Width * Math.Abs(faceAttributes.HeadPose.Yaw)); if (noseLengthProportion > 0.008) { traits.Add(new Trait { Name = "bignose", Accuracy = 1.0 }); } } }
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)); }
public void UpdateFacial(FaceLandmarks landmarks) { if (originalLandmarks == null) { originalLandmarks = landmarks; lastFacialValues.initial(); } else { currentLandmarks = landmarks; //GetAngles(currentLandmarks); } }
// 嘟嘴比例 private float GetMouthPuffValue(FaceLandmarks landmarks, FaceElement outline) { if (outline != FaceElement.outline) #if DEBUG { throw new System.Exception(); } #else { return(0F); } #endif Vector2 original = originalLandmarks.points[12] - originalLandmarks.points[4]; Vector2 current = landmarks.points[12] - landmarks.points[4]; float o_dist = original.magnitude; float c_dist = current.magnitude; return(Mathf.Clamp01((c_dist / o_dist - 1) * 8)); }
public static Dictionary <string, FeatureCoordinate> AsDictionary( this FaceLandmarks landmarks) { Dictionary <string, FeatureCoordinate> coords = new Dictionary <string, FeatureCoordinate>(); TypeInfo typeInfo = landmarks.GetType().GetTypeInfo(); foreach (var property in typeInfo.DeclaredProperties) { var value = property.GetValue(landmarks) as FeatureCoordinate; coords.Add(property.Name, value); } return(coords); }
public virtual void Validate() { if (FaceRectangle == null) { throw new ValidationException(ValidationRules.CannotBeNull, "FaceRectangle"); } if (FaceRectangle != null) { FaceRectangle.Validate(); } if (FaceLandmarks != null) { FaceLandmarks.Validate(); } }
// 眉毛整体上移比例 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))); }
public void updatePoints(FaceLandmarks landmarks) { points.Clear(); //points = now_points; //points = landmarks.points.ConvertAll(point => new Point2f(point.x, point.y)); // Tipnose points.Add(new Point2f(landmarks.points[30].x, landmarks.points[30].y)); // Chin points.Add(new Point2f(landmarks.points[8].x, landmarks.points[8].y)); // Left corner of the left eye points.Add(new Point2f(landmarks.points[36].x, landmarks.points[36].y)); // Right corner of the right eye points.Add(new Point2f(landmarks.points[45].x, landmarks.points[45].y)); // Left corner of the mouth points.Add(new Point2f(landmarks.points[48].x, landmarks.points[48].y)); // Right corner of the mouth points.Add(new Point2f(landmarks.points[54].x, landmarks.points[54].y)); }
// 是否吐舌头 private bool GetTongue(FaceLandmarks landmarks, FaceElement mouth) { if (mouth != FaceElement.mouth) #if DEBUG { throw new System.Exception(); } #else { return(false); } #endif Vector2 vertical = originalLandmarks.points[48] - originalLandmarks.points[54]; Vector2 distance = landmarks.points[48] - landmarks.points[54]; if (Vector2.Angle(vertical, distance) > 4.5) { return(true); } return(false); }
private static void runFaceAPI( string _filePath, out FaceRectangle[] _rects, out FaceLandmarks[] _landmarks) { string key = "1cdb412565ae43879ea8133525e89040"; FaceAPI faceAPI = new FaceAPI(key); var detectResult = faceAPI.detectFaces(_filePath); Task.WaitAll(detectResult); if (detectResult.Result) { _rects = faceAPI.getFaceRectangles(); _landmarks = faceAPI.getFaceLandmarks(); } else { _rects = new FaceRectangle[0]; _landmarks = new FaceLandmarks[0]; } }