From 147631122b407f01c2c316918751c9ab7f556e44 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Thu, 15 Jan 2026 10:54:52 +0800 Subject: [PATCH] tiaozhuan --- Wpf_AiSportsMicrospace/Views/Home.xaml.cs | 2 +- .../Views/JumpRope/TrainingRecords.xaml.cs | 77 ++++++++----------- 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs index ba62a70..1e0b2b2 100644 --- a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs @@ -195,7 +195,7 @@ namespace Wpf_AiSportsMicrospace } else { - var newPage = new StandingLeap(); + var newPage = new TrainingRecords(); mainWin?.SwitchPageWithMaskAnimation(newPage, true); } } diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs index f945952..6a02254 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs @@ -1,4 +1,5 @@ using Dto; +using SportExpand; using System; using System.Collections.Generic; using System.Text; @@ -16,6 +17,7 @@ using Wpf_AiSportsMicrospace.Common; using Wpf_AiSportsMicrospace.Enum; using Wpf_AiSportsMicrospace.Views; using Yztob.AiSports.Inferences.Things; +using Yztob.AiSports.Postures; namespace Views.JumpRope { @@ -48,19 +50,29 @@ namespace Views.JumpRope { if (humans == null || humans.Count == 0) return; - int leftWaving = DetectLeftHandRaise(humans); - if (leftWaving == 5) + var human = humans.FirstOrDefault(h => { - //_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; - if (newPage == null) - { - newPage = new Home(); - _mainWin?.SwitchPageWithMaskAnimation(newPage, true); - } - // 举左手逻辑,例如结束动画或退出 + var rightAnkle = h.Keypoints.FirstOrDefault(k => k.Name == "right_ankle"); + if (rightAnkle == null) + return false; - //return; - //_mainWin.WebcamClient.StopExtract(); + double xNorm = rightAnkle.X / 1920.0; + double yNorm = rightAnkle.Y / 1080.0; + + return xNorm >= 0.44 && xNorm <= 0.57 && yNorm >= 0.81; + }); + if (human != null) + { + + int leftWaving = DetectLeftHandRaise(human); + if (leftWaving == 5) + { + if (newPage == null) + { + newPage = new Home(); + _mainWin?.SwitchPageWithMaskAnimation(newPage, true); + } + } } } @@ -141,45 +153,20 @@ namespace Views.JumpRope } } - public int DetectLeftHandRaise(List humans) + public int DetectLeftHandRaise(Human human) { - if (humans == null || humans.Count == 0) - return (int)WavingAction.None; + var calculator = PostureCalculate.CreateCalculator(); + var rule = RaiseHand.RaiseLeftHand(); + var pass = calculator.Calculating(human, rule); - - foreach (var human in humans) + if (pass) { - 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.RaiseHand; } - return (int)WavingAction.None; // 没有检测到举手 + // 没有检测到举手 + return (int)WavingAction.None; } } }