using OpenCVForUnity.CoreModule; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public static class YogaConfig { public static readonly Dictionary BODY_PARTS = new Dictionary() { { "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 MODEL_PATHS = new Dictionary() { {ModelType.OpenPose,"OpenCVForUnity/dnn/lightweight_pose_estimation_201912.onnx" }, {ModelType.MediapipePersonDetect,"OpenCVForUnity/dnn/person_detection_mediapipe_2023mar.onnx" }, {ModelType.MediapipePose,"OpenCVForUnity/dnn/pose_estimation_mediapipe_2023mar.onnx" }, //{"","" }, }; public static int index(this string tagName) { if (!BODY_PARTS.ContainsKey(tagName)) { LogPrint.Error("TagName is not exist"); return -1; } return BODY_PARTS[tagName]; } public static string tagName(this int index) { if (index < 0 || index >= BODY_PARTS.Count) { LogPrint.Error("Index is not exist"); return ""; } return BODY_PARTS.FirstOrDefault(x => x.Value == index).Key; } public static Point p(this List points, string tagName) { if (!BODY_PARTS.ContainsKey(tagName)) { LogPrint.Error("TagName is not exist"); return new Point(-1, -1); } return points[BODY_PARTS[tagName]]; } public static Point p(this string tagName, List points) { if (!BODY_PARTS.ContainsKey(tagName)) { LogPrint.Error("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 points) { if (!BODY_PARTS.ContainsKey(tagName)) { LogPrint.Error("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 points) { if (points == null || points.Count == 0) { return false; } var point = points[BODY_PARTS[partName]]; if (point == new Point(-1, -1)) { LogPrint.Log($"{partName}²»ÔÚ»­ÃæÖÐ"); return false; } return true; } public static readonly double[] InMean = new double[] { 128.0, 128.0, 128.0 }; }