当前位置: 首页 > news >正文

CogPMAligMultiTool 工具使用-发卡识别

需求

识别下列发卡的形状

工具使用

1.脚本灰度值转换的引用

2.添加转灰度值脚本

CogImageConvertTool image = new CogImageConvertTool(); image.InputImage = mToolBlock.Inputs["InputImage"].Value as ICogImage; image.RunParams.RunMode = CogImageConvertRunModeConstants.Intensity; image.Run();

3.将转换后图像赋值

CogPMAlignMultiTool pma = mToolBlock.Tools["CogPMAlignMultiTool1"]as CogPMAlignMultiTool; pma.InputImage = image.OutputImage; pma.Run();

4.CogPMAlignMultiTool 工具实操

5.创建label集合和类

private CogGraphicCollection dt = new CogGraphicCollection(); dt.Clear(); private CogGraphicLabel createlabel(string text, float size, double x, double y, CogColorConstants color) { CogGraphicLabel label = new CogGraphicLabel(); label.Alignment = CogGraphicLabelAlignmentConstants.TopLeft; label.BackgroundColor = CogColorConstants.White; label.Color = color; label.Font = new Font("Arial", size, FontStyle.Bold, GraphicsUnit.Pixel); label.SetXYText(x, y, text); return label; }

6.遍历CogPMAlignMultiTool 并赋值

string type = ""; for(int i = 0;i < pma.Results.ResultItemCollection.Count;i++) { switch(pma.Results.ResultItemCollection[i].Name) { case"青蛙": type = "青蛙"; break; case"笑脸": type = "笑脸"; break; case"爱心": type = "爱心"; break; } dt.Add(createlabel("类型是:" + type, 25, 10, 10, CogColorConstants.Blue)); dt.Add(createlabel(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 25, 10, 90, CogColorConstants.Green)); }

7.赋值展示图片

foreach(ICogGraphic s in dt) { mToolBlock.AddGraphicToRunRecord(s, lastRecord, "CogPMAlignMultiTool1.InputImage", "script"); }

8.脚本All

#region namespace imports using System; using System.Collections; using System.Drawing; using System.IO; using System.Windows.Forms; using Cognex.VisionPro; using Cognex.VisionPro.ToolBlock; using Cognex.VisionPro3D; using Cognex.VisionPro.PMAlign; using Cognex.VisionPro.ImageProcessing; #endregion public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase { #region Private Member Variables private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock; #endregion private CogGraphicCollection dt = new CogGraphicCollection(); /// <summary> /// Called when the parent tool is run. /// Add code here to customize or replace the normal run behavior. /// </summary> /// <param name="message">Sets the Message in the tool's RunStatus.</param> /// <param name="result">Sets the Result in the tool's RunStatus</param> /// <returns>True if the tool should run normally, /// False if GroupRun customizes run behavior</returns> public override bool GroupRun(ref string message, ref CogToolResultConstants result) { // To let the execution stop in this script when a debugger is attached, uncomment the following lines. // #if DEBUG // if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); // #endif dt.Clear(); CogImageConvertTool image = new CogImageConvertTool(); image.InputImage = mToolBlock.Inputs["InputImage"].Value as ICogImage; image.RunParams.RunMode = CogImageConvertRunModeConstants.Intensity; image.Run(); CogPMAlignMultiTool pma = mToolBlock.Tools["CogPMAlignMultiTool1"]as CogPMAlignMultiTool; pma.InputImage = image.OutputImage; pma.Run(); // Run each tool using the RunTool function foreach(ICogTool tool in mToolBlock.Tools) mToolBlock.RunTool(tool, ref message, ref result); string type = ""; for(int i = 0;i < pma.Results.ResultItemCollection.Count;i++) { switch(pma.Results.ResultItemCollection[i].Name) { case"青蛙": type = "青蛙"; break; case"笑脸": type = "笑脸"; break; case"爱心": type = "爱心"; break; } dt.Add(createlabel("类型是:" + type, 25, 10, 10, CogColorConstants.Blue)); dt.Add(createlabel(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 25, 10, 90, CogColorConstants.Green)); } return false; } private CogGraphicLabel createlabel(string text, float size, double x, double y, CogColorConstants color) { CogGraphicLabel label = new CogGraphicLabel(); label.Alignment = CogGraphicLabelAlignmentConstants.TopLeft; label.BackgroundColor = CogColorConstants.White; label.Color = color; label.Font = new Font("Arial", size, FontStyle.Bold, GraphicsUnit.Pixel); label.SetXYText(x, y, text); return label; } #region When the Current Run Record is Created /// <summary> /// Called when the current record may have changed and is being reconstructed /// </summary> /// <param name="currentRecord"> /// The new currentRecord is available to be initialized or customized.</param> public override void ModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord) { } #endregion #region When the Last Run Record is Created /// <summary> /// Called when the last run record may have changed and is being reconstructed /// </summary> /// <param name="lastRecord"> /// The new last run record is available to be initialized or customized.</param> public override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord) { foreach(ICogGraphic s in dt) { mToolBlock.AddGraphicToRunRecord(s, lastRecord, "CogPMAlignMultiTool1.InputImage", "script"); } } #endregion #region When the Script is Initialized /// <summary> /// Perform any initialization required by your script here /// </summary> /// <param name="host">The host tool</param> public override void Initialize(Cognex.VisionPro.ToolGroup.CogToolGroup host) { // DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE base.Initialize(host); // Store a local copy of the script host this.mToolBlock = ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host)); } #endregion }

效果展示

http://www.jsqmd.com/news/620983/

相关文章:

  • OFA图像语义蕴含模型效果展示:contradiction高亮识别与错误假设预警能力
  • 深入解析AMD Versal自适应SoC:架构革新与多场景应用指南
  • Arduino CBUS按钮开关协议处理库CBUSSwitch详解
  • ARM 架构 JuiceFS 性能优化:基于 MLPerf 的实践与调优妒
  • KMS_VL_ALL_AIO完整指南:3分钟搞定Windows和Office激活的终极方案
  • 【Python实战】数据可视化自动化:matplotlib+pyecharts+AI智能推荐图表类型
  • Linux服务器网络突然不通?别慌,先检查一下nf_conntrack这张‘表’是不是满了
  • cocotb实战入门:从零搭建D触发器测试环境
  • 企业私有化IM哪个好? - BeeWorks
  • 全球线性可变位移传感器:工业数字化转型与智能制造驱动下的稳增进阶,2025年11.7亿,2032年规模19.25亿,2026-2032年CAGR7.5%
  • FastAPI项目半夜报警吵醒你?聊聊告警这事儿怎么搞!焉
  • MCP23017增强库:为HC-SR04超声波测距实现硬件级pulseIn()
  • 2026移动方舱技术全解析:保安岗亭/医院警务室/成品岗亭/治安岗亭/流动警务室/社区警务室/移动岗亭/移动方舱/选择指南 - 优质品牌商家
  • 联想 Yoga 7a 二合一笔记本:优缺点交织下的市场考验
  • 数据增强技术对比:Mosaic、Mixup、Cutout与CutMix的核心优势与应用场景
  • 2026年PC流量蓝海掘金:Bing开户公司排名与高价值人群触达策略
  • 算法备案不是终点,而是起点:AI原生软件全生命周期合规治理框架,覆盖需求→上线→迭代→下线4阶段
  • ADXL345驱动开发实战:I2Cdevlib在STM32与FreeRTOS中的工程集成
  • 从代码审计走进sql注入 --emlog篇
  • 9.9元ESP32-C3开发板实战:手把手教你用VSCode搭建RT-Thread最小系统(附调试技巧)
  • MetalLB才是给Ingress这个老登做负重前行的那个男人肚
  • PxMatrix LED矩阵驱动库:高性能HUB75显示方案详解
  • Win11家庭版无Hyper-V?手把手教你安装WSL2并迁移Ubuntu-24.04
  • Venera开源漫画阅读器:一站式管理本地与网络漫画的终极指南
  • 2026 年 5 款记账报税软件实测对比:零基础个体户 / 小微老板自己报税选它不踩坑
  • 测试工程师如何不被AI取代?防御性技能清单
  • 零基础入门:使用CYBER-VISION零号协议学习Python爬虫开发
  • 智能台灯项目复盘:从51单片机到产品思维的三个关键设计点
  • DFRobot_BMP280库深度解析:嵌入式BMP280传感器驱动开发指南
  • ORM性能测试Benchmark(最终版)偌