This commit is contained in:
tanglong 2025-09-25 16:30:09 +08:00
parent eff2b76183
commit bbc0291fed
2 changed files with 45 additions and 43 deletions

View File

@ -22,6 +22,24 @@ namespace Wpf_AiSportsMicrospace.Common
public class SportOperate public class SportOperate
{ {
private DateTime _lastSlideTime = DateTime.MinValue; private DateTime _lastSlideTime = DateTime.MinValue;
IPointTracker _leftTracker;
IPointTracker _rightTracker;
IPointTracker _leftElbow;
IPointTracker _rightElbow;
public SportOperate()
{
_leftTracker = PostureCalculate.CreatePointTracker("left_wrist", 0);
_rightTracker = PostureCalculate.CreatePointTracker("right_wrist", 0);
_leftElbow = PostureCalculate.CreatePointTracker("left_elbow", 0);
_rightElbow = PostureCalculate.CreatePointTracker("right_elbow", 0);
_leftTracker.Amplitude = 0.05f;
_rightTracker.Amplitude = 0.05f;
_leftElbow.Amplitude = 0.05f;
_rightElbow.Amplitude = 0.05f;
}
public WebcamClient CreateRTSP() public WebcamClient CreateRTSP()
{ {
WebcamClient webcamClient = WebcamClient.CreateRTSP("192.168.3.64", "admin", "yd708090", 554u); WebcamClient webcamClient = WebcamClient.CreateRTSP("192.168.3.64", "admin", "yd708090", 554u);
@ -34,16 +52,6 @@ namespace Wpf_AiSportsMicrospace.Common
/// <param name="human"></param> /// <param name="human"></param>
public int VerifyWavingAction(Human human) public int VerifyWavingAction(Human human)
{ {
IPointTracker _leftTracker = PostureCalculate.CreatePointTracker("left_wrist", 0);
IPointTracker _rightTracker = PostureCalculate.CreatePointTracker("right_wrist", 0);
IPointTracker _leftElbow = PostureCalculate.CreatePointTracker("left_elbow", 0);
IPointTracker _rightElbow = PostureCalculate.CreatePointTracker("right_elbow", 0);
_leftTracker.Amplitude = 0.05f;
_rightTracker.Amplitude = 0.05f;
_leftElbow.Amplitude = 0.05f;
_rightElbow.Amplitude = 0.05f;
var leftResult = _leftTracker.Tracking(human); var leftResult = _leftTracker.Tracking(human);
var rightResult = _rightTracker.Tracking(human); var rightResult = _rightTracker.Tracking(human);
var leftElbowResult = _leftElbow.Tracking(human); var leftElbowResult = _leftElbow.Tracking(human);
@ -63,12 +71,6 @@ namespace Wpf_AiSportsMicrospace.Common
public int VerifyLiftHandAction(Human human) public int VerifyLiftHandAction(Human human)
{ {
IPointTracker _rightTracker = PostureCalculate.CreatePointTracker("right_wrist", 0);
IPointTracker _rightElbow = PostureCalculate.CreatePointTracker("right_elbow", 0);
_rightTracker.Amplitude = 0.05f;
_rightElbow.Amplitude = 0.05f;
var rightResult = _rightTracker.Tracking(human); var rightResult = _rightTracker.Tracking(human);
var rightElbowResult = _rightElbow.Tracking(human); var rightElbowResult = _rightElbow.Tracking(human);

View File

@ -36,7 +36,6 @@ namespace Wpf_AiSportsMicrospace
private SportBase _sport; private SportBase _sport;
private readonly SportDetectionQueue _detectQueue; private readonly SportDetectionQueue _detectQueue;
private WebcamClient _webcamClient; private WebcamClient _webcamClient;
private DateTime _lastSlideTime = DateTime.MinValue;
private SportOperate _sportOperate; private SportOperate _sportOperate;
@ -98,37 +97,44 @@ namespace Wpf_AiSportsMicrospace
if (humans == null || humans.Count == 0) if (humans == null || humans.Count == 0)
return; return;
var human = humans //var human = humans
.Where(h => // .Where(h =>
h.Keypoints.Any(kp => kp.Name == "left_ankle" && kp.X < 1020 && kp.Y > 900 && kp.Y < 1020) && // h.Keypoints.Any(kp => kp.Name == "left_ankle" && kp.X < 1020 && kp.Y > 900 && kp.Y < 1020) &&
h.Keypoints.Any(kp => kp.Name == "right_ankle" && kp.X > 750 && kp.Y > 900 && kp.Y < 1020) // h.Keypoints.Any(kp => kp.Name == "right_ankle" && kp.X > 750 && kp.Y > 900 && kp.Y < 1020)
) // )
.FirstOrDefault(); // .FirstOrDefault();
//human = humans.FirstOrDefault(); var human = humans.FirstOrDefault();
if (human == null) return; if (human == null) return;
//检测挥手动作
var wavingAction = _sportOperate.VerifyWavingAction(human); // 启动进度条动画;
// 根据手势结果选择滑动方向 //SlideCoverFlow(coverFlow.StartSelectedProgress);
if (wavingAction == 1)
{ ////检测挥手动作
SlideCoverFlow(coverFlow.SlideRight); //var wavingAction = _sportOperate.VerifyWavingAction(human);
} //// 根据手势结果选择滑动方向
if (wavingAction == 2) //if (wavingAction == 1)
{ //{
SlideCoverFlow(coverFlow.SlideLeft); // SlideCoverFlow(coverFlow.SlideRight);
} // return;
//}
//if (wavingAction == 2)
//{
// SlideCoverFlow(coverFlow.SlideLeft);
// return;
//}
//检测举手动作 //检测举手动作
var liftHandAction = _sportOperate.VerifyLiftHandAction(human); var liftHandAction = _sportOperate.VerifyLiftHandAction(human);
// 根据手势结果选择滑动方向 // 根据手势结果
if (wavingAction == 1) if (liftHandAction == 1)
{ {
// 启动进度条动画; // 启动进度条动画;
SlideCoverFlow(coverFlow.StartSelectedProgress); SlideCoverFlow(coverFlow.StartSelectedProgress);
return;
} }
} }
catch (Exception ex) catch (Exception ex)
@ -153,11 +159,5 @@ namespace Wpf_AiSportsMicrospace
} }
}), System.Windows.Threading.DispatcherPriority.Background); }), System.Windows.Threading.DispatcherPriority.Background);
} }
private void Button_Click(object sender, RoutedEventArgs e)
{
// 启动进度条动画;
SlideCoverFlow(coverFlow.StartSelectedProgress);
}
} }
} }