diff --git a/Wpf_AiSportsMicrospace/Common/SportOperate.cs b/Wpf_AiSportsMicrospace/Common/SportOperate.cs index 4c88d1d..f1a5c27 100644 --- a/Wpf_AiSportsMicrospace/Common/SportOperate.cs +++ b/Wpf_AiSportsMicrospace/Common/SportOperate.cs @@ -146,6 +146,7 @@ namespace Wpf_AiSportsMicrospace.Common if (_raiseStartTime == null) _raiseStartTime = DateTime.Now; if (_wristStartTime == null) _wristStartTime = DateTime.Now; + var wristDuration = DateTime.Now - _wristStartTime.Value; if (!_firstHandTriggered && wristDuration.TotalSeconds >= 1) diff --git a/Wpf_AiSportsMicrospace/Optimizes.cs b/Wpf_AiSportsMicrospace/Optimizes.cs new file mode 100644 index 0000000..1f335a7 --- /dev/null +++ b/Wpf_AiSportsMicrospace/Optimizes.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; +using Yztob.AiSports.Postures.Sports; +using Yztob.AiSports.Postures.Things; + +namespace Wpf_AiSportsMicrospace +{ + public class Optimizes + { + /// + /// 执行运动微调 + /// + /// 要微调的运动 + public static void Optimizeing(SportBase sport) + { + if (sport == null) + throw new ArgumentNullException(nameof(sport)); + + //获取运动的检测规则,如果使用的是规则检测时提供 + Console.WriteLine(JsonConvert.SerializeObject(sport.Rules)); + //获取运动的检测动作样本姿态,如果使用的是相似度时提供 + Console.WriteLine(JsonConvert.SerializeObject(sport.Samples)); + + switch (sport.Key) + { + case "squat": + var loggicRule = sport.Rules["squat"] as CalcLogicAndRule; + //删除手部姿态检查规则 + loggicRule.Rules.RemoveAt(2); + loggicRule.Rules.RemoveAt(1); + break; + } + } + } +} diff --git a/Wpf_AiSportsMicrospace/SportExpand/FrontSquat.cs b/Wpf_AiSportsMicrospace/SportExpand/FrontSquat.cs new file mode 100644 index 0000000..2d668a1 --- /dev/null +++ b/Wpf_AiSportsMicrospace/SportExpand/FrontSquat.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Yztob.AiSports.Postures.Sports; +using Yztob.AiSports.Postures.Things; + +namespace SportExpand +{ + /// + /// 正面深蹲 + /// + public class FrontSquat : SportSquat + { + public FrontSquat() + { + var loggicRule = this.Rules["squat"] as CalcLogicAndRule; + //删除手部姿态检查规则 + //loggicRule.Rules.RemoveAt(2); + //loggicRule.Rules.RemoveAt(1); + + loggicRule.Rules.Clear(); + + // 新增下肢宽松规则 + // 1️⃣ 基础规则 + var baseRule = new CalcLogicAndRule() + { + Name = "基础检测(正面·宽松)", + Rules = new List() + { + new CalcWholeRule() + { + Name = "全身入镜", + Relaxed = true + }, + new CalcStandRule() + { + Name = "站姿检测", + Offset = 30 + } + } + }; + + // 2️⃣ 腿部检测规则 + var legRule = new CalcLogicAndRule() + { + Name = "腿部检测(正面·宽松)", + Rules = new List() + { + // ① 双腿横向张开(左右踝水平距离) + new CalcHorizontalRule() + { + Name = "双腿张开", + LeftKey = "left_ankle", + RightKey = "right_ankle", + Offset = 30 // 宽松偏差度数 + }, + + //// ② 膝盖不过内(左右一侧即可,可按需启用) + //new CalcLogicOrRule() + //{ + // Name = "膝盖不过内", + // Rules = new List() + // { + // new CalcPositionRule() + // { + // Name = "左膝可接受", + // ReferenceKey = "left_ankle", + // PositionKey = "left_knee", + // Position = "right", + // Scope = 0.1f + // }, + // new CalcPositionRule() + // { + // Name = "右膝可接受", + // ReferenceKey = "right_ankle", + // PositionKey = "right_knee", + // Position = "left", + // Scope = 0.1f + // } + // } + //}, + + // ③ 下蹲动作(左右一侧即可,轻微下蹲) + new CalcLogicOrRule() + { + Name = "下蹲动作", + Rules = new List() + { + new CalcAngleRule() + { + Name = "左腿稍微下蹲", + AngleKey = "left_knee", + SecondKey = "left_hip", + ThirdKey = "left_ankle", + Angle = 120f, // 轻微下蹲角度 + Offset = 20f // 允许偏差 + }, + new CalcAngleRule() + { + Name = "右腿稍微下蹲", + AngleKey = "right_knee", + SecondKey = "right_hip", + ThirdKey = "right_ankle", + Angle = 120f, + Offset = 20f + } + } + } + } + }; + + loggicRule.Rules.Add(baseRule); + loggicRule.Rules.Add(legRule); + } + } +} diff --git a/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs b/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs index fedbd9d..cb29fc1 100644 --- a/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs @@ -3,6 +3,7 @@ using Dto; using Enum; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using SportExpand; using System.ComponentModel; using System.IO; using System.Runtime.CompilerServices; @@ -468,8 +469,11 @@ namespace Views.SquatFu // 绘制发光圆 var userItem = AddUserItem(x, y, i); + // 绑定运动对象 - var sport = SportBase.Create("squat"); + var sport = new FrontSquat(); + + //Optimizes.Optimizeing(sport); //var sport = SportBase.Create("rope-skipping");