From 5aa415bb9ac97ae9691734debcbdd4c3d50f2d59 Mon Sep 17 00:00:00 2001 From: ltx <1006158920@qq.com> Date: Thu, 5 Feb 2026 09:04:43 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=E9=A1=B5=E9=9D=A2=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E7=82=B9=E4=BD=8D=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/WhackAMoleContext.cs | 2 +- .../Views/JumpRope/GroupJumpRope.xaml.cs | 21 +-- .../Views/SquatFu/WhackAMole.xaml.cs | 171 +----------------- 3 files changed, 13 insertions(+), 181 deletions(-) diff --git a/Wpf_AiSportsMicrospace/Dto/WhackAMoleContext.cs b/Wpf_AiSportsMicrospace/Dto/WhackAMoleContext.cs index 3ac909d..4f105e9 100644 --- a/Wpf_AiSportsMicrospace/Dto/WhackAMoleContext.cs +++ b/Wpf_AiSportsMicrospace/Dto/WhackAMoleContext.cs @@ -20,7 +20,7 @@ namespace Dto public List Sports { get; private set; } public List UseNameList { get; private set; } = new() { - "游客-A", "游客-B", "游客-C", "游客-D", "游客-E", "游客-F" + "游客-A", "游客-B", "游客-C", "游客-D", "游客-E", "游客-F", "游客-G", "游客-H", "游客-I", "游客-F", "游客-J" }; public WhackAMoleContext() { diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs index 1640286..cf9c04f 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs @@ -441,15 +441,12 @@ namespace Wpf_AiSportsMicrospace.Views _groupJumpRopeContext.UserList.Clear(); _groupJumpRopeContext.UserNumberList.Clear(); - double imgWidth = userBox.ActualWidth; - double imgHeight = userBox.ActualHeight; - double radius = 100; for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++) { var pos = _groupJumpRopeContext.CirclePositions[i]; - double x = pos.XNorm * imgWidth; - double y = pos.YNorm * imgHeight; + double x = pos.XNorm ; + double y = pos.YNorm ; // 绘制发光圆 var userItem = AddUserItem(x, y, i); @@ -476,8 +473,8 @@ namespace Wpf_AiSportsMicrospace.Views } private void UpdateCircleCounts(List humans) { - double radiusNormX = 0.07; - double radiusNormY = 0.14; + double radiusNormX = 150; + double radiusNormY = 150; for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++) { @@ -494,10 +491,10 @@ namespace Wpf_AiSportsMicrospace.Views if (rightFoot == null || leftFoot == null) continue; - double xRightNorm = rightFoot.X / userBox.ActualWidth; - double xLeftNorm = leftFoot.X / userBox.ActualWidth; - double yRightNorm = rightFoot.Y / userBox.ActualHeight; - double yLeftNorm = leftFoot.Y / userBox.ActualHeight; + double xRightNorm = rightFoot.X ; + double xLeftNorm = leftFoot.X ; + double yRightNorm = rightFoot.Y ; + double yLeftNorm = leftFoot.Y ; bool outOfCircle = xRightNorm < (circleX - radiusNormX) || xRightNorm > (circleX + radiusNormX) || @@ -570,7 +567,7 @@ namespace Wpf_AiSportsMicrospace.Views userItem.HorizontalAlignment = HorizontalAlignment.Left; userItem.ImageState = "1"; //userItem.Margin = new Thickness(centerX - (index == 0 ? 80 : index == 6 ? 190 : 135), centerY - 540, 0, 0); - userItem.Margin = new Thickness(centerX - 265, centerY - 500, 0, 0); + userItem.Margin = new Thickness(centerX - 25 - 100, centerY - 490 , 0, 0); userBox.Children.Add(userItem); _groupJumpRopeContext.UserList.Add(userItem); _groupJumpRopeContext.UserNumberList.Add("0"); diff --git a/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs b/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs index 7ad1669..f092a04 100644 --- a/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs @@ -329,132 +329,6 @@ namespace Views.SquatFu private bool _firstHandTriggered; private int _lastCountdownSecond = 3; private DateTime? _countdownStartTime; - public int DetectRightHandRaise(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 rightWrist = human.Keypoints.FirstOrDefault(k => k.Name == "right_wrist"); - var rightElbow = human.Keypoints.FirstOrDefault(k => k.Name == "right_elbow"); - - const double raiseThreshold = 60; // 举手阈值 - const double holdDuration = 1; // 持续时间(秒) - const int countdownSeconds = 3; // 倒计时长度 - - bool handRaised = false; - - if (rightWrist != null && rightElbow != null) - { - double verticalRise = rightElbow.Y - rightWrist.Y; - handRaised = verticalRise >= raiseThreshold; - } - - // ---------- 第一步:持续举手触发倒计时 ---------- - if (!_firstHandTriggered) - { - if (handRaised) - { - _raiseStartTime ??= DateTime.Now; - var holdElapsed = (DateTime.Now - _raiseStartTime.Value).TotalSeconds; - if (holdElapsed >= holdDuration) - { - // 举手达到指定时间,启动倒计时 - _firstHandTriggered = true; - _countdownStartTime = DateTime.Now; - _lastCountdownSecond = countdownSeconds; - return (int)WavingAction.FirstHand; - } - } - else - { - // 手放下,重置举手开始时间 - _raiseStartTime = DateTime.Now; - } - - continue; // 本人未触发,检测下一个人 - } - - // ---------- 第二步:倒计时逻辑 ---------- - var countdownElapsed = (DateTime.Now - _countdownStartTime.Value).TotalSeconds; - int currentSecond = countdownSeconds - (int)Math.Floor(countdownElapsed); - - if (currentSecond > 0 && currentSecond != _lastCountdownSecond) - { - _lastCountdownSecond = currentSecond; - Console.WriteLine($"倒计时:{currentSecond}"); - return (int)WavingAction.Raising; // 倒计时中 - } - - if (countdownElapsed >= countdownSeconds) - { - ResetRaiseState(); - return (int)WavingAction.RaiseHand; // 举手完成 - } - - return (int)WavingAction.Raising; - } - - // 没有任何中心区域内的人举手 - return (int)WavingAction.None; - } - 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; // 没有检测到举手 - } private void ResetRaiseState() { @@ -470,14 +344,12 @@ namespace Views.SquatFu _groupJumpRopeContext.UserList.Clear(); _groupJumpRopeContext.UserNumberList.Clear(); - double imgWidth = userBox.ActualWidth; - double imgHeight = userBox.ActualHeight; for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++) { var pos = _groupJumpRopeContext.CirclePositions[i]; - double x = pos.XNorm * imgWidth; - double y = pos.YNorm * imgHeight; + double x = pos.XNorm ; + double y = pos.YNorm ; // 绘制发光圆 var userItem = AddUserItem(x, y, i); @@ -581,43 +453,6 @@ namespace Views.SquatFu } } - - private string GetJumpState(int circleIndex, bool humanInCircle) - { - if (!humanInCircle) - { - // 无人 → 出圈 - return "3"; - } - - string currentNumber = _groupJumpRopeContext.UserNumberList[circleIndex]; - - if (!_jumpStatus.ContainsKey(circleIndex)) - { - _jumpStatus[circleIndex] = (currentNumber, DateTime.Now, "1"); // 初始状态先为停止 - return "1"; - } - var (lastNumber, lastChangeTime, lastState) = _jumpStatus[circleIndex]; - - if (currentNumber != lastNumber) - { - // 数字变化 → 跳绳中 - _jumpStatus[circleIndex] = (currentNumber, DateTime.Now, "2"); - return "2"; - } - - // 数字未变化,判断是否超过 2 秒 - double elapsed = (DateTime.Now - lastChangeTime).TotalSeconds; - if (elapsed >= 0.8) - { - // 超过 2 秒未变化 → 停止 - _jumpStatus[circleIndex] = (currentNumber, lastChangeTime, "1"); - return "1"; - } - // 维持上次状态 - return lastState; - } - private WhackAMoleUserControl AddUserItem(double centerX, double centerY, int index) { var userItem = new WhackAMoleUserControl(); @@ -629,7 +464,7 @@ namespace Views.SquatFu userItem.Index = index; //userItem.ImageState = "1"; //userItem.Margin = new Thickness(centerX - (index == 0 ? 80 : index == 6 ? 190 : 135), centerY - 540, 0, 0); - userItem.Margin = new Thickness(centerX - 265, centerY - 530, 0, 0); + userItem.Margin = new Thickness(centerX , centerY - 600 - 50, 0, 0); userBox.Children.Add(userItem); _groupJumpRopeContext.UserList.Add(userItem); _groupJumpRopeContext.UserNumberList.Add("0");