VpDetectionNodes.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using TeamAAS.FlowEditor.Execution;
  5. using TeamAAS.FlowEditor.Models;
  6. using TeamAAS.FlowEditor.Plugins;
  7. using Plugins.Vpp.Models;
  8. namespace Plugins.Vpp
  9. {
  10. // ─────────────────────────────────────────────────────────────────────
  11. // VisionPro 检测识别算子(算子级节点)。
  12. // 属性面板开放:输入图像绑定 + 高级编辑按钮(进原生工具界面改区域/参数/调试);
  13. // 工具实例随流程文件序列化,配置不丢。与 Halcon 算子操作习惯一致。
  14. // ─────────────────────────────────────────────────────────────────────
  15. /// <summary>VpBlob 分析:Blob 斑点分析,输出数量与重心。</summary>
  16. [Serializable]
  17. [Plugin("VpBlob分析", PluginCategory.Vpp模块, typeof(VpBlobModel), "EllipseOutline",
  18. NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.检测识别,
  19. Description = "Cognex Blob 斑点分析:属性面板绑定图像,高级编辑进原生界面设置区域/极性;输出数量与重心")]
  20. public class VpBlobPlugin : VpToolPluginBase<VpBlobModel>
  21. {
  22. protected override string ToolTypeName => "CogBlobTool";
  23. /// <summary>预设终端:Blob 官方测量项(GetMeasure 机制;测量需在原生编辑器 Measurements 页启用后才有值)。</summary>
  24. public override VpPresetTerminal[] PresetTerminals => new[]
  25. {
  26. new VpPresetTerminal("面积1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "Area"),
  27. new VpPresetTerminal("重心X1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "CenterMassX"),
  28. new VpPresetTerminal("重心Y1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "CenterMassY"),
  29. new VpPresetTerminal("面积2", "Results.GetBlobs[1]" + VpPresetTerminal.MeasureMarker + "Area"),
  30. new VpPresetTerminal("重心X2", "Results.GetBlobs[1]" + VpPresetTerminal.MeasureMarker + "CenterMassX"),
  31. new VpPresetTerminal("重心Y2", "Results.GetBlobs[1]" + VpPresetTerminal.MeasureMarker + "CenterMassY"),
  32. new VpPresetTerminal("周长1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "Perimeter"),
  33. new VpPresetTerminal("圆度偏差1", "Results.GetBlobs[0]" + VpPresetTerminal.MeasureMarker + "Acircularity"),
  34. };
  35. protected override IEnumerable<OutputField> DeclareResultFields()
  36. {
  37. yield return new OutputField("数量", typeof(int));
  38. yield return new OutputField("首个重心行", typeof(double));
  39. yield return new OutputField("首个重心列", typeof(double));
  40. }
  41. protected override void ExtractResults(object tool, Dictionary<string, object> results)
  42. {
  43. results["数量"] = Get(tool, "Results.Count") ?? 0;
  44. results["首个重心行"] = Get(tool, "Results.GetBlobs[0].CenterOfMassX");
  45. results["首个重心列"] = Get(tool, "Results.GetBlobs[0].CenterOfMassY");
  46. Log(2, $"Blob 完成:数量={results["数量"]}");
  47. }
  48. }
  49. /// <summary>Vp模板匹配:PMAlign 模板定位,输出数量/分数/位姿。</summary>
  50. [Serializable]
  51. [Plugin("Vp模板匹配", PluginCategory.Vpp模块, typeof(VpPMAlignModel), "CrosshairsGps",
  52. NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.检测识别,
  53. Description = "Cognex PMAlign 模板定位:高级编辑进原生界面训练模板/设置分数阈值;输出数量/分数/位姿")]
  54. public class VpPMAlignPlugin : VpToolPluginBase<VpPMAlignModel>
  55. {
  56. protected override string ToolTypeName => "CogPMAlignTool";
  57. /// <summary>预设终端:多目标定位(第 2/3 个目标的分数与位姿;第 1 个目标已由 类型化结果 覆盖)。</summary>
  58. public override VpPresetTerminal[] PresetTerminals => new[]
  59. {
  60. new VpPresetTerminal("分数2", "Results[1].Score"),
  61. new VpPresetTerminal("位置X2", "Results[1].GetPose.TranslationX"),
  62. new VpPresetTerminal("位置Y2", "Results[1].GetPose.TranslationY"),
  63. new VpPresetTerminal("角度2", "Results[1].GetPose.Rotation"),
  64. new VpPresetTerminal("分数3", "Results[2].Score"),
  65. new VpPresetTerminal("位置X3", "Results[2].GetPose.TranslationX"),
  66. new VpPresetTerminal("位置Y3", "Results[2].GetPose.TranslationY"),
  67. new VpPresetTerminal("角度3", "Results[2].GetPose.Rotation"),
  68. };
  69. protected override IEnumerable<OutputField> DeclareResultFields()
  70. {
  71. yield return new OutputField("数量", typeof(int));
  72. yield return new OutputField("分数", typeof(double));
  73. yield return new OutputField("位置X", typeof(double));
  74. yield return new OutputField("位置Y", typeof(double));
  75. yield return new OutputField("角度", typeof(double));
  76. }
  77. protected override void ExtractResults(object tool, Dictionary<string, object> results)
  78. {
  79. results["数量"] = Get(tool, "Results.Count") ?? 0;
  80. results["分数"] = Get(tool, "Results[0].Score");
  81. results["位置X"] = Get(tool, "Results[0].GetPose.TranslationX");
  82. results["位置Y"] = Get(tool, "Results[0].GetPose.TranslationY");
  83. results["角度"] = Get(tool, "Results[0].GetPose.Rotation");
  84. Log(2, $"PMAlign 完成:数量={results["数量"]},分数={results["分数"]}");
  85. }
  86. }
  87. }
  88. namespace Plugins.Vpp.Models
  89. {
  90. using TeamAAS.FlowEditor.Plugins;
  91. /// <summary>VpBlob 分析模型(工具实例/输入绑定/高级编辑按钮均在基类)。</summary>
  92. [Serializable]
  93. public class VpBlobModel : VpToolModelBase
  94. {
  95. }
  96. /// <summary>Vp模板匹配模型。</summary>
  97. [Serializable]
  98. public class VpPMAlignModel : VpToolModelBase
  99. {
  100. }
  101. }