Health/Assets/Scripts/PoseCheck/HoldPosition.cs

50 lines
1.6 KiB
C#

using OpenCVForUnity.CoreModule;
using System;
using System.Collections.Generic;
using UnityEngine;
public class HoldPosition : PoseBase
{
public override Vector2 GetBasicVectorDirection(List<Point> startPoint, List<Point> endPoint)
{
List<Vector2> vectors = new List<Vector2>();
//必要点位 Nose Neck
//计算鼻子到头颈矢量
//return GetAverageVector(startPoint, endPoint, "Nose");
return GetTwoPointAverageVector(startPoint, endPoint, "Nose", "Neck");
}
protected override bool IsMovePoint(string tagName)
{
return "Nose" == tagName || "REye" == tagName || "LEye" == tagName || "REar" == tagName || "LEar" == tagName;
}
public override bool? MovementValidation(Vector2 distance, TimeSpan totalTimeSpan, int level)
{
if (totalTimeSpan.TotalMilliseconds / 1000 < 0.05f)
{
LogPrint.Error("TimeSpan too short");
return null;
}
//保持姿势不发生移动
if (distance.magnitude < 10f)//允许一定误差
{
//EventManager.Instance.Dispatch(YogaEventType.Action_Success);
return true;
}
else
{
LogPrint.Warning($"Hold Position, magnitude:{distance.magnitude}", PrintLevel.Important);
//EventManager.Instance.Dispatch(YogaEventType.Action_Fail);
return false;
}
}
public override void ExcellenceEstimate(List<(TimeSpan, Vector2)> frameData, Vector2 distance, TimeSpan totalTimeSpan)
{
throw new NotImplementedException();
}
}