代码注释
This commit is contained in:
parent
2b21a37022
commit
b370717838
@ -28,18 +28,12 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
private int _leftWaveCount = 0;
|
||||
private int _rightWaveCount = 0;
|
||||
private const int WaveThreshold = 4;
|
||||
//IPointTracker _leftElbow;
|
||||
//IPointTracker _rightElbow;
|
||||
WebcamClient _webcamClient;
|
||||
|
||||
private DateTime _lastActionTime = DateTime.MinValue;
|
||||
|
||||
private Point? _lastLeftWrist = null;
|
||||
//private Point? _lastRightWrist = null;
|
||||
private DateTime? _raiseStartTime = null;
|
||||
private DateTime? _wristStartTime = null;
|
||||
private double _leftWristDeltaX = 0;
|
||||
//private double _rightWristDeltaX = 0;
|
||||
private bool _firstHandTriggered = false;
|
||||
|
||||
|
||||
@ -47,13 +41,9 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
{
|
||||
_leftTracker = PostureCalculate.CreatePointTracker("left_wrist", 0);
|
||||
_rightTracker = PostureCalculate.CreatePointTracker("right_wrist", 0);
|
||||
//_leftElbow = PostureCalculate.CreatePointTracker("left_elbow", 0);
|
||||
//_rightElbow = PostureCalculate.CreatePointTracker("right_elbow", 0);
|
||||
|
||||
_leftTracker.Amplitude = 0.3f;
|
||||
_rightTracker.Amplitude = 0.3f;
|
||||
//_leftElbow.Amplitude = 0.03f;
|
||||
//_rightElbow.Amplitude = 0.03f;
|
||||
}
|
||||
|
||||
public WebcamClient CreateRTSP()
|
||||
@ -69,6 +59,7 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
|
||||
return _webcamClient;
|
||||
}
|
||||
|
||||
public int VerifyWavingAction(List<Human> humans)
|
||||
{
|
||||
if (humans == null || humans.Count == 0)
|
||||
@ -87,11 +78,6 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
if (!(xNorm >= 0.44 && xNorm <= 0.57 && yNorm >= 0.81))
|
||||
continue;
|
||||
|
||||
//var leftWrist = human.Keypoints.FirstOrDefault(x => x.Name == "left_wrist");
|
||||
//var leftElbow = human.Keypoints.FirstOrDefault(x => x.Name == "left_elbow");
|
||||
//var rightWrist = human.Keypoints.FirstOrDefault(x => x.Name == "right_wrist");
|
||||
//var rightElbow = human.Keypoints.FirstOrDefault(x => x.Name == "right_elbow");
|
||||
|
||||
// --- 右手举手优先 ---
|
||||
int rightHandAction = DetectRightHandRaise(human);
|
||||
if (rightHandAction != (int)WavingAction.None)
|
||||
@ -124,32 +110,6 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
_rightWaveCount = 0; // 只重置右手
|
||||
return (int)WavingAction.RightWave;
|
||||
}
|
||||
|
||||
// --- 左手挥手 ---
|
||||
//if (leftWrist != null && leftElbow != null)
|
||||
//{
|
||||
// int leftResult = DetectHorizontalWave(
|
||||
// new Point(leftWrist.X, leftWrist.Y),
|
||||
// new Point(leftElbow.X, leftElbow.Y),
|
||||
// ref _lastLeftWrist,
|
||||
// ref _leftWristDeltaX,
|
||||
// true);
|
||||
// if (leftResult != (int)WavingAction.None)
|
||||
// return leftResult;
|
||||
|
||||
|
||||
// --- 右手挥手 ---
|
||||
//if (rightWrist != null && rightElbow != null)
|
||||
//{
|
||||
// int rightWaveResult = DetectHorizontalWave(
|
||||
// new Point(rightWrist.X, rightWrist.Y),
|
||||
// new Point(rightElbow.X, rightElbow.Y),
|
||||
// ref _lastRightWrist,
|
||||
// ref _rightWristDeltaX,
|
||||
// false);
|
||||
// if (rightWaveResult != (int)WavingAction.None)
|
||||
// return rightWaveResult;
|
||||
//}
|
||||
}
|
||||
|
||||
return (int)WavingAction.None;
|
||||
@ -162,15 +122,6 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
/// <returns>返回 WavingAction:FirstHand / Raising / RaiseHand / None</returns>
|
||||
public int DetectRightHandRaise(Human human)
|
||||
{
|
||||
//var rightWrist = human.Keypoints.FirstOrDefault(k => k.Name == "right_wrist");
|
||||
//var rightElbow = human.Keypoints.FirstOrDefault(k => k.Name == "right_elbow");
|
||||
|
||||
//if (rightWrist == null || rightElbow == null)
|
||||
// return (int)WavingAction.None;
|
||||
|
||||
//double verticalRise = rightElbow.Y - rightWrist.Y; // 手腕在肘上方 → 正值
|
||||
//const double raiseThreshold = 60; // 举手阈值,可根据实际调整
|
||||
|
||||
var calculator = PostureCalculate.CreateCalculator();
|
||||
var rule = RaiseHand.RaiseRightHand();
|
||||
var pass = calculator.Calculating(human, rule);
|
||||
@ -212,44 +163,5 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
return (int)WavingAction.None;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统一的水平挥手检测
|
||||
/// </summary>
|
||||
private int DetectHorizontalWave(Point wrist, Point elbow, ref Point? lastWrist, ref double deltaX, bool isLeft)
|
||||
{
|
||||
if (lastWrist != null)
|
||||
{
|
||||
double dx = wrist.X - lastWrist.Value.X;
|
||||
double dy = Math.Abs(wrist.Y - lastWrist.Value.Y);
|
||||
|
||||
// 累计水平位移
|
||||
deltaX += dx;
|
||||
|
||||
if (Math.Abs(deltaX) > 40 && dy < 60 && Math.Abs(wrist.Y - elbow.Y) < 60)
|
||||
{
|
||||
deltaX = 0; // 重置
|
||||
if (CheckCooldown())
|
||||
{
|
||||
return isLeft ? (int)WavingAction.LeftWave : (int)WavingAction.RightWave;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastWrist = wrist;
|
||||
return (int)WavingAction.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 冷却防抖(避免重复触发)
|
||||
/// </summary>
|
||||
private bool CheckCooldown(int cooldownMs = 1000)
|
||||
{
|
||||
if ((DateTime.Now - _lastActionTime).TotalMilliseconds < cooldownMs)
|
||||
return false;
|
||||
|
||||
_lastActionTime = DateTime.Now;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user