using OpenCVForUnity.CoreModule; using System; using System.Collections.Generic; using UnityEngine; public class HeadTurnUp : PoseBase { public override Vector2 GetBasicVectorDirection(List startPoint, List endPoint) { List vectors = new List(); //必要点位 Nose Neck //计算鼻子到头颈矢量 return GetAverageVector(startPoint, endPoint, "Nose"); } protected override bool IsMovePoint(string tagName) { return "Nose" == tagName || "REye" == tagName || "LEye" == tagName || "REar" == tagName || "LEar" == tagName; } public override void ValidationMovement(Vector2 distance, TimeSpan totalTimeSpan, int level) { var angle = Vector2.SignedAngle(Vector2.up, distance); LogPrint.Log($"Angle:{angle}", PrintLevel.Normal); if (MathF.Abs(angle) < 10) EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10° else EventManager.Instance.Dispatch(YogaEventType.Action_Fail); if (level < 1) return; LogPrint.Log($"distance x:{distance.x}, y:{distance.y}, magnitude:{distance.magnitude}", PrintLevel.Normal); if (distance.magnitude > 5f || distance.magnitude < 0.1f) EventManager.Instance.Dispatch(YogaEventType.Action_MoveDistanceNotAccurate); else EventManager.Instance.Dispatch(YogaEventType.Action_MoveDistanceExactly); if (level < 2) return; var speed = distance.magnitude / totalTimeSpan.TotalSeconds; LogPrint.Log($"speed:{speed}", PrintLevel.Normal); if (speed > 0.5f) EventManager.Instance.Dispatch(YogaEventType.Action_SpeedTooFast); //速度语音提示 else if (speed < 0.1f) EventManager.Instance.Dispatch(YogaEventType.Action_SpeedTooSlow); //速度语音提示 } public override void ExcellenceEstimate(List<(TimeSpan, Vector2)> frameData, Vector2 distance, TimeSpan totalTimeSpan) { throw new NotImplementedException(); } }