Health/Assets/Scripts/YogaConfig.cs

145 lines
4.4 KiB
C#
Raw Normal View History

2023-11-12 15:09:33 +00:00
using OpenCVForUnity.CoreModule;
2023-11-07 13:55:35 +00:00
using System.Collections;
using System.Collections.Generic;
2023-11-13 02:53:34 +00:00
using System.Linq;
2023-11-07 13:55:35 +00:00
using UnityEngine;
2023-11-12 15:09:33 +00:00
public static class YogaConfig
2023-11-07 13:55:35 +00:00
{
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" },
2023-11-15 17:23:16 +00:00
{ModelType.MediapipePersonDetect,"OpenCVForUnity/dnn/person_detection_mediapipe_2023mar.onnx" },
{ModelType.MediapipePose,"OpenCVForUnity/dnn/pose_estimation_mediapipe_2023mar.onnx" },
2023-11-07 13:55:35 +00:00
//{"","" },
};
2023-11-12 15:09:33 +00:00
public static int index(this string tagName)
{
if (!BODY_PARTS.ContainsKey(tagName))
{
2023-11-24 05:13:10 +00:00
LogPrint.Error("TagName is not exist");
2023-11-12 15:09:33 +00:00
return -1;
}
return BODY_PARTS[tagName];
}
2023-11-13 02:53:34 +00:00
public static string tagName(this int index)
{
if (index < 0 || index >= BODY_PARTS.Count)
{
2023-11-24 05:13:10 +00:00
LogPrint.Error("Index is not exist");
2023-11-13 02:53:34 +00:00
return "";
}
return BODY_PARTS.FirstOrDefault(x => x.Value == index).Key;
}
2023-11-12 15:09:33 +00:00
public static Point p(this List<Point> points, string tagName)
{
if (!BODY_PARTS.ContainsKey(tagName))
{
2023-11-24 05:13:10 +00:00
LogPrint.Error("TagName is not exist");
2023-11-12 15:09:33 +00:00
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))
{
2023-11-24 05:13:10 +00:00
LogPrint.Error("TagName is not exist");
2023-11-12 15:09:33 +00:00
return new Point(-1, -1);
}
if (points == null)
return new Point(-1, -1);
return points[BODY_PARTS[tagName]];
}
2023-11-13 02:53:34 +00:00
public static Vector2 vector(this string tagName, List<Point> points)
{
if (!BODY_PARTS.ContainsKey(tagName))
{
2023-11-24 05:13:10 +00:00
LogPrint.Error("TagName is not exist");
2023-11-13 02:53:34 +00:00
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);
}
2023-11-12 15:09:33 +00:00
public static bool IsValid(this string partName, List<Point> points)
{
2023-11-13 02:53:34 +00:00
if (points == null || points.Count == 0)
{
2023-11-12 15:09:33 +00:00
return false;
2023-11-13 02:53:34 +00:00
}
2023-11-12 15:09:33 +00:00
var point = points[BODY_PARTS[partName]];
if (point == new Point(-1, -1))
{
2023-11-24 05:13:10 +00:00
LogPrint.Log($"{partName}<7D><><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD>");
2023-11-12 15:09:33 +00:00
return false;
}
return true;
}
2023-11-07 13:55:35 +00:00
public static readonly double[] InMean = new double[] { 128.0, 128.0, 128.0 };
}
2023-11-15 08:10:56 +00:00