左右滑
This commit is contained in:
parent
47e10d2323
commit
e492e408ee
@ -2,7 +2,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.MyUserControl"
|
||||
Title="Home" Height="400" Width="800">
|
||||
Title="Home" Height="400" Width="800" Loaded="Window_Loaded">
|
||||
<Grid>
|
||||
<local:CoverFlowControl x:Name="coverFlow" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.ML.Runtime;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
@ -10,7 +11,15 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using Wpf_AiSportsMicrospace.Common;
|
||||
using Wpf_AiSportsMicrospace.MyUserControl;
|
||||
using Yztob.AiSports.Inferences.Abstractions;
|
||||
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
|
||||
{
|
||||
@ -19,9 +28,24 @@ namespace Wpf_AiSportsMicrospace
|
||||
/// </summary>
|
||||
public partial class Home : Window
|
||||
{
|
||||
private IHumanPredictor _humanPredictor;
|
||||
private IObjectDetector _objectDetector;
|
||||
private HumanGraphicsRenderer _humanGraphicsRenderer;
|
||||
private readonly List<SportDescriptor> _sports;
|
||||
private SportBase _sport;
|
||||
private readonly SportDetectionQueue _detectQueue;
|
||||
private IPointTracker _tracker;
|
||||
|
||||
public Home()
|
||||
{
|
||||
InitializeComponent();
|
||||
_humanPredictor = HumanPredictorFactory.Create(HumanPredictorType.SingleHigh);
|
||||
_objectDetector = ObjectDetectorFactory.CreateSportGoodsDetector();
|
||||
_humanGraphicsRenderer = new HumanGraphicsRenderer();
|
||||
_humanGraphicsRenderer.DrawLabel = false;
|
||||
|
||||
_sports = SportBase.GetSports();
|
||||
_detectQueue = new SportDetectionQueue();
|
||||
|
||||
string projectRoot = Path.Combine(AppContext.BaseDirectory, @"..\..\..");
|
||||
string albumPath = Path.Combine(projectRoot, "Resources", "Img", "Album");
|
||||
@ -36,5 +60,73 @@ namespace Wpf_AiSportsMicrospace
|
||||
// 默认选中第3张
|
||||
coverFlow.SelectedIndex = 2;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_tracker = PostureCalculate.CreatePointTracker("left_wrist", 0);
|
||||
|
||||
LoadRTSP();
|
||||
}
|
||||
|
||||
private void LoadRTSP()
|
||||
{
|
||||
//_sport.Reset();
|
||||
//_sport.Start();
|
||||
//_detectQueue.Start();
|
||||
|
||||
var _webcamClient = WebcamClient.CreateRTSP("192.168.3.64", "admin", "yd708090", 554u);
|
||||
|
||||
//处理抽帧回调
|
||||
_webcamClient.OnExtractFrame += this.OnFrameExtracted;
|
||||
_webcamClient.StartExtract();//开始抽帧
|
||||
|
||||
|
||||
}
|
||||
|
||||
private DateTime _lastSlideTime = DateTime.MinValue;
|
||||
|
||||
private void OnFrameExtracted(VideoFrame frame)
|
||||
{
|
||||
if (frame == null) return;
|
||||
|
||||
// 抽帧和人体识别全部在后台线程
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var buffer = frame.GetImageBuffer(ImageFormat.Jpeg).ToArray();
|
||||
var humanResult = _humanPredictor.Predicting(buffer, frame.Number);
|
||||
var human = humanResult?.Humans?.FirstOrDefault();
|
||||
if (human == null) return;
|
||||
|
||||
var tr = _tracker.Tracking(human); // 0 左滑,1 右滑
|
||||
|
||||
// 节流:每 500ms 最多更新一次 UI
|
||||
if ((DateTime.Now - _lastSlideTime).TotalMilliseconds < 300) return;
|
||||
_lastSlideTime = DateTime.Now;
|
||||
|
||||
Application.Current?.Dispatcher?.BeginInvoke(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (tr == 0)
|
||||
{
|
||||
//coverFlow.SlideLeft();
|
||||
}
|
||||
else if (tr == 1)
|
||||
coverFlow.SlideRight();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("UI update error: " + ex.Message);
|
||||
}
|
||||
}), System.Windows.Threading.DispatcherPriority.Background);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("OnFrameExtracted error: " + ex.Message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,5 +147,17 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 外部调用:左滑(下一张)
|
||||
public void SlideLeft()
|
||||
{
|
||||
SelectedIndex++;
|
||||
}
|
||||
|
||||
// 外部调用:右滑(上一张)
|
||||
public void SlideRight()
|
||||
{
|
||||
SelectedIndex--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user