feat: 添加PoseTransformHandler接口 提供结欢过滤方法的功能

添加直接返回和平均过滤两种过滤方法
This commit is contained in:
2023-03-01 22:07:39 +08:00
parent aaba183c48
commit 2d2adefb96
11 changed files with 114 additions and 47 deletions

View File

@@ -3,7 +3,7 @@ using System;
namespace Models
{
//名字
public struct PoseLandmarkType
public readonly struct PoseLandmarkType
{
public const int Nose = 0;
public const int LeftEyeInner = 1;

View File

@@ -1,7 +1,6 @@
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Collections;
using Utils;
namespace Models
{
@@ -23,12 +22,12 @@ namespace Models
/// <summary>
/// 取平均的长度
/// </summary>
public static int AverageLength;
public static int AverageLength = 3;
/// <summary>
/// 取平均之后的结果
/// </summary>
public Vector3 AveragePos;
public Vector3 ResultPosition => _transformHandler.GetResultPosition();
/// <summary>
/// 节点的父节点列表
@@ -44,56 +43,26 @@ namespace Models
/// 骨骼节点的当前角度
/// </summary>
public Quaternion CurrentQuaternion;
private int _count;
private readonly Queue<PoseLandmark> _landmarkQueue;
private readonly IPoseTransformHandler _transformHandler;
public PoseTransform(
int type,
int averageLength = 5
IPoseTransformHandler handler
)
{
MediaPipeName = new PoseLandmarkType(type);
UnityName = GetRelatedBone(MediaPipeName);
AveragePos = new Vector3();
Parent = new List<PoseLandmarkType>();
PreviousQuaternion = new Quaternion();
CurrentQuaternion = new Quaternion();
AverageLength = averageLength;
_count = 0;
_landmarkQueue = new Queue<PoseLandmark>();
_transformHandler = handler;
}
public static void UpdatePosition(ref PoseTransform pose, PoseLandmark landmark)
{
if (pose._count < AverageLength)
{
pose._landmarkQueue.Enqueue(landmark);
pose._count++;
}
else
{
pose._landmarkQueue.Dequeue();
pose._landmarkQueue.Enqueue(landmark);
var sum = new Vector3();
var parentsum = new Vector3(0f,0f,0f);
foreach (var poseLandmark in pose._landmarkQueue)
{
sum += new Vector3(poseLandmark.X, poseLandmark.Y, poseLandmark.Z);
}
pose.AveragePos = sum / AverageLength;
//pose.CurrentQuaternion = Quaternion.LookRotation(pose.AveragePos - parentsum).normalized;
}
pose._transformHandler.ReceivePoseLandmark(landmark);
}
public static void CalculateRotation(ref PoseTransform poseTransform, PoseLandmark landmark)