refact: 使用int重构了PoseLandmarkType
This commit is contained in:
@@ -47,9 +47,9 @@ namespace Models
|
||||
|
||||
public long TimeStamp { get; }
|
||||
|
||||
public PoseLandmark(PoseLandmarkType type, float x, float y, float z, float visibility, long timeStamp)
|
||||
public PoseLandmark(int type, float x, float y, float z, float visibility, long timeStamp)
|
||||
{
|
||||
Type = type;
|
||||
Type = new PoseLandmarkType(type);
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
@@ -66,7 +66,7 @@ namespace Models
|
||||
{
|
||||
var result = new byte[PacketLength];
|
||||
|
||||
BitConverter.GetBytes((int)Type).CopyTo(result, 0);
|
||||
BitConverter.GetBytes(Type.Value).CopyTo(result, 0);
|
||||
BitConverter.GetBytes(X).CopyTo(result, 4);
|
||||
BitConverter.GetBytes(Y).CopyTo(result, 8);
|
||||
BitConverter.GetBytes(Z).CopyTo(result, 12);
|
||||
@@ -84,7 +84,7 @@ namespace Models
|
||||
public static PoseLandmark ValueOf(byte[] bytes)
|
||||
{
|
||||
var result = new PoseLandmark(
|
||||
(PoseLandmarkType)BitConverter.ToInt32(bytes, 0),
|
||||
BitConverter.ToInt32(bytes, 0),
|
||||
BitConverter.ToSingle(bytes, 4),
|
||||
BitConverter.ToSingle(bytes, 8),
|
||||
BitConverter.ToSingle(bytes, 12),
|
||||
@@ -106,7 +106,7 @@ namespace Models
|
||||
|
||||
for (var i = 0; i < bytes.Length; i = i + PacketLength)
|
||||
{
|
||||
var landmark = new PoseLandmark((PoseLandmarkType)BitConverter.ToInt32(bytes, i),
|
||||
var landmark = new PoseLandmark(BitConverter.ToInt32(bytes, i),
|
||||
BitConverter.ToSingle(bytes, i + 4),
|
||||
BitConverter.ToSingle(bytes, i + 8),
|
||||
BitConverter.ToSingle(bytes, i + 12),
|
||||
@@ -127,7 +127,7 @@ namespace Models
|
||||
}
|
||||
else
|
||||
{
|
||||
return Type == landmark.Type
|
||||
return Type.Value == landmark.Type.Value
|
||||
&& Math.Abs(X - landmark.X) < Tolerance
|
||||
&& Math.Abs(Y - landmark.Y) < Tolerance
|
||||
&& Math.Abs(Z - landmark.Z) < Tolerance
|
||||
|
@@ -1,41 +1,70 @@
|
||||
using System;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
//名字
|
||||
public enum PoseLandmarkType
|
||||
{
|
||||
Nose,
|
||||
LeftEyeInner,
|
||||
LeftEye,
|
||||
LeftEyeOuter,
|
||||
RightEyeInner,
|
||||
RightEye,
|
||||
RightEyeOuter,
|
||||
LeftEar,
|
||||
RightEar,
|
||||
MouthLeft,
|
||||
MouthRight,
|
||||
LeftShoulder,
|
||||
RightShoulder,
|
||||
LeftElbow,
|
||||
RightElbow,
|
||||
LeftWrist,
|
||||
RightWrist,
|
||||
LeftPinky,
|
||||
RightPinky,
|
||||
LeftIndex,
|
||||
RightIndex,
|
||||
LeftThumb,
|
||||
RightThumb,
|
||||
LeftHip,
|
||||
RightHip,
|
||||
LeftKnee,
|
||||
RightKnee,
|
||||
LeftAnkle,
|
||||
RightAnkle,
|
||||
LeftHeel,
|
||||
RightHeel,
|
||||
LeftFootIndex,
|
||||
RightFootIndex,
|
||||
MaxValue
|
||||
}
|
||||
public struct PoseLandmarkType
|
||||
{
|
||||
public const int Nose = 0;
|
||||
public const int LeftEyeInner = 1;
|
||||
public const int LeftEye = 2;
|
||||
public const int LeftEyeOuter = 3;
|
||||
public const int RightEyeInner = 4;
|
||||
public const int RightEye = 5;
|
||||
public const int RightEyeOuter = 6;
|
||||
public const int LeftEar = 7;
|
||||
public const int RightEar = 8;
|
||||
public const int MouthLeft = 9;
|
||||
public const int MouthRight = 10;
|
||||
public const int LeftShoulder = 11;
|
||||
public const int RightShoulder = 12;
|
||||
public const int LeftElbow = 13;
|
||||
public const int RightElbow = 14;
|
||||
public const int LeftWrist = 15;
|
||||
public const int RightWrist = 16;
|
||||
public const int LeftPinky = 17;
|
||||
public const int RightPinky = 18;
|
||||
public const int LeftIndex = 19;
|
||||
public const int RightIndex = 20;
|
||||
public const int LeftThumb = 21;
|
||||
public const int RightThumb = 22;
|
||||
public const int LeftHip = 23;
|
||||
public const int RightHip = 24;
|
||||
public const int LeftKnee = 25;
|
||||
public const int RightKnee = 26;
|
||||
public const int LeftAnkle = 27;
|
||||
public const int RightAnkle = 28;
|
||||
public const int LeftHeel = 29;
|
||||
public const int RightHeel = 30;
|
||||
public const int LeftFootIndex = 31;
|
||||
public const int RightFootIndex = 32;
|
||||
public const int MaxValue = 33;
|
||||
|
||||
public int Value { get; }
|
||||
|
||||
public PoseLandmarkType(int value)
|
||||
{
|
||||
if (value >= MaxValue)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(value));
|
||||
}
|
||||
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Value.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -49,12 +49,12 @@ namespace Models
|
||||
private readonly Queue<PoseLandmark> _landmarkQueue;
|
||||
|
||||
public PoseTransform(
|
||||
PoseLandmarkType type,
|
||||
int type,
|
||||
int averageLength = 5
|
||||
)
|
||||
{
|
||||
MediaPipeName = type;
|
||||
UnityName = GetRelatedBone(type);
|
||||
MediaPipeName = new PoseLandmarkType(type);
|
||||
UnityName = GetRelatedBone(MediaPipeName);
|
||||
AveragePos = new Vector3();
|
||||
Parent = new List<PoseLandmarkType>();
|
||||
PreviousQuaternion = new Quaternion();
|
||||
@@ -108,7 +108,7 @@ namespace Models
|
||||
/// <returns>关联骨骼的种类</returns>
|
||||
private static HumanBodyBones GetRelatedBone(PoseLandmarkType type)
|
||||
{
|
||||
switch (type)
|
||||
switch (type.Value)
|
||||
{
|
||||
case PoseLandmarkType.LeftHip:
|
||||
return HumanBodyBones.LeftUpperLeg;
|
||||
|
Reference in New Issue
Block a user