diff --git a/Wpf_AiSportsMicrospace/Common/SportOperate.cs b/Wpf_AiSportsMicrospace/Common/SportOperate.cs index bccaa87..902cf0a 100644 --- a/Wpf_AiSportsMicrospace/Common/SportOperate.cs +++ b/Wpf_AiSportsMicrospace/Common/SportOperate.cs @@ -39,6 +39,7 @@ namespace Wpf_AiSportsMicrospace.Common private DateTime? _wristStartTime = null; private bool _firstHandTriggered = false; + private double? _lastRightWristX = null; private double? _lastRightWristY = null; private DateTime _rightRaiseGuardUntil = DateTime.MinValue; @@ -180,7 +181,7 @@ namespace Wpf_AiSportsMicrospace.Common bool wristAboveShoulder = wrist.Y <= shoulder.Y - 20; bool wristAboveElbow = wrist.Y <= elbow.Y - 20; - bool closeToBody = Math.Abs(wrist.X - shoulder.X) <= 260; + bool closeToBody = Math.Abs(wrist.X - shoulder.X) <= 220; return wristAboveShoulder && wristAboveElbow && closeToBody; } @@ -188,21 +189,26 @@ namespace Wpf_AiSportsMicrospace.Common private bool IsRightHandRaisingUp(Human human) { var wrist = human.Keypoints.FirstOrDefault(k => k.Name == "right_wrist"); + var elbow = human.Keypoints.FirstOrDefault(k => k.Name == "right_elbow"); var shoulder = human.Keypoints.FirstOrDefault(k => k.Name == "right_shoulder"); - if (wrist == null || shoulder == null) + if (wrist == null || shoulder == null || elbow == null) { + _lastRightWristX = null; _lastRightWristY = null; return false; } bool movingUp = _lastRightWristY.HasValue && _lastRightWristY.Value - wrist.Y >= 45; - bool closeToBody = Math.Abs(wrist.X - shoulder.X) <= 320; + bool movingSideways = _lastRightWristX.HasValue && Math.Abs(wrist.X - _lastRightWristX.Value) >= 80; + bool closeToBody = Math.Abs(wrist.X - shoulder.X) <= 220; bool highEnough = wrist.Y <= shoulder.Y + 120; + bool wristAboveElbow = wrist.Y <= elbow.Y - 20; + _lastRightWristX = wrist.X; _lastRightWristY = wrist.Y; - if (movingUp && closeToBody && highEnough) + if (movingUp && !movingSideways && closeToBody && highEnough && wristAboveElbow) { GuardWavesForRaise(); return true;