From f561e91ce6fdd449a4c5bbae4fa0f0fd738154fa Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Thu, 19 Nov 2026 13:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=A5=E9=AA=A4=E9=A1=B5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=92=AD=E6=94=BE=E6=8E=A7=E4=BB=B6=E5=92=8C?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E6=AD=A5=E9=AA=A4=E5=85=B3=E9=94=AE=E5=B8=A7?= =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/Imaging.cs | 3 ++- .../Training/RecordedVideoPlayback.cs | 5 +++- .../VVMs/RecipeEditor/EditorNodes.cs | 10 ++++++- .../VVMs/RecipeEditor/RecipeEditor.axaml | 19 ++++++++++++- .../RecipeEditor/RecipeEditorViewModel.cs | 3 ++- .../RecipeEditor/StepKeyFrameViewModel.cs | 27 +++++++++++++++++++ .../Sop/SopConfig.cs | 6 ++++- tests/VideoFlowTest.Smoke/Program.cs | 23 ++++++++++++++++ 8 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 src/SopHelper.Avalonia/VVMs/RecipeEditor/StepKeyFrameViewModel.cs diff --git a/src/SopHelper.Avalonia/Presentation/Imaging.cs b/src/SopHelper.Avalonia/Presentation/Imaging.cs index 3cd24d1..abec97b 100644 --- a/src/SopHelper.Avalonia/Presentation/Imaging.cs +++ b/src/SopHelper.Avalonia/Presentation/Imaging.cs @@ -1,4 +1,4 @@ -using Avalonia; +using Avalonia; using Avalonia.Media; using Avalonia.Platform; using OpenCvSharp; @@ -25,6 +25,7 @@ public class BitmapSource : IImage, IDisposable return new BitmapSource { Native = new NativeBitmap(stream) }; } public void Freeze() { /* Avalonia Bitmap snapshots are immutable already. */ } + public byte[] ToPngBytes() { using var stream = new MemoryStream(); Native!.Save(stream); return stream.ToArray(); } public void Save(string path) => Native!.Save(path); public void Dispose() { Native?.Dispose(); Native=null; GC.SuppressFinalize(this); } public static BitmapSource Create(int width,int height,double dpiX,double dpiY,PixelFormat format,object? palette, diff --git a/src/SopHelper.Avalonia/Training/RecordedVideoPlayback.cs b/src/SopHelper.Avalonia/Training/RecordedVideoPlayback.cs index f5937e5..a54d5ab 100644 --- a/src/SopHelper.Avalonia/Training/RecordedVideoPlayback.cs +++ b/src/SopHelper.Avalonia/Training/RecordedVideoPlayback.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using System.Diagnostics; using Avalonia.Threading; using OpenCvSharp; using Prism.Mvvm; @@ -28,6 +28,7 @@ public sealed class RecordedVideoPlayback : BindableBase public bool IsLoaded { get => _loaded; private set => SetProperty(ref _loaded, value); } public bool IsAtEnd { get => _atEnd; private set => SetProperty(ref _atEnd, value); } public bool IsSeeking => _seeking; + public double DisplayedSeconds { get; private set; } public double Progress { get => _duration > 0 ? Math.Clamp(_position / _duration * 100, 0, 100) : 0; @@ -152,6 +153,7 @@ public sealed class RecordedVideoPlayback : BindableBase } _capture = opened.Capture; Frame = opened.Frame.Image; + DisplayedSeconds = opened.Frame.Seconds; Analysis = opened.Frame.Analysis; _position = percent == 100 ? _duration : opened.Frame.Seconds; IsAtEnd = percent == 100; @@ -205,6 +207,7 @@ public sealed class RecordedVideoPlayback : BindableBase return; } Frame = decoded.Image; + DisplayedSeconds = decoded.Seconds; Analysis = decoded.Analysis; _position = decoded.Seconds; NotifyTime(); } diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs index 3998196..40bd889 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs @@ -1,4 +1,4 @@ -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; using System.Windows.Input; using Avalonia.Media; using Prism.Commands; @@ -417,6 +417,7 @@ public class RecipeNode : EditorNode Id = step.Id, Name = step.Name, Description = step.Description, + KeyFrameBase64 = step.KeyFrameBase64, KeyFrameSeconds = step.KeyFrameSeconds, Timeout = step.Timeout, StandardDurationMs = step.StandardDurationMs, SaveCompletionImage = step.SaveCompletionImage, @@ -486,6 +487,7 @@ public class RecipeNode : EditorNode Id = step.Id, Name = step.Name, Description = step.Description, + KeyFrameBase64 = step.KeyFrameBase64, KeyFrameSeconds = step.KeyFrameSeconds, Timeout = step.Timeout, StandardDurationMs = step.StandardDurationMs, SaveCompletionImage = step.SaveCompletionImage, @@ -780,6 +782,12 @@ public class RegionNode : EditorNode /// public class StepNode : EditorNode { + private string _keyFrameBase64 = ""; + private double? _keyFrameSeconds; + public string KeyFrameBase64 { get => _keyFrameBase64; set { if (SetProperty(ref _keyFrameBase64, value)) RaisePropertyChanged(nameof(KeyFrameLabel)); } } + public double? KeyFrameSeconds { get => _keyFrameSeconds; set { if (SetProperty(ref _keyFrameSeconds, value)) RaisePropertyChanged(nameof(KeyFrameLabel)); } } + public string KeyFrameLabel => string.IsNullOrEmpty(KeyFrameBase64) ? "尚未保存关键帧" : $"已保存关键帧:{KeyFrameSeconds:0.###} 秒(保存配方后持久化)"; + private int _aiCheckWindowMs = 10000, _aiMaxChecks = 20, _aiCheckSettleMs = 100; public int AiCheckWindowMs { get => _aiCheckWindowMs; set { if (SetProperty(ref _aiCheckWindowMs, value)) RaisePropertyChanged(nameof(AiContinueAfterWindow)); } } public bool AiContinueAfterWindow { get => AiCheckWindowMs > 0; set { if (value != AiContinueAfterWindow) AiCheckWindowMs = value ? 10000 : 0; } } diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml index f7e1fa7..68f3cd5 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml @@ -1,4 +1,4 @@ - + @@ -109,6 +109,7 @@ + @@ -121,6 +122,22 @@