dd
This commit is contained in:
parent
33e2addc03
commit
cbf1728489
@ -31,10 +31,9 @@ namespace Wpf_AiSportsMicrospace.Common
|
|||||||
IPointTracker _rightTracker;
|
IPointTracker _rightTracker;
|
||||||
private int _leftWaveCount = 0;
|
private int _leftWaveCount = 0;
|
||||||
private int _rightWaveCount = 0;
|
private int _rightWaveCount = 0;
|
||||||
private const int WaveThreshold = 4;
|
private const int WaveThreshold =1;
|
||||||
WebcamClient _webcamClient;
|
WebcamClient _webcamClient;
|
||||||
|
|
||||||
private DateTime? _raiseStartTime = null;
|
|
||||||
private DateTime? _wristStartTime = null;
|
private DateTime? _wristStartTime = null;
|
||||||
private bool _firstHandTriggered = false;
|
private bool _firstHandTriggered = false;
|
||||||
|
|
||||||
@ -75,7 +74,8 @@ namespace Wpf_AiSportsMicrospace.Common
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 验证右手动作(右手举手优先,然后左右挥手)
|
/// 验证右手动作(右手举手优先,然后左右挥手)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int VerifyRightWavingAction(List<Human> humans)
|
public int
|
||||||
|
VerifyRightWavingAction(List<Human> humans)
|
||||||
{
|
{
|
||||||
if (humans == null || humans.Count == 0)
|
if (humans == null || humans.Count == 0)
|
||||||
return (int)WavingAction.None;
|
return (int)WavingAction.None;
|
||||||
@ -148,7 +148,6 @@ namespace Wpf_AiSportsMicrospace.Common
|
|||||||
|
|
||||||
if (!pass)
|
if (!pass)
|
||||||
{
|
{
|
||||||
_raiseStartTime = null;
|
|
||||||
_wristStartTime = null;
|
_wristStartTime = null;
|
||||||
_firstHandTriggered = false;
|
_firstHandTriggered = false;
|
||||||
return (int)WavingAction.None;
|
return (int)WavingAction.None;
|
||||||
@ -156,23 +155,31 @@ namespace Wpf_AiSportsMicrospace.Common
|
|||||||
|
|
||||||
var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
|
|
||||||
_raiseStartTime ??= now;
|
//_raiseStartTime ??= now;
|
||||||
_wristStartTime ??= now;
|
_wristStartTime ??= now;
|
||||||
|
|
||||||
double wristElapsed = (now - _wristStartTime.Value).TotalSeconds;
|
double wristElapsed = (now - _wristStartTime.Value).TotalSeconds;
|
||||||
double raiseElapsed = (now - _raiseStartTime.Value).TotalSeconds;
|
//double raiseElapsed = (now - _raiseStartTime.Value).TotalSeconds;
|
||||||
|
|
||||||
// 第一步:触发倒计时 / 举手开始
|
// 第一步:触发倒计时 / 举手开始
|
||||||
if (!_firstHandTriggered && wristElapsed >= 1)
|
if (!_firstHandTriggered && wristElapsed >= 0)
|
||||||
{
|
{
|
||||||
_firstHandTriggered = true;
|
_firstHandTriggered = true;
|
||||||
return (int)WavingAction.FirstHand;
|
return (int)WavingAction.FirstHand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if (wristElapsed <= 3)
|
||||||
|
//{
|
||||||
|
// return (int)WavingAction.Raising;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//_wristStartTime = null;
|
||||||
|
//_firstHandTriggered = false;
|
||||||
|
//return (int)WavingAction.RaiseHand;
|
||||||
|
|
||||||
// 第二步:举手完成
|
// 第二步:举手完成
|
||||||
if (raiseElapsed >= 1)
|
if (wristElapsed >= 3)
|
||||||
{
|
{
|
||||||
_raiseStartTime = null;
|
|
||||||
_wristStartTime = null;
|
_wristStartTime = null;
|
||||||
_firstHandTriggered = false;
|
_firstHandTriggered = false;
|
||||||
return (int)WavingAction.RaiseHand;
|
return (int)WavingAction.RaiseHand;
|
||||||
|
|||||||
@ -57,6 +57,7 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
ImageUri = GetResourceUri("play_img/play_music.png"),
|
ImageUri = GetResourceUri("play_img/play_music.png"),
|
||||||
ProgressColor1 = "#e73d42",
|
ProgressColor1 = "#e73d42",
|
||||||
ProgressColor2 = "#fd8212"
|
ProgressColor2 = "#fd8212"
|
||||||
|
|
||||||
});
|
});
|
||||||
coverFlow.Images.Add(new CoverFlowItem
|
coverFlow.Images.Add(new CoverFlowItem
|
||||||
{
|
{
|
||||||
@ -96,8 +97,8 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
{
|
{
|
||||||
if (!IsGestureActive) return; // 手势识别已停止,直接返回
|
if (!IsGestureActive) return; // 手势识别已停止,直接返回
|
||||||
|
|
||||||
var human = humans.FirstOrDefault();
|
//var human = humans.FirstOrDefault();
|
||||||
if (human == null) return;
|
//if (human == null) return;
|
||||||
|
|
||||||
// 检测挥手动作
|
// 检测挥手动作
|
||||||
var wavingaction = _mainWin.SportOperate.VerifyRightWavingAction(humans);
|
var wavingaction = _mainWin.SportOperate.VerifyRightWavingAction(humans);
|
||||||
@ -105,29 +106,31 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
switch (wavingaction)
|
switch (wavingaction)
|
||||||
{
|
{
|
||||||
case (int)WavingAction.LeftWave: // 左手挥动
|
case (int)WavingAction.LeftWave: // 左手挥动
|
||||||
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.SlideRight());
|
Application.Current.Dispatcher.Invoke(() => coverFlow.SlideRight());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (int)WavingAction.RightWave: // 右手挥动
|
case (int)WavingAction.RightWave: // 右手挥动
|
||||||
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.SlideLeft());
|
Application.Current.Dispatcher.Invoke(() => coverFlow.SlideLeft());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (int)WavingAction.FirstHand: // 举手开始
|
case (int)WavingAction.FirstHand: // 举手开始
|
||||||
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.StartSelectedProgress());
|
//Application.Current.Dispatcher.BeginInvoke(() => coverFlow.StartSelectedProgress());
|
||||||
|
RouterGoNew();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (int)WavingAction.Raising: // 举手中,实时更新进度
|
case (int)WavingAction.Raising: // 举手中,实时更新进度
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (int)WavingAction.RaiseHand: // 举手完成
|
case (int)WavingAction.RaiseHand: // 举手完成
|
||||||
coverFlow.ProgressCompleted += CoverFlow_ProgressCompleted;
|
|
||||||
|
|
||||||
// 设置标记,停止后续手势识别
|
// 设置标记,停止后续手势识别
|
||||||
IsGestureActive = false;
|
//IsGestureActive = false;
|
||||||
|
//RouterGoNew();
|
||||||
|
|
||||||
|
//coverFlow.ProgressCompleted += CoverFlow_ProgressCompleted;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // 没有动作 → 取消进度
|
default: // 没有动作 → 取消进度
|
||||||
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.CancelSelectedProgress());
|
//Application.Current.Dispatcher.BeginInvoke(() => coverFlow.CancelSelectedProgress());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,7 +275,7 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
var baseData = await db.BasicConfig.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
var baseData = await db.BasicConfig.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||||
if (baseData == null)
|
if (baseData == null)
|
||||||
{
|
{
|
||||||
baseData = new BasicConfig { Code = AppSettings.Code, Host = host.Text, UserName = name.Text, Password = password.Text , HomeWidth = int.Parse(homeWidth.Text)};
|
baseData = new BasicConfig { Code = AppSettings.Code, Host = host.Text, UserName = name.Text, Password = password.Text, HomeWidth = int.Parse(homeWidth.Text) };
|
||||||
db.BasicConfig.Add(baseData);
|
db.BasicConfig.Add(baseData);
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -207,8 +207,8 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
int leftWaving = sportOperate.VerifyLeftWavingAction(humans);
|
int leftWaving = sportOperate.VerifyLeftWavingAction(humans);
|
||||||
if (leftWaving == 5)
|
if (leftWaving == 5)
|
||||||
{
|
{
|
||||||
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
//_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
||||||
_mainWin.WebcamClient.StopExtract();
|
//_mainWin.WebcamClient.StopExtract();
|
||||||
|
|
||||||
// 举左手逻辑,例如结束动画或退出
|
// 举左手逻辑,例如结束动画或退出
|
||||||
var newPage = new Home();
|
var newPage = new Home();
|
||||||
@ -223,16 +223,10 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
switch (rightWaving)
|
switch (rightWaving)
|
||||||
{
|
{
|
||||||
case (int)WavingAction.FirstHand:
|
case (int)WavingAction.FirstHand:
|
||||||
|
_currentGameState = GameState.Running;
|
||||||
StartCountdown(3);
|
StartCountdown(3);
|
||||||
_isCountdownStarted = true; // 倒计时开始,停止左手检测
|
_isCountdownStarted = true; // 倒计时开始,停止左手检测
|
||||||
break;
|
break;
|
||||||
//case (int)WavingAction.Raising:
|
|
||||||
// UpdateCountdown();
|
|
||||||
// break;
|
|
||||||
//case (int)WavingAction.RaiseHand:
|
|
||||||
// FinishCountdown();
|
|
||||||
// _currentGameState = GameState.Running; // 倒计时完成 → 游戏开始
|
|
||||||
// break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -249,50 +243,44 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
private async void StartCountdown(int start = 3)
|
private async void StartCountdown(int start = 3)
|
||||||
{
|
{
|
||||||
_mainWin.ShowCountDownAnimation();
|
_mainWin.ShowCountDownAnimation();
|
||||||
//_currentCountdown = start;
|
|
||||||
|
|
||||||
//countdownText.Text = _currentCountdown.ToString();
|
|
||||||
//countdownGrid.Visibility = Visibility.Visible;
|
|
||||||
|
|
||||||
//_lastUpdateTime = DateTime.Now;
|
|
||||||
|
|
||||||
Utils.PlayBackgroundMusic("countdown_3.mp3", false);
|
Utils.PlayBackgroundMusic("countdown_3.mp3", false);
|
||||||
|
|
||||||
//开始人脸识别=============================================
|
//开始人脸识别=============================================
|
||||||
Action<VideoFrame> handler = null;
|
//Action<VideoFrame> handler = null;
|
||||||
|
|
||||||
handler = async (frame) =>
|
//handler = async (frame) =>
|
||||||
{
|
//{
|
||||||
var buffer = frame.GetImageBuffer(ImageFormat.Jpeg).ToArray();
|
// var buffer = frame.GetImageBuffer(ImageFormat.Jpeg).ToArray();
|
||||||
double[] xValues = [.. _groupJumpRopeContext.CirclePositions.Select(p => p.XNorm)];
|
// double[] xValues = [.. _groupJumpRopeContext.CirclePositions.Select(p => p.XNorm)];
|
||||||
|
|
||||||
var studentList = Utils.FacialRecognition(buffer, xValues);
|
// var studentList = Utils.FacialRecognition(buffer, xValues);
|
||||||
|
|
||||||
if (studentList != null && studentList.Count > 0)
|
// if (studentList != null && studentList.Count > 0)
|
||||||
{
|
// {
|
||||||
// 解绑事件
|
// // 解绑事件
|
||||||
_mainWin.FacialRecognitionEvent -= handler;
|
// _mainWin.FacialRecognitionEvent -= handler;
|
||||||
|
|
||||||
for (int i = 0; i < studentList.Count; i++)
|
// for (int i = 0; i < studentList.Count; i++)
|
||||||
{
|
// {
|
||||||
var student = studentList[i];
|
// var student = studentList[i];
|
||||||
if (student != null)
|
// if (student != null)
|
||||||
{
|
// {
|
||||||
_groupJumpRopeContext.UserList[i].DisplayText = student.StudentName;
|
// _groupJumpRopeContext.UserList[i].DisplayText = student.StudentName;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 这里可以继续处理 studentList
|
// // 这里可以继续处理 studentList
|
||||||
};
|
//};
|
||||||
|
|
||||||
// 绑定事件
|
//// 绑定事件
|
||||||
_mainWin.FacialRecognitionEvent += handler;
|
//_mainWin.FacialRecognitionEvent += handler;
|
||||||
|
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000);
|
||||||
FinishCountdown();
|
FinishCountdown();
|
||||||
_currentGameState = GameState.Running;
|
//_currentGameState = GameState.Running;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateCountdown()
|
private void UpdateCountdown()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user