143 lines
4.2 KiB
C#
143 lines
4.2 KiB
C#
using OpenCVForUnity.CoreModule;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
|
||
public static class YogaConfig
|
||
{
|
||
public static readonly Dictionary<string, int> BODY_PARTS = new Dictionary<string, int>()
|
||
{
|
||
{ "Nose", 0 }, //{ "Nose", 0 },
|
||
{ "Neck", 1 }, //{ "Neck", 1 },
|
||
{ "LShoulder", 2 }, //{ "RShoulder", 2 },
|
||
{ "LElbow", 3 }, //{ "RElbow", 3 },
|
||
{ "LWrist", 4 }, //{ "RWrist", 4 },
|
||
{ "RShoulder",5 }, //{ "LShoulder",5 },
|
||
{ "RElbow", 6 }, //{ "LElbow", 6 },
|
||
{ "RWrist", 7 }, //{ "LWrist", 7 },
|
||
{ "LHip", 8 }, //{ "RHip", 8 },
|
||
{ "LKnee", 9 }, //{ "RKnee", 9 },
|
||
{ "LAnkle", 10 }, //{ "RAnkle", 10 },
|
||
{ "RHip", 11 }, //{ "LHip", 11 },
|
||
{ "RKnee", 12 }, //{ "LKnee", 12 },
|
||
{ "RAnkle", 13 }, //{ "LAnkle", 13 },
|
||
{ "LEye", 14 }, //{ "REye", 14 },
|
||
{ "REye", 15 }, //{ "LEye", 15 },
|
||
{ "LEar", 16 }, //{ "REar", 16 },
|
||
{ "REar", 17 }, //{ "LEar", 17 },
|
||
{ "Background", 18 } //{ "Background", 18 }
|
||
};
|
||
|
||
public static readonly string[,] POSE_PAIRS = new string[,]
|
||
{
|
||
{ "Neck", "RShoulder" },
|
||
{ "Neck", "LShoulder" },
|
||
{ "RShoulder", "RElbow" },
|
||
{ "RElbow", "RWrist" },
|
||
{ "LShoulder", "LElbow" },
|
||
{ "LElbow", "LWrist" },
|
||
{ "Neck", "RHip" },
|
||
{ "RHip", "RKnee" },
|
||
{ "RKnee", "RAnkle" },
|
||
{ "Neck", "LHip" },
|
||
{ "LHip", "LKnee" },
|
||
{ "LKnee", "LAnkle" },
|
||
{ "Neck", "Nose" },
|
||
{ "Nose", "REye" },
|
||
{ "REye", "REar" },
|
||
{ "Nose", "LEye" },
|
||
{ "LEye", "LEar" }
|
||
};
|
||
|
||
public const float InWidth = 256;
|
||
public const float InHeight = 256;
|
||
public const float InScale = 1.0f / 255;
|
||
|
||
public static readonly Dictionary<ModelType, string> MODEL_PATHS = new Dictionary<ModelType, string>()
|
||
{
|
||
{ModelType.OpenPose,"OpenCVForUnity/dnn/lightweight_pose_estimation_201912.onnx" },
|
||
//{"","" },
|
||
};
|
||
|
||
public static int index(this string tagName)
|
||
{
|
||
if (!BODY_PARTS.ContainsKey(tagName))
|
||
{
|
||
Debug.LogError("TagName is not exist");
|
||
return -1;
|
||
}
|
||
return BODY_PARTS[tagName];
|
||
}
|
||
|
||
public static string tagName(this int index)
|
||
{
|
||
if (index < 0 || index >= BODY_PARTS.Count)
|
||
{
|
||
Debug.LogError("Index is not exist");
|
||
return "";
|
||
}
|
||
return BODY_PARTS.FirstOrDefault(x => x.Value == index).Key;
|
||
}
|
||
|
||
public static Point p(this List<Point> points, string tagName)
|
||
{
|
||
if (!BODY_PARTS.ContainsKey(tagName))
|
||
{
|
||
Debug.LogError("TagName is not exist");
|
||
return new Point(-1, -1);
|
||
}
|
||
|
||
return points[BODY_PARTS[tagName]];
|
||
}
|
||
|
||
public static Point p(this string tagName, List<Point> points)
|
||
{
|
||
if (!BODY_PARTS.ContainsKey(tagName))
|
||
{
|
||
Debug.LogError("TagName is not exist");
|
||
return new Point(-1, -1);
|
||
}
|
||
|
||
if (points == null)
|
||
return new Point(-1, -1);
|
||
|
||
return points[BODY_PARTS[tagName]];
|
||
}
|
||
|
||
public static Vector2 vector(this string tagName, List<Point> points)
|
||
{
|
||
if (!BODY_PARTS.ContainsKey(tagName))
|
||
{
|
||
Debug.LogError("TagName is not exist");
|
||
return new Vector2(-1, -1);
|
||
}
|
||
|
||
if (points == null)
|
||
return new Vector2(-1, -1);
|
||
|
||
return new Vector2((float)points[BODY_PARTS[tagName]].x, (float)points[BODY_PARTS[tagName]].y);
|
||
}
|
||
|
||
public static bool IsValid(this string partName, List<Point> points)
|
||
{
|
||
if (points == null || points.Count == 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
var point = points[BODY_PARTS[partName]];
|
||
if (point == new Point(-1, -1))
|
||
{
|
||
Debug.Log($"{partName}<7D><><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD>");
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
public static readonly double[] InMean = new double[] { 128.0, 128.0, 128.0 };
|
||
}
|
||
|
||
|