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/Dto/MusicJumpRopeContext.cs b/Wpf_AiSportsMicrospace/Dto/MusicJumpRopeContext.cs index c07300d..a7c1913 100644 --- a/Wpf_AiSportsMicrospace/Dto/MusicJumpRopeContext.cs +++ b/Wpf_AiSportsMicrospace/Dto/MusicJumpRopeContext.cs @@ -86,6 +86,9 @@ namespace Dto }) .ToList(); + + RankList = rankList; + return rankList; } public List UpdateScoreRankList() 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 new file mode 100644 index 0000000..2291f0b --- /dev/null +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs new file mode 100644 index 0000000..1337af0 --- /dev/null +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +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 +{ + /// + /// TrainingRecords.xaml 的交互逻辑 + /// + 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; // 没有检测到举手 + } + } +}