diff --git a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs index e471f96..4ce9c30 100644 --- a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs @@ -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) { diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs index ebc0203..128e024 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs @@ -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 { diff --git a/Wpf_AiSportsMicrospace/Views/Main.xaml.cs b/Wpf_AiSportsMicrospace/Views/Main.xaml.cs index 0c62839..6897fc1 100644 --- a/Wpf_AiSportsMicrospace/Views/Main.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/Main.xaml.cs @@ -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(() =>