using SopHelper.Engine.Common; namespace SopHelper.Engine.Inference; internal static class HandednessDecoder { /// /// 当前 legacy MediaPipe ONNX 模型按镜像输入定义左右手;采集管线未镜像, /// 因此将模型输出取反,统一为操作者实际右手的概率后再做跨帧稳定。 /// https://chuoling.github.io/mediapipe/solutions/hands.html#multi_handedness /// public static void ApplyUnmirrored(Hand hand, float modelRightProbability) { if (!float.IsFinite(modelRightProbability) || modelRightProbability is < 0 or > 1) { hand.RightHandProbability = null; hand.HandType = HandType.Unknown; return; } var actualRightProbability = 1f - modelRightProbability; hand.RightHandProbability = actualRightProbability; hand.HandType = actualRightProbability >= 0.5f ? HandType.Right : HandType.Left; } }