Health/Assets/Scripts/PoseCheck/HeadTurnDown.cs

64 lines
2.4 KiB
C#
Raw Normal View History

2023-11-10 07:17:23 +00:00
using OpenCVForUnity.CoreModule;
using System;
2023-11-10 07:17:23 +00:00
using System.Collections.Generic;
using UnityEngine;
2023-11-10 07:17:23 +00:00
public class HeadTurnDown : PoseBase
{
public override Vector2 GetBasicVectorDirection(List<Point> startPoint, List<Point> endPoint)
2023-11-10 07:17:23 +00:00
{
List<Vector2> vectors = new List<Vector2>();
//必要点位 Nose Neck
//计算鼻子到头颈矢量
return GetAverageVector(startPoint, endPoint, "Nose");
}
2023-11-13 02:53:34 +00:00
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)
{
2023-11-25 20:52:27 +00:00
if (totalTimeSpan.TotalMilliseconds / 1000 < 0.05f)
{
LogPrint.Error("TimeSpan too short");
return;
}
var angle = Vector2.SignedAngle(Vector2.down, distance);
LogPrint.Log($"Angle:{angle}", PrintLevel.Normal);
2023-11-26 10:14:22 +00:00
if (MathF.Abs(angle) < 50 && distance.magnitude > 5f)
EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10°
else
2023-11-25 20:52:27 +00:00
{
2023-11-26 10:14:22 +00:00
LogPrint.Warning($"Angle:{angle}, magnitude:{distance.magnitude}", PrintLevel.Important);
EventManager.Instance.Dispatch(YogaEventType.Action_Fail);
2023-11-25 20:52:27 +00:00
return;
}
2023-11-13 02:53:34 +00:00
if (level < 1)
return;
2023-11-13 02:53:34 +00:00
LogPrint.Log($"distance x:{distance.x}, y:{distance.y}, magnitude:{distance.magnitude}", PrintLevel.Normal);
2023-11-25 20:52:27 +00:00
if (distance.magnitude > 80f || distance.magnitude < 20f)
EventManager.Instance.Dispatch(YogaEventType.Action_MoveDistanceNotAccurate);
else
EventManager.Instance.Dispatch(YogaEventType.Action_MoveDistanceExactly);
2023-11-13 02:53:34 +00:00
if (level < 2)
return;
var speed = distance.magnitude / totalTimeSpan.TotalSeconds;
LogPrint.Log($"speed:{speed}", PrintLevel.Normal);
2023-11-25 20:52:27 +00:00
if (speed > 20f)
EventManager.Instance.Dispatch(YogaEventType.Action_SpeedTooFast); //速度语音提示
2023-11-25 20:52:27 +00:00
else if (speed < 8f)
EventManager.Instance.Dispatch(YogaEventType.Action_SpeedTooSlow); //速度语音提示
}
public override void ExcellenceEstimate(List<(TimeSpan, Vector2)> frameData, Vector2 distance, TimeSpan totalTimeSpan)
{
throw new NotImplementedException();
2023-11-10 07:17:23 +00:00
}
}