Compare commits
No commits in common. "9a646dbb3ceac4908f468cfb436ed8695ac0cc12" and "bbc0291fedcf01d0e421eb45a59e30f43240a7f6" have entirely different histories.
9a646dbb3c
...
bbc0291fed
@ -27,7 +27,6 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
IPointTracker _rightTracker;
|
||||
IPointTracker _leftElbow;
|
||||
IPointTracker _rightElbow;
|
||||
WebcamClient _webcamClient;
|
||||
|
||||
public SportOperate()
|
||||
{
|
||||
@ -43,8 +42,8 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
}
|
||||
public WebcamClient CreateRTSP()
|
||||
{
|
||||
_webcamClient = WebcamClient.CreateRTSP("192.168.3.64", "admin", "yd708090", 554u);
|
||||
return _webcamClient;
|
||||
WebcamClient webcamClient = WebcamClient.CreateRTSP("192.168.3.64", "admin", "yd708090", 554u);
|
||||
return webcamClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
|
||||
using Microsoft.ML.Runtime;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
@ -37,8 +36,7 @@ namespace Wpf_AiSportsMicrospace
|
||||
private SportBase _sport;
|
||||
private readonly SportDetectionQueue _detectQueue;
|
||||
private WebcamClient _webcamClient;
|
||||
private ConcurrentQueue<VideoFrame> _frameQueue = new();
|
||||
private CancellationTokenSource _cts = new();
|
||||
|
||||
private SportOperate _sportOperate;
|
||||
|
||||
public Home()
|
||||
@ -78,36 +76,17 @@ namespace Wpf_AiSportsMicrospace
|
||||
_sportOperate = new SportOperate();
|
||||
_webcamClient = _sportOperate.CreateRTSP();
|
||||
|
||||
_webcamClient.OnExtractFrame += frame =>
|
||||
{
|
||||
if (frame != null)
|
||||
_frameQueue.Enqueue(frame);
|
||||
};
|
||||
_webcamClient.StartExtract();
|
||||
|
||||
StartFrameProcessing();
|
||||
//处理抽帧回调
|
||||
_webcamClient.OnExtractFrame += this.OnFrameExtracted;
|
||||
_webcamClient.StartExtract();//开始抽帧
|
||||
}
|
||||
|
||||
private void StartFrameProcessing()
|
||||
private void OnFrameExtracted(VideoFrame frame)
|
||||
{
|
||||
if (frame == null) return;
|
||||
|
||||
// 抽帧和人体识别全部在后台线程
|
||||
Task.Run(() =>
|
||||
{
|
||||
while (!_cts.Token.IsCancellationRequested)
|
||||
{
|
||||
if (_frameQueue.TryDequeue(out var frame))
|
||||
{
|
||||
ProcessFrame(frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(5);
|
||||
}
|
||||
}
|
||||
}, _cts.Token);
|
||||
}
|
||||
|
||||
|
||||
private void ProcessFrame(VideoFrame frame)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -154,20 +133,31 @@ namespace Wpf_AiSportsMicrospace
|
||||
if (liftHandAction == 1)
|
||||
{
|
||||
// 启动进度条动画;
|
||||
Dispatcher.BeginInvoke(() => coverFlow.StartSelectedProgress());
|
||||
SlideCoverFlow(coverFlow.StartSelectedProgress);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("OnFrameExtracted error: " + ex.Message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
// 抽象 UI 更新到方法中
|
||||
private void SlideCoverFlow(Action slideAction)
|
||||
{
|
||||
base.OnClosed(e);
|
||||
_cts.Cancel();
|
||||
_webcamClient?.StopExtract();
|
||||
Application.Current?.Dispatcher?.BeginInvoke(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
slideAction?.Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("UI update error: " + ex.Message);
|
||||
}
|
||||
}), System.Windows.Threading.DispatcherPriority.Background);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user