63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using OpenCVForUnity.CoreModule;
|
|
using OpenCVForUnity.ImgprocModule;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public abstract class PoseBase
|
|
{
|
|
public abstract bool CheckPose(List<Point> points);
|
|
|
|
public Dictionary<string, Point> GetVaildPoints(List<Point> points, List<string> pointName)
|
|
{
|
|
var retVal = new Dictionary<string, Point>();
|
|
|
|
foreach (var name in pointName)
|
|
{
|
|
if (points[YogaConfig.BODY_PARTS[name]] != new Point(-1, -1))
|
|
{
|
|
retVal.Add(name, points[YogaConfig.BODY_PARTS[name]]);
|
|
}
|
|
}
|
|
return retVal;
|
|
}
|
|
|
|
public bool CheckPoint(List<Point> points, string partName)
|
|
{
|
|
var point = points[YogaConfig.BODY_PARTS[partName]];
|
|
if (point == new Point(-1, -1))
|
|
{
|
|
//Debug.Log($"{partName}不在画面中");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//motion check
|
|
public bool CheckMotion(List<Point> points, string partName, double threshold)
|
|
{
|
|
var point = points[YogaConfig.BODY_PARTS[partName]];
|
|
if (point == new Point(-1, -1))
|
|
{
|
|
//Debug.Log($"{partName}不在画面中");
|
|
return false;
|
|
}
|
|
|
|
var lastPoint = YogaManager.Instance.Points[YogaConfig.BODY_PARTS[partName]];
|
|
if (lastPoint == new Point(-1, -1))
|
|
{
|
|
YogaManager.Instance.Points[YogaConfig.BODY_PARTS[partName]] = point;
|
|
return false;
|
|
}
|
|
|
|
var distance = Math.Sqrt(Math.Pow(point.x - lastPoint.x, 2) + Math.Pow(point.y - lastPoint.y, 2));
|
|
if (distance > threshold)
|
|
{
|
|
YogaManager.Instance.Points[YogaConfig.BODY_PARTS[partName]] = point;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |