This commit is contained in:
tanglong 2025-10-16 08:41:11 +08:00
parent 6d248c8892
commit 3d97ce0dc7
3 changed files with 13 additions and 7 deletions

View File

@ -55,10 +55,12 @@ namespace Wpf_AiSportsMicrospace
Unloaded += Home_Unloaded;
Utils.PlayBackgroundMusic("homeprojectselected.mp3", true);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
_mainWin.WebcamClient.StartExtract();
}
private void Home_Unloaded(object sender, RoutedEventArgs e)
{

View File

@ -200,6 +200,9 @@ namespace Wpf_AiSportsMicrospace.Views
int leftWaving = DetectLeftHandRaise(humans);
if (leftWaving == 5)
{
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
_mainWin.WebcamClient.StopExtract();
// 举左手逻辑,例如结束动画或退出
var newPage = new Home();
_mainWin?.SwitchPageWithMaskAnimation(newPage, true);
@ -272,11 +275,16 @@ namespace Wpf_AiSportsMicrospace.Views
x.ImageState = "1";
});
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
_mainWin.WebcamClient.StopExtract();
RankingItemList = _groupJumpRopeContext.UpdateRankList();
ShowRankingBoard(RankingItemList);
Utils.StopBackgroundMusic();
_currentGameState = GameState.Finished;
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
_mainWin.WebcamClient.StartExtract();
}
private DateTime? _raiseStartTime;
@ -374,6 +382,7 @@ namespace Wpf_AiSportsMicrospace.Views
if (humans == null || humans.Count == 0)
return (int)WavingAction.None;
foreach (var human in humans)
{
if (human?.Keypoints == null)
@ -389,7 +398,6 @@ namespace Wpf_AiSportsMicrospace.Views
if (!(xNorm >= 0.44 && xNorm <= 0.57 && yNorm >= 0.81))
continue;
// 获取左手关键点
var leftWrist = human.Keypoints.FirstOrDefault(k => k.Name == "left_wrist");
var leftElbow = human.Keypoints.FirstOrDefault(k => k.Name == "left_elbow");
@ -400,7 +408,7 @@ namespace Wpf_AiSportsMicrospace.Views
const double raiseThreshold = 60; // 举手阈值
// 判断左手是否举起
double verticalRise = leftWrist.Y - leftElbow.Y;
double verticalRise = leftElbow.Y - leftWrist.Y;
if (verticalRise >= raiseThreshold)
{
return (int)WavingAction.RaiseHand; // 一旦检测到左手举起,立即返回
@ -577,7 +585,7 @@ namespace Wpf_AiSportsMicrospace.Views
Height = 71,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(0, 57 * item.Rank, 0, 0)
Margin = new Thickness(0, 69 * item.Rank, 0, 0)
};
var border = new Border
{

View File

@ -110,10 +110,6 @@ namespace Wpf_AiSportsMicrospace.Views
var humans = humanResult?.Humans?.ToList();
if (humans == null || humans.Count == 0)
return;
foreach (var human in humans)
{
_detectQueue.Enqueue(frame.Number, human, null);
}
// 触发全局事件
Application.Current.Dispatcher.BeginInvoke(() =>