检测类
This commit is contained in:
parent
3f343a5931
commit
b5db17278f
85
Wpf_AiSportsMicrospace/Common/SportOperate.cs
Normal file
85
Wpf_AiSportsMicrospace/Common/SportOperate.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using HandyControl.Controls;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using Yztob.AiSports.Inferences.Abstractions;
|
||||||
|
using Yztob.AiSports.Inferences.Things;
|
||||||
|
using Yztob.AiSports.Postures;
|
||||||
|
using Yztob.AiSports.Postures.Abstractions;
|
||||||
|
using Yztob.AiSports.Postures.Sports;
|
||||||
|
using Yztob.AiSports.Postures.Things;
|
||||||
|
using Yztob.AiSports.Sensors.Abstractions;
|
||||||
|
using Yztob.AiSports.Sensors.Things;
|
||||||
|
|
||||||
|
namespace Wpf_AiSportsMicrospace.Common
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 运动检测操作类
|
||||||
|
/// </summary>
|
||||||
|
public class SportOperate
|
||||||
|
{
|
||||||
|
private DateTime _lastSlideTime = DateTime.MinValue;
|
||||||
|
public WebcamClient CreateRTSP()
|
||||||
|
{
|
||||||
|
WebcamClient webcamClient = WebcamClient.CreateRTSP("192.168.3.64", "admin", "yd708090", 554u);
|
||||||
|
return webcamClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证挥手动作[0:无效,1:左,2:右]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="human"></param>
|
||||||
|
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 rightResult = _rightTracker.Tracking(human);
|
||||||
|
var leftElbowResult = _leftElbow.Tracking(human);
|
||||||
|
var rightElbowResult = _rightElbow.Tracking(human);
|
||||||
|
|
||||||
|
// 节流:每 300ms 最多更新一次 UI
|
||||||
|
if ((DateTime.Now - _lastSlideTime).TotalMilliseconds < 500) return 0;
|
||||||
|
_lastSlideTime = DateTime.Now;
|
||||||
|
|
||||||
|
// 根据手势结果选择滑动方向
|
||||||
|
if (leftResult != 0 && leftElbowResult != 0) return 1;
|
||||||
|
if (rightResult != 0 & rightElbowResult != 0) return 2;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 rightElbowResult = _rightElbow.Tracking(human);
|
||||||
|
|
||||||
|
// 节流:每 300ms 最多更新一次 UI
|
||||||
|
if ((DateTime.Now - _lastSlideTime).TotalMilliseconds < 500) return 0;
|
||||||
|
_lastSlideTime = DateTime.Now;
|
||||||
|
|
||||||
|
// 根据手势结果选择滑动方向
|
||||||
|
if (rightResult != 0 & rightElbowResult != 0) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.ML.Runtime;
|
|
||||||
|
using Microsoft.ML.Runtime;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
@ -34,11 +35,10 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
private readonly List<SportDescriptor> _sports;
|
private readonly List<SportDescriptor> _sports;
|
||||||
private SportBase _sport;
|
private SportBase _sport;
|
||||||
private readonly SportDetectionQueue _detectQueue;
|
private readonly SportDetectionQueue _detectQueue;
|
||||||
private IPointTracker _leftTracker;
|
|
||||||
private IPointTracker _rightTracker;
|
|
||||||
private IPointTracker _leftElbow;
|
|
||||||
private IPointTracker _rightElbow;
|
|
||||||
private WebcamClient _webcamClient;
|
private WebcamClient _webcamClient;
|
||||||
|
private DateTime _lastSlideTime = DateTime.MinValue;
|
||||||
|
|
||||||
|
private SportOperate _sportOperate;
|
||||||
|
|
||||||
public Home()
|
public Home()
|
||||||
{
|
{
|
||||||
@ -74,35 +74,15 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
//_leftTracker = PostureCalculate.CreatePointTracker("left_wrist", 0);
|
_sportOperate = new SportOperate();
|
||||||
//_rightTracker = PostureCalculate.CreatePointTracker("right_wrist", 0);
|
|
||||||
//_leftElbow = PostureCalculate.CreatePointTracker("left_elbow", 0);
|
|
||||||
//_rightElbow = PostureCalculate.CreatePointTracker("right_elbow", 0);
|
|
||||||
|
|
||||||
//_leftTracker.Amplitude = 0.05f;
|
_webcamClient = _sportOperate.CreateRTSP();
|
||||||
//_rightTracker.Amplitude = 0.05f;
|
|
||||||
|
|
||||||
//_leftElbow.Amplitude = 0.05f;
|
|
||||||
//_rightElbow.Amplitude = 0.05f;
|
|
||||||
|
|
||||||
//LoadRTSP();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadRTSP()
|
|
||||||
{
|
|
||||||
//_sport.Reset();
|
|
||||||
//_sport.Start();
|
|
||||||
//_detectQueue.Start();
|
|
||||||
|
|
||||||
_webcamClient = WebcamClient.CreateRTSP("192.168.3.64", "admin", "yd708090", 554u);
|
|
||||||
|
|
||||||
//处理抽帧回调
|
//处理抽帧回调
|
||||||
_webcamClient.OnExtractFrame += this.OnFrameExtracted;
|
_webcamClient.OnExtractFrame += this.OnFrameExtracted;
|
||||||
_webcamClient.StartExtract();//开始抽帧
|
_webcamClient.StartExtract();//开始抽帧
|
||||||
}
|
}
|
||||||
|
|
||||||
private DateTime _lastSlideTime = DateTime.MinValue;
|
|
||||||
|
|
||||||
private void OnFrameExtracted(VideoFrame frame)
|
private void OnFrameExtracted(VideoFrame frame)
|
||||||
{
|
{
|
||||||
if (frame == null) return;
|
if (frame == null) return;
|
||||||
@ -119,37 +99,38 @@ 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();
|
||||||
|
|
||||||
var human = humans.FirstOrDefault();
|
//human = humans.FirstOrDefault();
|
||||||
|
|
||||||
if (human == null)
|
if (human == null) return;
|
||||||
return;
|
|
||||||
|
|
||||||
var leftResult = _leftTracker.Tracking(human);
|
|
||||||
var rightResult = _rightTracker.Tracking(human);
|
|
||||||
|
|
||||||
var leftElbowResult = _leftElbow.Tracking(human);
|
|
||||||
var rightElbowResult = _rightElbow.Tracking(human);
|
|
||||||
|
|
||||||
// 节流:每 300ms 最多更新一次 UI
|
|
||||||
if ((DateTime.Now - _lastSlideTime).TotalMilliseconds < 500) return;
|
|
||||||
_lastSlideTime = DateTime.Now;
|
|
||||||
|
|
||||||
|
//检测挥手动作
|
||||||
|
var wavingAction = _sportOperate.VerifyWavingAction(human);
|
||||||
// 根据手势结果选择滑动方向
|
// 根据手势结果选择滑动方向
|
||||||
if (leftResult != 0 && leftElbowResult != 1)
|
if (wavingAction == 1)
|
||||||
{
|
{
|
||||||
SlideCoverFlow(coverFlow.SlideRight);
|
SlideCoverFlow(coverFlow.SlideRight);
|
||||||
}
|
}
|
||||||
if (rightResult != 0 & rightElbowResult != 1)
|
if (wavingAction == 2)
|
||||||
{
|
{
|
||||||
SlideCoverFlow(coverFlow.SlideLeft);
|
SlideCoverFlow(coverFlow.SlideLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//检测举手动作
|
||||||
|
var liftHandAction = _sportOperate.VerifyLiftHandAction(human);
|
||||||
|
|
||||||
|
// 根据手势结果选择滑动方向
|
||||||
|
if (wavingAction == 1)
|
||||||
|
{
|
||||||
|
// 启动进度条动画;
|
||||||
|
SlideCoverFlow(coverFlow.StartSelectedProgress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -173,5 +154,11 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
}
|
}
|
||||||
}), System.Windows.Threading.DispatcherPriority.Background);
|
}), System.Windows.Threading.DispatcherPriority.Background);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Button_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// 启动进度条动画;
|
||||||
|
SlideCoverFlow(coverFlow.StartSelectedProgress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,12 +34,19 @@
|
|||||||
<Image Source="{Binding ImageUri}" Width="150" Height="200" Stretch="UniformToFill"/>
|
<Image Source="{Binding ImageUri}" Width="150" Height="200" Stretch="UniformToFill"/>
|
||||||
|
|
||||||
<!-- 矩形进度条 -->
|
<!-- 矩形进度条 -->
|
||||||
<Path Stroke="Gold" StrokeThickness="4"
|
<Path Stroke="Yellow" StrokeThickness="4"
|
||||||
Data="{Binding Progress, Converter={StaticResource ProgressToRectangleGeometryConverter}, ConverterParameter='150,200'}"/>
|
Data="{Binding Progress, Converter={StaticResource ProgressToRectangleGeometryConverter}, ConverterParameter='150,200'}"/>
|
||||||
<!-- 火花 -->
|
<!-- 火花 -->
|
||||||
<Ellipse x:Name="Spark" Width="8" Height="8" Fill="Yellow" Visibility="Collapsed">
|
<Ellipse x:Name="Spark" Width="8" Height="8" Visibility="Collapsed">
|
||||||
|
<Ellipse.Fill>
|
||||||
|
<RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5" RadiusX="1" RadiusY="1">
|
||||||
|
<GradientStop Color="Yellow" Offset="0"/>
|
||||||
|
<GradientStop Color="Orange" Offset="0.4"/>
|
||||||
|
<GradientStop Color="Red" Offset="1"/>
|
||||||
|
</RadialGradientBrush>
|
||||||
|
</Ellipse.Fill>
|
||||||
<Ellipse.Effect>
|
<Ellipse.Effect>
|
||||||
<DropShadowEffect Color="White" BlurRadius="10" ShadowDepth="0"/>
|
<DropShadowEffect Color="Orange" BlurRadius="10" ShadowDepth="0"/>
|
||||||
</Ellipse.Effect>
|
</Ellipse.Effect>
|
||||||
</Ellipse>
|
</Ellipse>
|
||||||
</Canvas>
|
</Canvas>
|
||||||
|
|||||||
@ -46,8 +46,8 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
UpdateLayoutWithAnimation();
|
UpdateLayoutWithAnimation();
|
||||||
|
|
||||||
// 启动进度条动画
|
// 启动进度条动画
|
||||||
var current = Images[_selectedIndex];
|
//var current = Images[_selectedIndex];
|
||||||
StartProgress(current);
|
//StartProgress(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -72,7 +72,19 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
|
|
||||||
private CoverFlowItem _currentItem;
|
private CoverFlowItem _currentItem;
|
||||||
|
|
||||||
private void StartProgress(CoverFlowItem item)
|
/// <summary>
|
||||||
|
/// 针对当前选中项启动进度条动画
|
||||||
|
/// </summary>
|
||||||
|
public void StartSelectedProgress()
|
||||||
|
{
|
||||||
|
if (SelectedIndex >= 0 && SelectedIndex < Images.Count)
|
||||||
|
{
|
||||||
|
var current = Images[SelectedIndex];
|
||||||
|
StartProgress(current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartProgress(CoverFlowItem item)
|
||||||
{
|
{
|
||||||
StopProgress();
|
StopProgress();
|
||||||
|
|
||||||
@ -91,7 +103,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
{
|
{
|
||||||
if (_currentItem.Progress < 1)
|
if (_currentItem.Progress < 1)
|
||||||
{
|
{
|
||||||
_currentItem.Progress += 0.002; // 控制速度
|
_currentItem.Progress += 0.00556; // 控制速度
|
||||||
if (spark != null)
|
if (spark != null)
|
||||||
{
|
{
|
||||||
var pos = GetSparkPosition(_currentItem.Progress, 150, 200);
|
var pos = GetSparkPosition(_currentItem.Progress, 150, 200);
|
||||||
@ -164,7 +176,6 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
|
|
||||||
private void UpdateLayoutWithAnimation(bool instant = false)
|
private void UpdateLayoutWithAnimation(bool instant = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
double centerX = ActualWidth / 2;
|
double centerX = ActualWidth / 2;
|
||||||
double spacing = 180;
|
double spacing = 180;
|
||||||
double sideScale = 0.8;
|
double sideScale = 0.8;
|
||||||
@ -229,18 +240,18 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
new DoubleAnimation(targetOpacity, TimeSpan.FromMilliseconds(400)));
|
new DoubleAnimation(targetOpacity, TimeSpan.FromMilliseconds(400)));
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = Images[i];
|
//var item = Images[i];
|
||||||
|
|
||||||
if (i == SelectedIndex)
|
//if (i == SelectedIndex)
|
||||||
{
|
//{
|
||||||
item.IsSelected = true;
|
// item.IsSelected = true;
|
||||||
StartProgress(item); // 开始绘制进度条 + 火花
|
// StartProgress(item); // 开始绘制进度条 + 火花
|
||||||
}
|
//}
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
item.IsSelected = false;
|
// item.IsSelected = false;
|
||||||
StopProgress(); // 停止并重置进度
|
// StopProgress(); // 停止并重置进度
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user