news 2026/7/24 20:48:20

机器视觉8 —— CogPatInspectTool 缺陷对比工具(加画轮廓)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
机器视觉8 —— CogPatInspectTool 缺陷对比工具(加画轮廓)

CogPatInspectTool主要用于缺陷检测和复杂模式分析

功能特点

  • 模式检测:能够根据图像中的特征和模式来检测目标物体,即使在复杂背景下也能准确识
  • 位置和角度检测:可以检测并识别目标物体的位置和角度信息,为后续的分析和处理提供基
  • 多目标识别:支持同时检测和识别多个目标物体,提高检测效率和准确
  • 结果分析:输出检测结果的位置信息和匹配度,方便用户对检测结果进行评估和判

工作原理:过将当前图像与“训练图像"进行对比,获取“原始差异图像"。再将“原始差异图像”与“阈
值图像”进行对比,进而获取“阈值差异图像",最约一到当前图像与训练图像的差异,通常差异区域即为缺陷所在。

(简介内容摘自豆包AI)

原图和脚本代码见文末

工具搭建

注意:要把CogPMAlignTool1工具的Pose给到CogPatInspectTool1工具

结果显示效果

画出有缺陷的部分

  1. 点击抓取训练图像与原点
  2. 切换到Current.TrainImage调整训练区域
  3. 点击训练新模式

运行工具得到已训练的结果

编写脚本画出缺陷轮廓

  1. 创建图形集合
  2. 循环blob工具找到的斑点
  3. 创建图形对象,把斑点轮廓画出来并添加到图形集合中
  4. 创建文本,根据blob斑点个数来修改文本的内容和颜色
  5. 添加文本到图像集合
  6. 添加显示

#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.CalibFix; using Cognex.VisionPro.PatInspect; using Cognex.VisionPro.Blob; #endregion public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase { #region Private Member Variables private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock; private CogGraphicCollection gc = new CogGraphicCollection(); // 创建图形集合 #endregion /// <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) { foreach(ICogTool tool in mToolBlock.Tools) mToolBlock.RunTool(tool, ref message, ref result); gc.Clear(); // 清除图形集合 CogBlobTool blob1 = mToolBlock.Tools["CogBlobTool1"] as CogBlobTool; // 循环找到的blob斑点并画出其轮廓 for (int i = 0; i < blob1.Results.GetBlobs().Count; i++) { CogPolygon p = new CogPolygon(); p = blob1.Results.GetBlobs()[i].GetBoundary(); p.Color = CogColorConstants.Red; gc.Add(p); } // 创建label根据找到的blob斑点个数修改其颜色的文本内容 CogGraphicLabel label1 = new CogGraphicLabel(); label1.Font = new Font("楷体",30); if (blob1.Results.GetBlobs().Count > 0) { label1.Color = CogColorConstants.Red; label1.SetXYText(200, 200, "NG"); } else { label1.Color = CogColorConstants.Green; label1.SetXYText(200, 200, "OK"); } gc.Add(label1); return false; } #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 item in gc) { mToolBlock.AddGraphicToRunRecord(item, lastRecord, "CogPMAlignTool1.InputImage", ""); } } #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 }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/24 20:47:30

WebSocket 跨站劫持(CSWSH)漏洞原理与 PortSwigger Lab 实战

在开始实战前向大家推荐一个比较好用的插件&#xff08;这一关可以用到&#xff09;具体作用是实时更换session和查询第一步&#xff1a;进入 Live chat&#xff0c;发送一条消息Click "Live chat" and send a chat message.为什么&#xff1f;因为你需要先知道WebSo…

作者头像 李华
网站建设 2026/7/24 20:47:03

HarmonyOS ArkTS 实战:实现一个校园竞赛报名与项目管理应用

HarmonyOS ArkTS 实战&#xff1a;校园竞赛报名与项目管理完整实现 摘要项目难度&#xff1a;⭐⭐⭐ 中级实战 适用人群&#xff1a;有 ArkTS 基础、希望学习学习类应用开发的 HarmonyOS 开发者 开发环境&#xff1a;DevEco Studio Next / API 24 代码规模&#xff1a;单页面约…

作者头像 李华
网站建设 2026/7/24 20:46:56

类中的流操作符的重载

目录 摘要&#xff1a; 一&#xff1a;理解cout的本质 二&#xff1a;<<操作符的重载 问题1&#xff1a;参数颠倒 问题2&#xff1a;无法访问私有成员变量 问题3&#xff1a;无法连续使用<< 问题4&#xff1a;最终版本 三&#xff1a;>>操作符的重载…

作者头像 李华
网站建设 2026/7/24 20:46:43

河南精密机加工工厂|10 人 SolidWorks+UG 共享云主机完整配置方案

河南本地精密机加工企业以五金精密零部件、汽车结构件、工装夹具、模具加工为主&#xff0c;研发团队一般 8–10 人&#xff0c;同时使用 SolidWorks 做零件 / 工装建模、UG 做分型与多轴刀路编程。传统一人一台工作站投入高、新旧电脑性能参差不齐、图纸分散易流失、车间电磁干…

作者头像 李华
网站建设 2026/7/24 20:45:21

宇树 G1/H1 人形机器人动作捕捉与实时模仿系统

该系统本质上不是传统的“机器人自己规划路线”&#xff0c;而是一套&#xff1a; 人体动作采集 实时遥操作 动作重定向 全身平衡控制 示教数据训练 系统&#xff0c;它要解决的核心问题不是“机器人从哪里走到哪里”&#xff0c;而是&#xff1a; 人做出一个动作后&#x…

作者头像 李华