From 540bc3813b6af9df19f61671b9a2a0cf40c39e77 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Tue, 21 Oct 2025 15:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wpf_AiSportsMicrospace/Common/SportOperate.cs | 2 +- .../MyUserControl/PopSilder.xaml.cs | 2 +- Wpf_AiSportsMicrospace/Views/Home.xaml.cs | 8 +- .../Views/JumpRope/MusicJumpRope.xaml.cs | 2 - .../Views/JumpRope/TrainingRecords.xaml | 2 +- .../Views/JumpRope/TrainingRecords.xaml.cs | 79 +++++++++++++++++++ 6 files changed, 89 insertions(+), 6 deletions(-) diff --git a/Wpf_AiSportsMicrospace/Common/SportOperate.cs b/Wpf_AiSportsMicrospace/Common/SportOperate.cs index 5be2d76..7148e16 100644 --- a/Wpf_AiSportsMicrospace/Common/SportOperate.cs +++ b/Wpf_AiSportsMicrospace/Common/SportOperate.cs @@ -56,7 +56,7 @@ namespace Wpf_AiSportsMicrospace.Common { try { - _webcamClient = WebcamClient.CreateRTSP("172.17.30.65", "admin", "yd708090", 554u); + _webcamClient = WebcamClient.CreateRTSP("172.17.30.64", "admin", "yd708090", 554u); } catch (Exception) { diff --git a/Wpf_AiSportsMicrospace/MyUserControl/PopSilder.xaml.cs b/Wpf_AiSportsMicrospace/MyUserControl/PopSilder.xaml.cs index 3136615..646ee75 100644 --- a/Wpf_AiSportsMicrospace/MyUserControl/PopSilder.xaml.cs +++ b/Wpf_AiSportsMicrospace/MyUserControl/PopSilder.xaml.cs @@ -163,7 +163,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl private void OnTimePointReached(double timePoint) { Console.WriteLine($"触发时间点: {timePoint}"); - if (isMiss) + if (_isMiss) { head_m.Visibility = Visibility.Visible; miss.Visibility = Visibility.Visible; diff --git a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs index 6d42220..52bee37 100644 --- a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs @@ -14,6 +14,7 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; +using Views.JumpRope; using Wpf_AiSportsMicrospace; using Wpf_AiSportsMicrospace.Common; using Wpf_AiSportsMicrospace.Enum; @@ -160,11 +161,16 @@ namespace Wpf_AiSportsMicrospace var newPage = new GroupJumpRope(); mainWin?.SwitchPageWithMaskAnimation(newPage, true); } - else + else if (coverFlow.SelectedIndex == 1) { var newPage = new MusicJumpRope(); mainWin?.SwitchPageWithMaskAnimation(newPage, true); } + else + { + var newPage = new TrainingRecords(); + mainWin?.SwitchPageWithMaskAnimation(newPage, true); + } } private void Image_MouseDown(object sender, MouseButtonEventArgs e) diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs index f808adb..840036e 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs @@ -44,7 +44,6 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope // 容忍时间(节拍误差) public double _beatTolerance = 0.24; // ±150ms - private int _totalDots = 0; // 滚动显示的节拍点集合 public ObservableCollection BeatDisplayLeft { get; set; } = new(); public ObservableCollection BeatDisplayRight { get; set; } = new(); @@ -452,7 +451,6 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope if (humans == null || humans.Count == 0) return (int)WavingAction.None; - foreach (var human in humans) { if (human?.Keypoints == null) diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml index 1dadc84..2291f0b 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Views.JumpRope" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> + Height="1080" Width="1920" Loaded="UserControl_Loaded"> diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs index f1da728..1337af0 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs @@ -10,6 +10,11 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Wpf_AiSportsMicrospace; +using Wpf_AiSportsMicrospace.Common; +using Wpf_AiSportsMicrospace.Enum; +using Wpf_AiSportsMicrospace.Views; +using Yztob.AiSports.Inferences.Things; namespace Views.JumpRope { @@ -18,9 +23,83 @@ namespace Views.JumpRope /// public partial class TrainingRecords : UserControl { + private Main _mainWin => Application.Current.MainWindow as Main; public TrainingRecords() { InitializeComponent(); + Loaded += UserControl_Loaded; + } + + private void UserControl_Loaded(object sender, RoutedEventArgs e) + { + Utils.PlayBackgroundMusic("homeprojectselected.mp3", true); + _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; + } + + private void OnHumanFrameUpdated(object sender, List humans) + { + try + { + if (humans == null || humans.Count == 0) return; + + int leftWaving = DetectLeftHandRaise(humans); + if (leftWaving == 5) + { + _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; + _mainWin.WebcamClient.StopExtract(); + + // 举左手逻辑,例如结束动画或退出 + var newPage = new Home(); + _mainWin?.SwitchPageWithMaskAnimation(newPage, true); + } + } + + catch (Exception ex) + { + Console.WriteLine("OnFrameExtracted error: " + ex.Message); + } + + } + + public int DetectLeftHandRaise(List humans) + { + if (humans == null || humans.Count == 0) + return (int)WavingAction.None; + + + foreach (var human in humans) + { + if (human?.Keypoints == null) + continue; + + // --- 筛选右脚踝坐标 --- + var rightAnkle = human.Keypoints.FirstOrDefault(k => k.Name == "right_ankle"); + if (rightAnkle == null) + continue; + double xNorm = rightAnkle.X / 1920; + double yNorm = rightAnkle.Y / 1080; + // 仅检测中心区域内的人 + 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"); + + if (leftWrist == null || leftElbow == null) + continue; + + const double raiseThreshold = 60; // 举手阈值 + + // 判断左手是否举起 + double verticalRise = leftElbow.Y - leftWrist.Y; + if (verticalRise >= raiseThreshold) + { + return (int)WavingAction.RaiseHand; // 一旦检测到左手举起,立即返回 + } + } + + return (int)WavingAction.None; // 没有检测到举手 } } }