using System; using System.Collections.Generic; using System.Threading; using TeamAAS.FlowEditor.Execution; using TeamAAS.FlowEditor.Models; using TeamAAS.FlowEditor.Plugins; using Plugins.Vpp.Models; namespace Plugins.Vpp { // ───────────────────────────────────────────────────────────────────── // VisionPro 检测识别算子(算子级节点)。 // 属性面板开放:输入图像绑定 + 高级编辑按钮(进原生工具界面改区域/参数/调试); // 工具实例随流程文件序列化,配置不丢。与 Halcon 算子操作习惯一致。 // ───────────────────────────────────────────────────────────────────── /// VpBlob 分析:Blob 斑点分析,输出数量与重心。 [Serializable] [Plugin("VpBlob分析", PluginCategory.Vpp模块, typeof(VpBlobModel), "EllipseOutline", NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.检测识别, Description = "Cognex Blob 斑点分析:属性面板绑定图像,高级编辑进原生界面设置区域/极性;输出数量与重心")] public class VpBlobPlugin : VpToolPluginBase { protected override string ToolTypeName => "CogBlobTool"; /// 预设终端:Blob 官方测量项(GetMeasure 机制;测量需在原生编辑器 Measurements 页启用后才有值)。 public override VpPresetTerminal[] PresetTerminals => new[] { new VpPresetTerminal("面积1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "Area"), new VpPresetTerminal("重心X1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "CenterMassX"), new VpPresetTerminal("重心Y1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "CenterMassY"), new VpPresetTerminal("面积2", "Results.GetBlobs[1]" + VpPresetTerminal.MeasureMarker + "Area"), new VpPresetTerminal("重心X2", "Results.GetBlobs[1]" + VpPresetTerminal.MeasureMarker + "CenterMassX"), new VpPresetTerminal("重心Y2", "Results.GetBlobs[1]" + VpPresetTerminal.MeasureMarker + "CenterMassY"), new VpPresetTerminal("周长1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "Perimeter"), new VpPresetTerminal("圆度偏差1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "Acircularity"), }; protected override IEnumerable DeclareResultFields() { yield return new OutputField("数量", typeof(int)); yield return new OutputField("首个重心行", typeof(double)); yield return new OutputField("首个重心列", typeof(double)); } protected override void ExtractResults(object tool, Dictionary results) { results["数量"] = Get(tool, "Results.Count") ?? 0; results["首个重心行"] = Get(tool, "Results.GetBlobs[0].CenterOfMassX"); results["首个重心列"] = Get(tool, "Results.GetBlobs[0].CenterOfMassY"); Log(2, $"Blob 完成:数量={results["数量"]}"); } } /// Vp模板匹配:PMAlign 模板定位,输出数量/分数/位姿。 [Serializable] [Plugin("Vp模板匹配", PluginCategory.Vpp模块, typeof(VpPMAlignModel), "CrosshairsGps", NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.检测识别, Description = "Cognex PMAlign 模板定位:高级编辑进原生界面训练模板/设置分数阈值;输出数量/分数/位姿")] public class VpPMAlignPlugin : VpToolPluginBase { protected override string ToolTypeName => "CogPMAlignTool"; /// 预设终端:多目标定位(第 2/3 个目标的分数与位姿;第 1 个目标已由 类型化结果 覆盖)。 public override VpPresetTerminal[] PresetTerminals => new[] { new VpPresetTerminal("分数2", "Results[1].Score"), new VpPresetTerminal("位置X2", "Results[1].GetPose.TranslationX"), new VpPresetTerminal("位置Y2", "Results[1].GetPose.TranslationY"), new VpPresetTerminal("角度2", "Results[1].GetPose.Rotation"), new VpPresetTerminal("分数3", "Results[2].Score"), new VpPresetTerminal("位置X3", "Results[2].GetPose.TranslationX"), new VpPresetTerminal("位置Y3", "Results[2].GetPose.TranslationY"), new VpPresetTerminal("角度3", "Results[2].GetPose.Rotation"), }; protected override IEnumerable DeclareResultFields() { yield return new OutputField("数量", typeof(int)); yield return new OutputField("分数", typeof(double)); yield return new OutputField("位置X", typeof(double)); yield return new OutputField("位置Y", typeof(double)); yield return new OutputField("角度", typeof(double)); } protected override void ExtractResults(object tool, Dictionary results) { results["数量"] = Get(tool, "Results.Count") ?? 0; results["分数"] = Get(tool, "Results[0].Score"); results["位置X"] = Get(tool, "Results[0].GetPose.TranslationX"); results["位置Y"] = Get(tool, "Results[0].GetPose.TranslationY"); results["角度"] = Get(tool, "Results[0].GetPose.Rotation"); Log(2, $"PMAlign 完成:数量={results["数量"]},分数={results["分数"]}"); } } } namespace Plugins.Vpp.Models { using TeamAAS.FlowEditor.Plugins; /// VpBlob 分析模型(工具实例/输入绑定/高级编辑按钮均在基类)。 [Serializable] public class VpBlobModel : VpToolModelBase { } /// Vp模板匹配模型。 [Serializable] public class VpPMAlignModel : VpToolModelBase { } }