ai优化8
This commit is contained in:
parent
621f2c348b
commit
e57aa384b4
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 优化后的右手举手检测
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user