From e57aa384b4955216b1ddc6ccc6e8af87f5510b7e Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Wed, 13 May 2026 11:49:14 +0800 Subject: [PATCH] =?UTF-8?q?ai=E4=BC=98=E5=8C=968?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wpf_AiSportsMicrospace/Common/SportOperate.cs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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; + } + /// /// 优化后的右手举手检测 ///