tiaozhuan

This commit is contained in:
tanglong 2026-01-15 10:54:52 +08:00
parent 534071ebc1
commit 147631122b
2 changed files with 33 additions and 46 deletions

View File

@ -195,7 +195,7 @@ namespace Wpf_AiSportsMicrospace
}
else
{
var newPage = new StandingLeap();
var newPage = new TrainingRecords();
mainWin?.SwitchPageWithMaskAnimation(newPage, true);
}
}

View File

@ -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<Human> 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;
}
}
}