From 6a18cb32562ec62416984eb8fe776be802c1c85c Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Fri, 13 Nov 2026 14:19:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4YOLO=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E7=AE=A1=E7=BA=BF=E4=B8=8E=E6=A8=A1=E5=9E=8B=E8=AE=AD=E7=BB=83?= =?UTF-8?q?=E5=8F=8A=E7=89=A9=E4=BD=93=E8=A7=84=E5=88=99=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Diagnostics/RuntimeCheck.cs | 22 +- .../SopHelper.Avalonia.csproj | 4 +- .../VVMs/RecipeEditor/EditorNodes.cs | 9 +- .../VVMs/RecipeEditor/RecipeEditor.axaml | 79 +--- .../RecipeEditor/RecipeEditorViewModel.cs | 59 +-- .../RuntimeSettings/RuntimeSettings.axaml | 14 +- .../VVMs/SopPage/SopPage.axaml | 1 - .../VVMs/SopPage/SopPageViewModel.cs | 36 +- .../Inference/YoloDetector.cs | 440 ------------------ .../Pipeline/DetectionPipeline.cs | 49 +- .../Sop/ConditionEvaluator.cs | 74 --- .../Sop/SopConfig.cs | 4 +- .../Sop/SopConfigLoader.cs | 30 +- .../Sop/SopEngine.cs | 4 +- tests/Avalonia.Smoke/Program.cs | 157 +------ tests/Pipeline.Smoke/Program.cs | 76 +-- tests/Preview.Smoke/Program.cs | 2 +- tests/TensorPreprocessing.Smoke/Program.cs | 2 +- tests/VisionDecision.Smoke/Program.cs | 11 + 19 files changed, 88 insertions(+), 985 deletions(-) delete mode 100644 src/SopHelper.CrossPlatform.Engine/Inference/YoloDetector.cs diff --git a/src/SopHelper.Avalonia/Diagnostics/RuntimeCheck.cs b/src/SopHelper.Avalonia/Diagnostics/RuntimeCheck.cs index d30f004..7bda8bf 100644 --- a/src/SopHelper.Avalonia/Diagnostics/RuntimeCheck.cs +++ b/src/SopHelper.Avalonia/Diagnostics/RuntimeCheck.cs @@ -13,18 +13,24 @@ internal static class RuntimeCheck try { var root=AppContext.BaseDirectory; - using var yolo=new YoloDetector();using var hand=new MediaPipeHandDetector(); - yolo.Load(Path.Combine(root,"models/yolo11n.onnx"),[],preferGpu:requireGpu,requireGpu:requireGpu); + using var hand=new MediaPipeHandDetector(); hand.Load(Path.Combine(root,"models/palm_detection_full_Nx3x192x192_post.onnx"),Path.Combine(root,"models/hand_landmark_sparse_Nx3x224x224.onnx"),requireGpu,requireGpu); - if(!yolo.IsReady||!hand.IsReady)throw new InvalidOperationException("模型未加载"); - if(requireGpu && (!yolo.UsingGpu || !hand.UsingGpu))throw new InvalidOperationException("要求 GPU 推理,但模型未使用 GPU"); - using var frame=new Mat(480,640,MatType.CV_8UC3,Scalar.Black);yolo.Detect(frame);hand.Detect(frame); + if(!hand.IsReady)throw new InvalidOperationException("手部模型未加载"); + if(requireGpu && !hand.UsingGpu)throw new InvalidOperationException("要求 GPU 推理,但手部模型未使用 GPU"); + using var frame=new Mat(480,640,MatType.CV_8UC3,Scalar.Black);hand.Detect(frame); var config=SopConfigLoader.Parse("sop:\n name: runtime-check\n settings:\n auto_reset_on_complete: false\n steps:\n - id: 1\n name: timer\n detection:\n method: time_elapsed\n duration_ms: 1\n"); - var engine=new SopEngine();engine.Load(config);engine.Start();Thread.Sleep(10);engine.ProcessFrame(new FrameResult()); + config.Sop.Steps[0].Description="测试步骤已经完成"; + var engine=new SopEngine { VisionDecisionClient=new CheckDecision() };engine.Load(config);engine.Start(); + for(var i=0;i<100&&engine.State!=EngineState.Completed;i++) {Thread.Sleep(10);engine.ProcessFrame(new FrameResult(),()=>[1]);} if(engine.State!=EngineState.Completed)throw new Exception("SOP 状态机测试失败"); - Console.WriteLine(JsonSerializer.Serialize(new{passed=true,opencv=Cv2.GetVersionString(),classes=yolo.ClassNames.Count,hand=hand.IsReady, - yoloBackend=yolo.Backend,handBackend=hand.Backend,sop=engine.State.ToString()}));return 0; + Console.WriteLine(JsonSerializer.Serialize(new{passed=true,opencv=Cv2.GetVersionString(),hand=hand.IsReady, + handBackend=hand.Backend,sop=engine.State.ToString(),aiGate="simulated"}));return 0; } catch(Exception error){Console.Error.WriteLine(error);return 1;} } + private sealed class CheckDecision : IVisionDecisionClient + { + public Task DecideAsync(VisionDecisionRequest request,CancellationToken token) + => Task.FromResult(new VisionDecisionResult(true,1,"诊断模拟确认")); + } } diff --git a/src/SopHelper.Avalonia/SopHelper.Avalonia.csproj b/src/SopHelper.Avalonia/SopHelper.Avalonia.csproj index 9cc6799..ed3ca4c 100644 --- a/src/SopHelper.Avalonia/SopHelper.Avalonia.csproj +++ b/src/SopHelper.Avalonia/SopHelper.Avalonia.csproj @@ -25,10 +25,8 @@ - + - - diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs index f3c2b3c..08c0990 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs @@ -105,13 +105,10 @@ public class RecipeNode : EditorNode ConditionMethod.HandInRegion, ConditionMethod.HandLeaveRegion, ConditionMethod.HandMove, - ConditionMethod.HandNearObject, - ConditionMethod.ObjectPresent, - ConditionMethod.ObjectInZone, ]; Hands = ["any", "left", "right"]; - ViolationTypes = [ViolationType.Timeout, ViolationType.ObjectRemoved]; + ViolationTypes = [ViolationType.Timeout]; AddRegionCommand = new DelegateCommand(() => { AddRegion(); Changed?.Invoke(); }); RemoveRegionCommand = new DelegateCommand(node => { RemoveRegion(node); Changed?.Invoke(); }, node => node is not null); @@ -511,9 +508,7 @@ public class RecipeNode : EditorNode config.Sop.Steps.Add(def); } - var model = new ModelDef { Path = Model.Path, InputSize = Model.InputSize }; - model.Classes.AddRange(Model.Classes.Items.Select(c => c.Text).Where(c => !string.IsNullOrWhiteSpace(c))); - config.Sop.Model = model; + config.Sop.Model = null; return config; } diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml index 7a24e36..ead93fd 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml @@ -209,8 +209,6 @@ - - @@ -253,8 +251,6 @@ - - @@ -268,16 +264,6 @@ - -