From 9bed3d200bd74c1f53eaebc9b261b8e86149d274 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Wed, 11 Mar 2026 14:05:00 +0800 Subject: [PATCH] 4444 --- Wpf_AiSportsMicrospace/Common/SportOperate.cs | 11 ------ .../MyUserControl/CoverFlowControl.xaml.cs | 37 +------------------ Wpf_AiSportsMicrospace/Views/Home.xaml.cs | 29 +++++---------- .../Views/JumpRope/GroupJumpRope.xaml.cs | 3 +- .../Views/JumpRope/MusicJumpRope.xaml.cs | 1 + .../Views/SquatFu/WhackAMole.xaml.cs | 2 +- 6 files changed, 15 insertions(+), 68 deletions(-) diff --git a/Wpf_AiSportsMicrospace/Common/SportOperate.cs b/Wpf_AiSportsMicrospace/Common/SportOperate.cs index 24a6af1..3c95b08 100644 --- a/Wpf_AiSportsMicrospace/Common/SportOperate.cs +++ b/Wpf_AiSportsMicrospace/Common/SportOperate.cs @@ -155,11 +155,9 @@ namespace Wpf_AiSportsMicrospace.Common var now = DateTime.Now; - //_raiseStartTime ??= now; _wristStartTime ??= now; double wristElapsed = (now - _wristStartTime.Value).TotalSeconds; - //double raiseElapsed = (now - _raiseStartTime.Value).TotalSeconds; // 第一步:触发倒计时 / 举手开始 if (!_firstHandTriggered && wristElapsed >= 0) @@ -168,15 +166,6 @@ namespace Wpf_AiSportsMicrospace.Common return (int)WavingAction.FirstHand; } - //if (wristElapsed <= 3) - //{ - // return (int)WavingAction.Raising; - //} - - //_wristStartTime = null; - //_firstHandTriggered = false; - //return (int)WavingAction.RaiseHand; - // 第二步:举手完成 if (wristElapsed >= 3) { diff --git a/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml.cs b/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml.cs index c57c8ba..518f93f 100644 --- a/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml.cs +++ b/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml.cs @@ -45,10 +45,6 @@ namespace Wpf_AiSportsMicrospace.MyUserControl Images[i].IsSelected = i == _selectedIndex; UpdateLayoutWithAnimation(); - - // 启动进度条动画 - //var current = Images[_selectedIndex]; - //StartProgress(current); } } @@ -58,16 +54,6 @@ namespace Wpf_AiSportsMicrospace.MyUserControl InitializeComponent(); DataContext = this; Loaded += (s, e) => UpdateLayoutWithAnimation(true); - - //var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(5) }; - //timer.Tick += (s, e) => - //{ - // if (Images.Count == 0) return; - // var current = Images[_selectedIndex]; - // if (current.Progress < 1) - // current.Progress += 0.01; // 调整速度 - //}; - //timer.Start(); } private EventHandler _renderHandler; @@ -275,32 +261,13 @@ namespace Wpf_AiSportsMicrospace.MyUserControl public async void SlideLeft() { StopProgress(); - - await Dispatcher.InvokeAsync(async () => - { - while (ItemsHost.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) - await Task.Delay(10); - - // 强制刷新布局 - ItemsHost.UpdateLayout(); - - SelectedIndex++; - }, DispatcherPriority.ContextIdle); + SelectedIndex++; } public async void SlideRight() { StopProgress(); - - await Dispatcher.InvokeAsync(async () => - { - while (ItemsHost.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) - await Task.Delay(10); - - ItemsHost.UpdateLayout(); - - SelectedIndex--; - }, DispatcherPriority.ContextIdle); + SelectedIndex--; } } } \ No newline at end of file diff --git a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs index cfc7a74..68ec8d8 100644 --- a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs @@ -97,8 +97,7 @@ namespace Wpf_AiSportsMicrospace { if (!IsGestureActive) return; // 手势识别已停止,直接返回 - //var human = humans.FirstOrDefault(); - //if (human == null) return; + if (humans == null || humans.Count == 0) return; // 检测挥手动作 var wavingaction = _mainWin.SportOperate.VerifyRightWavingAction(humans); @@ -106,23 +105,15 @@ namespace Wpf_AiSportsMicrospace switch (wavingaction) { case (int)WavingAction.LeftWave: // 左手挥动 - //Application.Current.Dispatcher.Invoke(() => coverFlow.SlideRight()); - - - coverFlow.SlideRight(); + Application.Current.Dispatcher.BeginInvoke(() => coverFlow.SlideRight()); break; case (int)WavingAction.RightWave: // 右手挥动 - //Application.Current.Dispatcher.Invoke(() => coverFlow.SlideLeft()); - coverFlow.SlideLeft(); + Application.Current.Dispatcher.BeginInvoke(() => coverFlow.SlideLeft()); break; case (int)WavingAction.FirstHand: // 举手开始 - Dispatcher.InvokeAsync(() => - { - coverFlow.StartSelectedProgress(); - }, DispatcherPriority.Render); - //RouterGoNew(); + Application.Current.Dispatcher.BeginInvoke(() => coverFlow.StartSelectedProgress()); break; case (int)WavingAction.Raising: // 举手中,实时更新进度 @@ -130,14 +121,12 @@ namespace Wpf_AiSportsMicrospace case (int)WavingAction.RaiseHand: // 举手完成 // 设置标记,停止后续手势识别 - //IsGestureActive = false; - RouterGoNew(); - - //coverFlow.ProgressCompleted += CoverFlow_ProgressCompleted; + IsGestureActive = false; + coverFlow.ProgressCompleted += CoverFlow_ProgressCompleted; break; default: // 没有动作 → 取消进度 - //Application.Current.Dispatcher.BeginInvoke(() => coverFlow.CancelSelectedProgress()); + Application.Current.Dispatcher.BeginInvoke(() => coverFlow.CancelSelectedProgress()); break; } } @@ -147,8 +136,8 @@ namespace Wpf_AiSportsMicrospace // 停止抽帧线程/释放资源 try { - //_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; - //_mainWin.WebcamClient.StopExtract(); + _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; + _mainWin.WebcamClient.StopExtract(); RouterGoNew(); } catch (Exception ex) diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs index 1cf4d38..7805ed6 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs @@ -100,8 +100,9 @@ namespace Wpf_AiSportsMicrospace.Views _groupJumpRopeContext.CirclePositions = pointlist; _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; + _mainWin.WebcamClient.StartExtract(); - DrawCirclesWithText(); + DrawCirclesWithText(); // 播放音乐 PlayMusic("raisehand.mp3"); diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs index aba1054..b1047fd 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs @@ -110,6 +110,7 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope // 监听播放完成事件 _mediaPlayer.MediaEnded += MediaPlayer_MediaEnded; + _mainWin.WebcamClient.StartExtract(); _mediaPlayer.Play(); } diff --git a/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs b/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs index 0d095de..e89f082 100644 --- a/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs @@ -82,7 +82,7 @@ namespace Views.SquatFu // 播放音乐 PlayMusic("raisehand.mp3"); _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; - + _mainWin.WebcamClient.StartExtract(); } private void UserControl_Unloaded(object sender, RoutedEventArgs e)