update:页面渲染点位修改
This commit is contained in:
parent
6e508d3185
commit
5aa415bb9a
@ -20,7 +20,7 @@ namespace Dto
|
|||||||
public List<SportBase> Sports { get; private set; }
|
public List<SportBase> Sports { get; private set; }
|
||||||
public List<string> UseNameList { get; private set; } = new()
|
public List<string> UseNameList { get; private set; } = new()
|
||||||
{
|
{
|
||||||
"游客-A", "游客-B", "游客-C", "游客-D", "游客-E", "游客-F"
|
"游客-A", "游客-B", "游客-C", "游客-D", "游客-E", "游客-F", "游客-G", "游客-H", "游客-I", "游客-F", "游客-J"
|
||||||
};
|
};
|
||||||
public WhackAMoleContext()
|
public WhackAMoleContext()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -441,15 +441,12 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
_groupJumpRopeContext.UserList.Clear();
|
_groupJumpRopeContext.UserList.Clear();
|
||||||
_groupJumpRopeContext.UserNumberList.Clear();
|
_groupJumpRopeContext.UserNumberList.Clear();
|
||||||
|
|
||||||
double imgWidth = userBox.ActualWidth;
|
|
||||||
double imgHeight = userBox.ActualHeight;
|
|
||||||
double radius = 100;
|
|
||||||
|
|
||||||
for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++)
|
for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++)
|
||||||
{
|
{
|
||||||
var pos = _groupJumpRopeContext.CirclePositions[i];
|
var pos = _groupJumpRopeContext.CirclePositions[i];
|
||||||
double x = pos.XNorm * imgWidth;
|
double x = pos.XNorm ;
|
||||||
double y = pos.YNorm * imgHeight;
|
double y = pos.YNorm ;
|
||||||
|
|
||||||
// 绘制发光圆
|
// 绘制发光圆
|
||||||
var userItem = AddUserItem(x, y, i);
|
var userItem = AddUserItem(x, y, i);
|
||||||
@ -476,8 +473,8 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
}
|
}
|
||||||
private void UpdateCircleCounts(List<Human> humans)
|
private void UpdateCircleCounts(List<Human> humans)
|
||||||
{
|
{
|
||||||
double radiusNormX = 0.07;
|
double radiusNormX = 150;
|
||||||
double radiusNormY = 0.14;
|
double radiusNormY = 150;
|
||||||
|
|
||||||
for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++)
|
for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++)
|
||||||
{
|
{
|
||||||
@ -494,10 +491,10 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
if (rightFoot == null || leftFoot == null)
|
if (rightFoot == null || leftFoot == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
double xRightNorm = rightFoot.X / userBox.ActualWidth;
|
double xRightNorm = rightFoot.X ;
|
||||||
double xLeftNorm = leftFoot.X / userBox.ActualWidth;
|
double xLeftNorm = leftFoot.X ;
|
||||||
double yRightNorm = rightFoot.Y / userBox.ActualHeight;
|
double yRightNorm = rightFoot.Y ;
|
||||||
double yLeftNorm = leftFoot.Y / userBox.ActualHeight;
|
double yLeftNorm = leftFoot.Y ;
|
||||||
|
|
||||||
bool outOfCircle =
|
bool outOfCircle =
|
||||||
xRightNorm < (circleX - radiusNormX) || xRightNorm > (circleX + radiusNormX) ||
|
xRightNorm < (circleX - radiusNormX) || xRightNorm > (circleX + radiusNormX) ||
|
||||||
@ -570,7 +567,7 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
userItem.HorizontalAlignment = HorizontalAlignment.Left;
|
userItem.HorizontalAlignment = HorizontalAlignment.Left;
|
||||||
userItem.ImageState = "1";
|
userItem.ImageState = "1";
|
||||||
//userItem.Margin = new Thickness(centerX - (index == 0 ? 80 : index == 6 ? 190 : 135), centerY - 540, 0, 0);
|
//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);
|
userBox.Children.Add(userItem);
|
||||||
_groupJumpRopeContext.UserList.Add(userItem);
|
_groupJumpRopeContext.UserList.Add(userItem);
|
||||||
_groupJumpRopeContext.UserNumberList.Add("0");
|
_groupJumpRopeContext.UserNumberList.Add("0");
|
||||||
|
|||||||
@ -329,132 +329,6 @@ namespace Views.SquatFu
|
|||||||
private bool _firstHandTriggered;
|
private bool _firstHandTriggered;
|
||||||
private int _lastCountdownSecond = 3;
|
private int _lastCountdownSecond = 3;
|
||||||
private DateTime? _countdownStartTime;
|
private DateTime? _countdownStartTime;
|
||||||
public int DetectRightHandRaise(List<Human> 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<Human> 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()
|
private void ResetRaiseState()
|
||||||
{
|
{
|
||||||
@ -470,14 +344,12 @@ namespace Views.SquatFu
|
|||||||
_groupJumpRopeContext.UserList.Clear();
|
_groupJumpRopeContext.UserList.Clear();
|
||||||
_groupJumpRopeContext.UserNumberList.Clear();
|
_groupJumpRopeContext.UserNumberList.Clear();
|
||||||
|
|
||||||
double imgWidth = userBox.ActualWidth;
|
|
||||||
double imgHeight = userBox.ActualHeight;
|
|
||||||
|
|
||||||
for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++)
|
for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++)
|
||||||
{
|
{
|
||||||
var pos = _groupJumpRopeContext.CirclePositions[i];
|
var pos = _groupJumpRopeContext.CirclePositions[i];
|
||||||
double x = pos.XNorm * imgWidth;
|
double x = pos.XNorm ;
|
||||||
double y = pos.YNorm * imgHeight;
|
double y = pos.YNorm ;
|
||||||
|
|
||||||
// 绘制发光圆
|
// 绘制发光圆
|
||||||
var userItem = AddUserItem(x, y, i);
|
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)
|
private WhackAMoleUserControl AddUserItem(double centerX, double centerY, int index)
|
||||||
{
|
{
|
||||||
var userItem = new WhackAMoleUserControl();
|
var userItem = new WhackAMoleUserControl();
|
||||||
@ -629,7 +464,7 @@ namespace Views.SquatFu
|
|||||||
userItem.Index = index;
|
userItem.Index = index;
|
||||||
//userItem.ImageState = "1";
|
//userItem.ImageState = "1";
|
||||||
//userItem.Margin = new Thickness(centerX - (index == 0 ? 80 : index == 6 ? 190 : 135), centerY - 540, 0, 0);
|
//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);
|
userBox.Children.Add(userItem);
|
||||||
_groupJumpRopeContext.UserList.Add(userItem);
|
_groupJumpRopeContext.UserList.Add(userItem);
|
||||||
_groupJumpRopeContext.UserNumberList.Add("0");
|
_groupJumpRopeContext.UserNumberList.Add("0");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user