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 @@ - -