SOP流程视频增加标准录像流程检测测试

This commit is contained in:
tfarcraw 2026-11-17 23:12:10 +08:00
parent 26ec86f565
commit b90c8781fd
9 changed files with 369 additions and 8 deletions

View File

@ -0,0 +1,88 @@
using Prism.Commands;
using SopHelper.Engine.Sop;
namespace SopHelper.Training;
public sealed partial class CameraViewModel
{
private SopVideoFlowTest? _flowTest;
private Func<SopConfig>? _flowTestConfigProvider;
private bool _testingFlow;
private string _flowTestStatus = "", _flowTestDetails = "";
public Func<SopConfig>? FlowTestConfigProvider
{
get => _flowTestConfigProvider;
set { _flowTestConfigProvider = value; UpdateCommands(); }
}
public DelegateCommand TestFlowCommand { get; }
public bool IsTestingFlow
{
get => _testingFlow;
private set { SetProperty(ref _testingFlow, value); StateChanged(); }
}
public bool CanSeekVideo => Playback.IsLoaded && !IsTestingFlow && !IsBusy;
public string FlowTestStatus { get => _flowTestStatus; private set => SetProperty(ref _flowTestStatus, value); }
public string FlowTestDetails { get => _flowTestDetails; private set => SetProperty(ref _flowTestDetails, value); }
private async Task StartFlowTestAsync()
{
if (IsRecording || IsTestingFlow) return;
await Playback.StopAsync();
EndFlowTest("开始新的测试");
FlowTestDetails = "";
FlowTestStatus = "正在准备流程测试…";
try
{
var test = new SopVideoFlowTest(FlowTestConfigProvider!());
_flowTest = test;
IsTestingFlow = true;
if (IsPreviewing)
{
await Task.Run(_camera.Disconnect);
ClearPreview(); IsPreviewing = false;
}
test.Changed += (status, details) => _dispatcher.BeginInvoke(() =>
{
if (!ReferenceEquals(_flowTest, test) || _closing) return;
FlowTestStatus = status; FlowTestDetails = details;
});
await Task.Run(test.LoadModels);
test.Start();
FlowTestDetails = test.Details;
FlowTestStatus = "正在播放标准视频并检测流程(使用当前编辑配置)";
Playback.FrameProcessor = test.ProcessFrame;
await Playback.PlayAsync(StandardVideoPath);
if (IsTestingFlow) Status = "正在测试流程;点击“停止播放”可停止测试";
}
catch (Exception error)
{
await Playback.StopAsync();
EndFlowTest("测试失败");
FlowTestStatus = "测试失败:" + error.Message;
throw;
}
}
// 仅在解码任务结束后调用,避免释放正在推理的模型。
private async Task CompleteFlowTestAsync()
{
var test = _flowTest;
if (test is null) return;
FlowTestStatus = "标准视频播放结束,正在收取最后的 AI 判定…";
await test.FinishPendingDecisionAsync();
if (ReferenceEquals(_flowTest, test)) EndFlowTest("标准视频播放结束");
}
private void EndFlowTest(string reason)
{
Playback.FrameProcessor = null;
if (_flowTest is { } test)
{
FlowTestStatus = test.Finish(reason);
FlowTestDetails = test.Details;
_flowTest = null;
test.Dispose();
}
IsTestingFlow = false;
}
}

View File

@ -13,7 +13,7 @@ using Prism.Mvvm;
namespace SopHelper.Training;
public sealed class CameraViewModel : BindableBase
public sealed partial class CameraViewModel : BindableBase
{
private readonly ICameraService _camera;
private readonly VideoRecorder _recorder;
@ -90,21 +90,27 @@ public sealed class CameraViewModel : BindableBase
SaveDirectory = _recipeRecordingDirectory ?? ReadSaveDirectory(root);
}
catch (Exception e) { Status = "录像目录配置读取失败:" + e.Message; }
PreviewCommand = Command(TogglePreviewAsync, () => !IsBusy && !_closing && (IsPreviewing || SelectedCamera != null));
PreviewCommand = Command(TogglePreviewAsync, () => !IsBusy && !_closing && !IsTestingFlow && (IsPreviewing || SelectedCamera != null));
StartRecordingCommand = Command(StartRecordingAsync, () => !IsBusy && !_closing && !IsRecording && !HasStandardVideo && IsPreviewing && Preview != null && HasRecentFrame);
StopRecordingCommand = Command(() => { StopRecording(); return Task.CompletedTask; }, () => !IsBusy && !_closing && IsRecording);
PauseCommand = Command(() => { TogglePause(); return Task.CompletedTask; }, () => !IsBusy && !_closing && IsRecording);
RestartCommand = Command(RestartRecordingAsync, () => _sopStandard && !IsBusy && !_closing && HasStandardVideo && IsPreviewing && Preview != null && HasRecentFrame);
PlayVideoCommand = Command(ToggleVideoPlaybackAsync, () => _sopStandard && !IsBusy && !_closing && !IsRecording && HasStandardVideo);
StopVideoCommand = Command(async () => { await Playback.StopAsync(); Status = "视频播放已停止"; }, () => !IsBusy && !_closing && Playback.IsLoaded);
RestartCommand = Command(RestartRecordingAsync, () => _sopStandard && !IsBusy && !_closing && !IsTestingFlow && HasStandardVideo && IsPreviewing && Preview != null && HasRecentFrame);
PlayVideoCommand = Command(ToggleVideoPlaybackAsync, () => _sopStandard && !IsBusy && !_closing && !IsTestingFlow && !IsRecording && HasStandardVideo);
TestFlowCommand = Command(StartFlowTestAsync, () => _sopStandard && !IsBusy && !_closing && !IsTestingFlow && !IsRecording && HasStandardVideo && FlowTestConfigProvider is not null);
StopVideoCommand = Command(async () => { await Playback.StopAsync(); EndFlowTest("测试已停止"); Status = "视频播放已停止"; }, () => !IsBusy && !_closing && Playback.IsLoaded);
Playback.PropertyChanged += (_, e) =>
{
if (e.PropertyName is nameof(Playback.Frame) or nameof(Playback.IsLoaded)) RaisePropertyChanged(nameof(DisplayImage));
if (e.PropertyName is nameof(Playback.IsPlaying) or nameof(Playback.IsLoaded) or nameof(Playback.IsAtEnd))
{ RaisePropertyChanged(nameof(PlayVideoButtonText)); UpdateCommands(); }
if (e.PropertyName == nameof(Playback.IsAtEnd) && Playback.IsAtEnd) Status = "视频播放结束,可点击“重新播放”再次观看";
if (e.PropertyName == nameof(Playback.IsLoaded)) RaisePropertyChanged(nameof(CanSeekVideo));
if (e.PropertyName == nameof(Playback.IsAtEnd) && Playback.IsAtEnd)
{
if (IsTestingFlow) _ = CompleteFlowTestAsync();
Status = "视频播放结束,可点击“重新播放”再次观看";
}
};
Playback.Failed += message => Status = message;
Playback.Failed += message => { EndFlowTest(message); Status = message; };
BrowseCommand = Command(async () =>
{
var picker = new OpenFolderDialog { Title = "选择录像保存目录" };
@ -153,6 +159,7 @@ public sealed class CameraViewModel : BindableBase
RaisePropertyChanged(nameof(CanChangeDirectory)); RaisePropertyChanged(nameof(SelectedCameraName));
RaisePropertyChanged(nameof(PreviewButtonText)); UpdateCommands();
RaisePropertyChanged(nameof(PauseButtonText)); RaisePropertyChanged(nameof(HasStandardVideo));
RaisePropertyChanged(nameof(CanSeekVideo));
}
private async Task TogglePreviewAsync()
{
@ -383,6 +390,7 @@ public sealed class CameraViewModel : BindableBase
_closing = true; _timer.Stop(); StateChanged();
await _operation;
await Playback.StopAsync();
EndFlowTest("测试已关闭");
try { await Task.Run(_camera.Dispose); }
finally
{

View File

@ -38,6 +38,8 @@ public sealed class RecordedVideoPlayback : BindableBase
}
public string TimeText => $"{TimeSpan.FromSeconds(_position):mm\\:ss} / {TimeSpan.FromSeconds(_duration):mm\\:ss}";
public event Action<string>? Failed;
/// <summary>在解码线程处理即将显示的原始帧;Mat 仅在回调期间有效。</summary>
public Action<Mat, long, double>? FrameProcessor { get; set; }
public RecordedVideoPlayback()
{
@ -213,6 +215,8 @@ public sealed class RecordedVideoPlayback : BindableBase
if (!capture.Grab()) return new(null, 0);
using var frame = new Mat();
if (!capture.Read(frame) || frame.Empty()) return new(null, 0);
var frameId = Math.Max(0, (long)capture.PosFrames - 1);
FrameProcessor?.Invoke(frame, frameId, frameId / _fps);
var stride = checked((int)frame.Step());
var image = BitmapSource.Create(frame.Width, frame.Height, 96, 96, PixelFormats.Bgr24, null,
frame.Data, checked(stride * frame.Height), stride);

View File

@ -0,0 +1,104 @@
using System.Net.Http;
using OpenCvSharp;
using SopHelper.Engine.Common;
using SopHelper.Engine.Inference;
using SopHelper.Engine.Sop;
namespace SopHelper.Training;
/// <summary>独立的录像测试轮次,使用生产 SOP 引擎,不影响运行页统计。</summary>
public sealed class SopVideoFlowTest : IDisposable
{
private static readonly HttpClient VisionHttp = new() { Timeout = Timeout.InfiniteTimeSpan };
private readonly MediaPipeHandDetector _hands = new();
private readonly SopEngine _engine = new();
private readonly Dictionary<int, StepSnapshot> _steps = [];
private readonly int _stride;
private long _seen;
private readonly object _gate = new();
private FrameResult? _lastResult;
private bool _disposed;
public event Action<string, string>? Changed;
public bool IsCompleted => _engine.State == EngineState.Completed;
public string Details
{
get { lock (_gate) return string.Join(Environment.NewLine, _steps.Values.OrderBy(s => s.StepId)
.Select(s => $"{(s.IsMet ? "✓" : s.IsCurrent ? "▶" : "○")} {s.StepId} {s.Name}:{s.Message}")); }
}
public string Progress { get { lock (_gate) return $"已完成 {_steps.Values.Count(s => s.IsMet)}/{_steps.Count} 步"; } }
public SopVideoFlowTest(SopConfig config, IVisionDecisionClient? visionClient = null)
{
if (config.Sop.Steps.Count == 0) throw new InvalidOperationException("请先添加流程步骤,再测试流程");
// 深拷贝,测试轮次不修改编辑中的配方,也不自动开始下一轮。
var snapshot = SopConfigLoader.Parse(SopConfigLoader.ToYaml(config));
snapshot.Sop.Settings.AutoResetOnComplete = false;
snapshot.Sop.Model = null;
_stride = Math.Max(1, snapshot.Sop.Settings.FrameStride);
_engine.VisionDecisionClient = visionClient ?? new ConfiguredVisionDecisionClient(VisionHttp);
_engine.StepSnapshotChanged += step =>
{
if (_steps.TryGetValue(step.StepId, out var previous) && previous.IsMet && !step.IsMet) return;
_steps[step.StepId] = step;
Changed?.Invoke(IsCompleted ? $"流程检测通过,{Progress}" : $"正在测试流程,{Progress}", Details);
};
_engine.Completed += () => Changed?.Invoke($"流程检测通过,{Progress}", Details);
_engine.Load(snapshot);
}
public void Start() => _engine.Start();
public void LoadModels()
{
if (!_engine.Config.Sop.Steps.Any(s => ConditionMethod.RequiresHandDetection(s.Detection?.Method))) return;
_hands.Load(Path.Combine(AppContext.BaseDirectory, "models/palm_detection_full_Nx3x192x192_post.onnx"),
Path.Combine(AppContext.BaseDirectory, "models/hand_landmark_sparse_Nx3x224x224.onnx"), requireGpu: OperatingSystem.IsLinux());
if (!_hands.IsReady) throw new InvalidOperationException("手部模型缺失,无法测试流程,请检查 models 目录");
}
public void ProcessFrame(Mat image, long frameId, double seconds)
{
if (++_seen % _stride != 0 || IsCompleted) return;
var result = new FrameResult { FrameId = frameId, Timestamp = DateTime.Now, Size = (image.Width, image.Height) };
if (_engine.RequiresHandDetection) result.Hands = _hands.Detect(image);
ProcessResult(result, image);
}
/// <summary>使用与正式运行相同的原帧裁剪、手部门控和 AI 完成判定。</summary>
public void ProcessResult(FrameResult result, Mat image)
{
lock (_gate)
{
if (_disposed) return;
_lastResult = result;
_engine.ProcessFrame(result, captureDecisionImage: region => VisionDecisionImage.Encode(image, region));
}
}
public async Task FinishPendingDecisionAsync()
{
while (true)
{
lock (_gate)
{
if (_disposed || !_engine.HasPendingDecision || _lastResult is null) return;
// 只消费已发送的判定,不在结束画面重复触发新的送检。
_engine.ProcessFrame(_lastResult);
if (!_engine.HasPendingDecision) return;
}
await Task.Delay(20).ConfigureAwait(false);
}
}
public string Finish(string reason)
{
lock (_gate) return IsCompleted
? $"{reason};流程检测通过,{Progress}"
: $"{reason};流程未完成,{Progress},停在步骤 {_engine.CurrentStep?.Id}「{_engine.CurrentStep?.Name}」";
}
public void Dispose()
{
lock (_gate) { _disposed = true; _engine.Stop(); _hands.Dispose(); }
}
}

View File

@ -436,17 +436,22 @@
<Button Content="停止录像" Command="{Binding StopRecordingCommand}" />
<Button Content="重新录制" Command="{Binding RestartCommand}" />
<Button Content="{Binding PlayVideoButtonText}" Command="{Binding PlayVideoCommand}" />
<Button Content="测试流程" Command="{Binding TestFlowCommand}" ToolTip.Tip="从头播放标准视频,使用当前编辑的步骤和区域进行流程检测" />
<Button Content="停止播放" Command="{Binding StopVideoCommand}" />
<Button Content="打开保存位置" Command="{Binding RevealCommand}" />
</WrapPanel>
<Grid ColumnDefinitions="*,Auto">
<Slider x:Name="VideoSeekSlider" Minimum="0" Maximum="100" Value="{Binding Playback.Progress, Mode=TwoWay}" IsEnabled="{Binding Playback.IsLoaded}" SmallChange="1" LargeChange="10" VerticalAlignment="Center" ToolTip.Tip="拖动进度条跳转播放位置" />
<Slider x:Name="VideoSeekSlider" Minimum="0" Maximum="100" Value="{Binding Playback.Progress, Mode=TwoWay}" IsEnabled="{Binding CanSeekVideo}" SmallChange="1" LargeChange="10" VerticalAlignment="Center" ToolTip.Tip="拖动进度条跳转播放位置" />
<TextBlock Grid.Column="1" Text="{Binding Playback.TimeText}" Margin="12,0,0,0" />
</Grid>
</StackPanel>
<StackPanel Grid.Row="3" Spacing="6">
<TextBlock Text="{Binding RecordingInfo}" />
<TextBlock Text="{Binding Status}" TextWrapping="Wrap" />
<TextBlock Text="{Binding FlowTestStatus}" TextWrapping="Wrap" />
<ScrollViewer MaxHeight="150" VerticalScrollBarVisibility="Auto">
<TextBlock Text="{Binding FlowTestDetails}" TextWrapping="Wrap" />
</ScrollViewer>
</StackPanel>
<TextBlock Grid.Row="4" Text="{Binding StandardVideoPath}" Foreground="{StaticResource FgDim}" TextWrapping="Wrap" Margin="0,8,0,0" />
</Grid>

View File

@ -163,6 +163,7 @@ public partial class RecipeEditorViewModel : BindableBase, IDialogAware
var recipeDirectory = Path.GetDirectoryName(_path)!;
var root = Path.GetDirectoryName(Path.GetDirectoryName(recipeDirectory)!)!;
SopRecording = new SopHelper.Training.CameraViewModel(new CameraService(), root, Path.GetFileNameWithoutExtension(_path), sopStandard: true, selectedCameraProvider: _selectedCameraProvider);
SopRecording.FlowTestConfigProvider = () => Recipe.ToConfig();
RaisePropertyChanged(nameof(HasSopRecording));
UpdateAgentDefaultVideo();
}

View File

@ -49,6 +49,8 @@ public class SopEngine
private List<StepDef> _ordered = [];
public IVisionDecisionClient? VisionDecisionClient { get; set; }
/// <summary>视频输入结束后,允许消费已发送的最后一次 AI 判定。</summary>
public bool HasPendingDecision => _pendingDecision is not null;
private PendingDecision? _pendingDecision;
private long _nextDecisionAt;
private readonly HandImageRegionTracker _handImageRegion = new();

View File

@ -0,0 +1,142 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Headless;
using Avalonia.Markup.Xaml.Styling;
using Avalonia.Themes.Fluent;
using Avalonia.Threading;
using Avalonia.VisualTree;
using OpenCvSharp;
using Prism.Dialogs;
using SopHelper.Engine.Common;
using SopHelper.Engine.Sop;
using SopHelper.Engine.Training;
using SopHelper.Training;
using SopHelper.VVMs.RecipeEditor;
using Window = Avalonia.Controls.Window;
internal static class Program
{
[STAThread]
public static void Main()
{
var root = Path.Combine(Path.GetTempPath(), "video-flow-test-" + Guid.NewGuid().ToString("N"));
var previousRoot = Environment.GetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT");
Environment.SetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT", root);
try
{
AppBuilder.Configure<Application>().UseSkia().UseHeadless(new AvaloniaHeadlessPlatformOptions { UseHeadlessDrawing = false }).SetupWithoutStarting();
Application.Current!.Styles.Add(new FluentTheme());
Application.Current.Styles.Add(new StyleInclude(new Uri("avares://SopHelper.Avalonia/")) { Source = new Uri("avares://SopHelper.Avalonia/Themes/Styles.axaml") });
CheckAiFlow();
CheckVideoPage(root);
}
finally
{
Environment.SetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT", previousRoot);
if (Directory.Exists(root)) Directory.Delete(root, true);
}
}
private static void CheckAiFlow()
{
var config = SopConfigLoader.Parse("""
sop:
name: 流程测试
settings: { auto_reset_on_complete: true }
regions: { work: { x1: 0, y1: 0, x2: 64, y2: 48 } }
steps:
- id: 1
name: 装配
description: 零件安装到位
detection: { method: hand_in_region, region: work, stable_frames: 1, tolerance: 1 }
ai_confirmation: { image_mode: fixed_region, image_region: work, timeout_seconds: 2 }
""");
var fake = new FakeDecision();
using var test = new SopVideoFlowTest(config, fake);
test.Start();
using var image = new Mat(48, 64, MatType.CV_8UC3, new Scalar(30, 60, 90));
var frame = new FrameResult { FrameId = 12, Timestamp = DateTime.Now, Size = (64, 48), Hands = [new Hand { Rect = new(20, 20, 10, 10) }] };
test.ProcessResult(frame, image);
Until(() => fake.Request is not null);
Check(!test.IsCompleted && fake.Request!.FrameId == 12 && fake.Request.Jpeg.Length > 0, "Hand trigger submits the exact video frame to AI without completing early");
var drain = test.FinishPendingDecisionAsync();
Check(!drain.IsCompleted, "End of video waits for the outstanding AI decision");
fake.Result.SetResult(new(true, .99, "已安装"));
Pump(drain);
Check(test.IsCompleted && test.Finish("播放结束").Contains("检测通过") && test.Details.Contains("✓ 1 装配"), "Final AI confirmation completes the flow and preserves the completed step result");
Check(config.Sop.Settings.AutoResetOnComplete, "Test run preserves the editor configuration");
using var cancelled = new SopVideoFlowTest(config, new FakeDecision());
cancelled.Start();
cancelled.ProcessResult(frame, image);
var cancelledDrain = cancelled.FinishPendingDecisionAsync();
cancelled.Dispose(); Pump(cancelledDrain);
Check(!cancelled.IsCompleted, "Stopping a test cancels pending AI without reporting success");
}
private static void CheckVideoPage(string root)
{
var store = new RecipeWorkspace(root);
var config = new SopConfig(); config.Sop.Name = "视频测试界面"; config.Sop.Parts = [];
var vm = new RecipeEditorViewModel();
vm.OnDialogOpened(new DialogParameters { { "directory", store.RecipesDirectory }, { "config", config }, { "new", true } });
vm.SaveCommand.Execute();
var model = vm.SopRecording!;
Check(!model.TestFlowCommand.CanExecute(), "Test flow is disabled without a saved standard video");
Directory.CreateDirectory(Path.GetDirectoryName(model.StandardVideoPath)!);
using (var writer = new VideoWriter(model.StandardVideoPath, FourCC.MJPG, 10, new OpenCvSharp.Size(64, 48)))
{
Check(writer.IsOpened(), "Standard test video opens");
for (var i = 0; i < 10; i++)
{
using var image = new Mat(48, 64, MatType.CV_8UC3, new Scalar(30, 60, 90)); writer.Write(image);
}
}
// Unsupported condition exercises playback and incomplete results without hardware/models/API.
config.Sop.Steps = [new StepDef { Id = 1, Name = "待配置步骤", Description = "验证当前编辑配置", Detection = new() { Method = "unsupported" } }];
model.FlowTestConfigProvider = () => config;
var view = new RecipeEditor { DataContext = vm };
var window = new Window { Content = view, Width = 1040, Height = 760 }; window.Show(); window.UpdateLayout();
var tabs = view.GetVisualDescendants().OfType<TabControl>().Single();
tabs.SelectedItem = tabs.Items.OfType<TabItem>().Single(t => t.Header?.ToString() == "SOP流程视频");
window.UpdateLayout(); Dispatcher.UIThread.RunJobs();
var button = view.GetVisualDescendants().OfType<Button>().Single(b => ReferenceEquals(b.Command, model.TestFlowCommand));
Check(button.Content?.ToString() == "测试流程" && button.IsEffectivelyVisible && model.TestFlowCommand.CanExecute(), "SOP video page exposes the enabled test flow button");
model.TestFlowCommand.Execute(); Until(() => !model.IsBusy);
Check(model.IsTestingFlow && model.Playback.IsPlaying && model.DisplayImage is { PixelWidth: 64, PixelHeight: 48 }, "Test button plays and displays the standard video without a camera");
Check(!model.TestFlowCommand.CanExecute() && !model.PlayVideoCommand.CanExecute() && !model.PreviewCommand.CanExecute() && !model.CanSeekVideo, "Test run prevents restart, playback switching, camera switching, and seeking");
Check(!view.FindControl<Slider>("VideoSeekSlider")!.IsEnabled, "Actual seek slider is disabled during flow testing");
Until(() => !model.IsTestingFlow);
Check(model.Playback.IsAtEnd && model.FlowTestStatus.Contains("流程未完成") && model.FlowTestDetails.Contains("待配置步骤"), "Video EOF reports incomplete flow and shows the step reason");
model.TestFlowCommand.Execute(); Until(() => !model.IsBusy);
Check(model.Playback.Progress < 50, "Each test restarts the video from its beginning");
model.StopVideoCommand.Execute(); Until(() => !model.IsBusy);
Check(!model.IsTestingFlow && !model.Playback.IsLoaded && model.FlowTestStatus.Contains("测试已停止"), "Stop playback also stops detection and preserves the test summary");
model.TestFlowCommand.Execute(); Until(() => !model.IsBusy);
Pump(vm.ShutdownAsync());
Check(!model.IsTestingFlow && !model.Playback.IsLoaded && model.Playback.FrameProcessor is null, "Closing the editor releases playback and flow detection");
using (var exclusive = new FileStream(model.StandardVideoPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
Check(exclusive.Length > 0, "Closing flow test unlocks the video file");
window.Close(); vm.OnDialogClosed();
}
private static void Until(Func<bool> ready)
{
var watch = System.Diagnostics.Stopwatch.StartNew();
while (!ready() && watch.Elapsed < TimeSpan.FromSeconds(10))
{
using var cancellation = new CancellationTokenSource(10);
Dispatcher.UIThread.MainLoop(cancellation.Token);
}
if (!ready()) throw new TimeoutException("Smoke test timed out");
Dispatcher.UIThread.RunJobs();
}
private static void Pump(Task task) { Until(() => task.IsCompleted); task.GetAwaiter().GetResult(); }
private static void Check(bool value, string message) { if (!value) throw new Exception(message); Console.WriteLine("PASS: " + message); }
private sealed class FakeDecision : IVisionDecisionClient
{
public VisionDecisionRequest? Request;
public TaskCompletionSource<VisionDecisionResult> Result { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
public Task<VisionDecisionResult> DecideAsync(VisionDecisionRequest request, CancellationToken cancellationToken)
{ Request = request; return Result.Task.WaitAsync(cancellationToken); }
}
}

View File

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/SopHelper.Avalonia/SopHelper.Avalonia.csproj" />
<PackageReference Include="Avalonia.Headless" Version="12.1.5" />
</ItemGroup>
</Project>