diff --git a/Wpf_AiSportsMicrospace/Common/SportOperate.cs b/Wpf_AiSportsMicrospace/Common/SportOperate.cs index 957db19..bccaa87 100644 --- a/Wpf_AiSportsMicrospace/Common/SportOperate.cs +++ b/Wpf_AiSportsMicrospace/Common/SportOperate.cs @@ -39,6 +39,8 @@ namespace Wpf_AiSportsMicrospace.Common private DateTime? _wristStartTime = null; private bool _firstHandTriggered = false; + private double? _lastRightWristY = null; + private DateTime _rightRaiseGuardUntil = DateTime.MinValue; public SportOperate() @@ -121,10 +123,11 @@ namespace Wpf_AiSportsMicrospace.Common if (rightHandAction != (int)WavingAction.None) { ResetWaveCounts(); + GuardWavesForRaise(); return rightHandAction; } - if (IsRightHandRaiseIntent(target)) + if (IsRightHandRaiseIntent(target) || IsRightHandRaisingUp(target) || DateTime.UtcNow < _rightRaiseGuardUntil) { ResetWaveCounts(); return (int)WavingAction.None; @@ -158,6 +161,11 @@ namespace Wpf_AiSportsMicrospace.Common _rightWaveCount = 0; } + private void GuardWavesForRaise() + { + _rightRaiseGuardUntil = DateTime.UtcNow.AddMilliseconds(900); + } + private static bool IsRightHandRaiseIntent(Human human) { var wrist = human.Keypoints.FirstOrDefault(k => k.Name == "right_wrist"); @@ -177,6 +185,32 @@ namespace Wpf_AiSportsMicrospace.Common return wristAboveShoulder && wristAboveElbow && closeToBody; } + private bool IsRightHandRaisingUp(Human human) + { + var wrist = human.Keypoints.FirstOrDefault(k => k.Name == "right_wrist"); + var shoulder = human.Keypoints.FirstOrDefault(k => k.Name == "right_shoulder"); + + if (wrist == null || shoulder == null) + { + _lastRightWristY = null; + return false; + } + + bool movingUp = _lastRightWristY.HasValue && _lastRightWristY.Value - wrist.Y >= 45; + bool closeToBody = Math.Abs(wrist.X - shoulder.X) <= 320; + bool highEnough = wrist.Y <= shoulder.Y + 120; + + _lastRightWristY = wrist.Y; + + if (movingUp && closeToBody && highEnough) + { + GuardWavesForRaise(); + return true; + } + + return false; + } + /// /// 优化后的右手举手检测 ///