Visonpro 检测是否有缺齿

一、效果展示

二、上面是原展开工具CogPolarUnwrapTool;

第二种方法: 用Blob 和 CogCopyRegionTool

 

三、 用预处理工具  加减常数,让图片变得更亮点

四、圆展开工具

 

五、模板匹配

六、代码分解

1.创建集合和文子显示工具

CogGraphicCollection dt = new CogGraphicCollection();CogGraphicLabel Label;

2.加载工具,并实例化一个List集合

 dt.Clear();CogPolarUnwrapTool polar = mToolBlock.Tools["CogPolarUnwrapTool1"]as CogPolarUnwrapTool;CogPMAlignTool pma = mToolBlock.Tools["CogPMAlignTool1"]as CogPMAlignTool;List<double> listX = new List<double>();

3.定义图标中的坐标吗,添加集合,排序

 double total = 0;double x, y;for(int i = 0;i < pma.Results.Count;i++){listX.Add(pma.Results[i].GetPose().TranslationX);total += pma.Results[i].GetPose().TranslationY;}y = total / pma.Results.Count;listX.Sort();

4.进行传参,找出之前的x和y坐标系,并用参数接收是否存在缺失

int a = 0;for(int i = 0;i < listX.Count - 1;i++){if((listX[i + 1] - listX[i]) > 50){x = (listX[i + 1] + listX[i]) / 2;y = total / pma.Results.Count;double lastx,lasty;polar.RunParams.GetInputPointFromOutputPoint(polar.InputImage, polar.Region, x, y, out lastx, out lasty);dt.Add(Create(lastx, lasty));a++;}}

5.进行判断是否缺失

 Label = new CogGraphicLabel();if(a > 0){Label.SetXYText(100, 100, "缺失"+a);Label.Color = CogColorConstants.Red;Label.Font = new Font("楷体", 30);dt.Add(Label);}else{Label.SetXYText(100, 100, "OK");Label.Color = CogColorConstants.Green;Label.Font = new Font("楷体", 30);dt.Add(Label);}

6.将上面传入圆展开的x,y坐标,进行创建圆

private CogCircle Create(double x, double y){CogCircle co = new CogCircle();co.CenterX = x;co.CenterY = y;co.Radius = 20;co.LineWidthInScreenPixels = 6;co.Color = CogColorConstants.Red;dt.Add(co);return co;}

7.输出

for(int i = 0;i < dt.Count;i++){mToolBlock.AddGraphicToRunRecord(dt[i], lastRecord, "CogIPOneImageTool1.InputImage", "");}

8.代码All

#region namespace imports
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro3D;
using Cognex.VisionPro.ImageProcessing;
using Cognex.VisionPro.PMAlign;
#endregionpublic class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{#region Private Member Variablesprivate Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;#endregionCogGraphicCollection dt = new CogGraphicCollection();CogGraphicLabel Label;/// <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();// #endifdt.Clear();CogPolarUnwrapTool polar = mToolBlock.Tools["CogPolarUnwrapTool1"]as CogPolarUnwrapTool;CogPMAlignTool pma = mToolBlock.Tools["CogPMAlignTool1"]as CogPMAlignTool;List<double> listX = new List<double>();// Run each tool using the RunTool functionforeach(ICogTool tool in mToolBlock.Tools)mToolBlock.RunTool(tool, ref message, ref result);double total = 0;double x, y;for(int i = 0;i < pma.Results.Count;i++){listX.Add(pma.Results[i].GetPose().TranslationX);total += pma.Results[i].GetPose().TranslationY;}y = total / pma.Results.Count;listX.Sort();int a = 0;for(int i = 0;i < listX.Count - 1;i++){if((listX[i + 1] - listX[i]) > 50){x = (listX[i + 1] + listX[i]) / 2;y = total / pma.Results.Count;double lastx,lasty;polar.RunParams.GetInputPointFromOutputPoint(polar.InputImage, polar.Region, x, y, out lastx, out lasty);dt.Add(Create(lastx, lasty));a++;}}Label = new CogGraphicLabel();if(a > 0){Label.SetXYText(100, 100, "缺失"+a);Label.Color = CogColorConstants.Red;Label.Font = new Font("楷体", 30);dt.Add(Label);}else{Label.SetXYText(100, 100, "OK");Label.Color = CogColorConstants.Green;Label.Font = new Font("楷体", 30);dt.Add(Label);}return false;}private CogCircle Create(double x, double y){CogCircle co = new CogCircle();co.CenterX = x;co.CenterY = y;co.Radius = 20;co.LineWidthInScreenPixels = 6;co.Color = CogColorConstants.Red;dt.Add(co);return co;}#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){for(int i = 0;i < dt.Count;i++){mToolBlock.AddGraphicToRunRecord(dt[i], lastRecord, "CogIPOneImageTool1.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 REMOVEbase.Initialize(host);// Store a local copy of the script hostthis.mToolBlock = ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));}#endregion}

 

七、polar.RunParams.GetInputPointFromOutputPoint

该方法用于输出图像中的坐标 (x, y) 转换为输入图像中的坐标 (lastx, lasty)

  • polar.InputImage 是输入图像对象
  • polar.Region 可能是指定的处理区域
  • x, y 是输出图像中的坐标
  • out lastx, out lasty 是输出参数,表示转换后的输入图像中的坐标。

​​​​​​​polar.RunParams.GetInputPointFromOutputPoint(

  1. polar.InputImage, // 输入图像

  2. polar.Region, // 处理区域

  3. x, // 输出图像中的X坐标

  4. y, // 输出图像中的Y坐标

  5. out lastx, // 输出:对应的输入图像中的X坐标

  6. out lasty // 输出:对应的输入图像中的Y坐标 );

​​​​​​​注意事项:

  1. 方法的作用:该方法的主要作用是将输出图像中的坐标映射回输入图像中的坐标,通常用于图像变换后的逆向坐标查找。
  2. 参数检查:确保 polar.InputImage 和 polar.Region 已正确初始化,并且 x, y 坐标在有效的范围内。
  3. 返回值lastx 和 lasty 是通过 out 参数返回的,因此调用后可以直接使用这两个变量获取转换后的坐标。

八、第二种方法

1.定义值

2. 工具展示

3. Blob设置

4.CogCopyReigonTool设置

添加终端链接

 

 

 5.CogBlob覆盖后设置

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.ImageProcessing;
using Cognex.VisionPro.Blob;
#endregionpublic class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{#region Private Member Variablesprivate Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;#endregionCogGraphicLabel label = new CogGraphicLabel();/// <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();// #endifint count = (int) mToolBlock.Inputs["Count"].Value;CogBlobTool blob = mToolBlock.Tools["CogBlobTool2"]as CogBlobTool;// Run each tool using the RunTool functionforeach(ICogTool tool in mToolBlock.Tools)mToolBlock.RunTool(tool, ref message, ref result);int currentCount = blob.Results.GetBlobs().Count;int diff = count - currentCount;string res = "";label.Color = CogColorConstants.Green;label.Font = new Font("宋体", 20);if (diff > 0){res = "缺失:" + diff;label.Color = CogColorConstants.Red;}else{res = "良品";}label.SetXYText(100, 250, res);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){mToolBlock.AddGraphicToRunRecord(label, lastRecord, "CogIPOneImageTool1.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 REMOVEbase.Initialize(host);// Store a local copy of the script hostthis.mToolBlock = ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));}#endregion}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/19181.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

线性表之顺序表

目录 一 线性表 1概念&#xff1a; 2分类 3特点 二 顺序表 1概念 2结构 3分类 4静态线性表&#xff08;使用定长数组存储元素&#xff09; 4.1结构 4.2 静态顺序表缺陷 5 动态顺序表&#xff08;利用动态内存管理实现内存的变化&#xff09; 5.1结构【因为动态顺序表的…

IoTDB 常见问题 QA 第五期

关于 IoTDB 的 Q & A 情人节之际&#xff0c;让 IoTDB Q&A 陪您一起共度解惑&#xff01;我们将定期汇总我们将定期汇总社区讨论频繁的问题&#xff0c;并展开进行详细回答&#xff0c;通过积累常见问题“小百科”&#xff0c;方便大家使用 IoTDB。 Q1&#xff1a;导入…

【NLP】文本预处理

目录 一、文本处理的基本方法 1.1 分词 1.2 命名体实体识别 1.3 词性标注 二、文本张量的表示形式 2.1 one-hot编码 2.2 word2vec 模型 2.2.1 CBOW模式 2.2.2 skipgram模式 2.3 词嵌入word embedding 三、文本数据分析 3.1 标签数量分布 3.2 句子长度分布 3.3 词…

1-16 tortoiseGit分支与Git操作

1-1 创建分支 什么时候需要开分支&#xff1f; - 隔离线上版本和开发版本 - 大功能开发&#xff0c;不想影响到其他人&#xff0c;自己独立开个分支去开发 SVN经典目录结构&#xff1a; - trunk-------------------------开发中的文件 - bran…

4090单卡挑战DeepSeek r1 671b:尝试量化后的心得的分享

引言&#xff1a; 最近&#xff0c;DeepSeek-R1在完全开源的背景下&#xff0c;与OpenAI的O1推理模型展开了激烈竞争&#xff0c;引发了广泛关注。为了让更多本地用户能够运行DeepSeek&#xff0c;我们成功将R1 671B参数模型从720GB压缩至131GB&#xff0c;减少了80%&#xff…

frp与云服务器内网穿透

最近想使用一个便宜的云服务器进行内网穿透&#xff0c;访问到本地电脑 之前使用ssh一直没成功&#xff0c;原因还没分析出来&#xff0c;后来换了一种方法&#xff0c;使用frp来进行内网穿透 frp内网穿透搭建 frp简介 frp 是一个专注于内网穿透的高性能的反向代理应用&…

题海拾贝:英语作文(map)

Hello大家好&#xff01;很高兴我们又见面啦&#xff01;给生活添点passion&#xff0c;开始今天的编程之路&#xff01; 我的博客&#xff1a;<但凡. 我的专栏&#xff1a;《编程之路》、《数据结构与算法之美》、《题海拾贝》 欢迎点赞&#xff0c;关注&#xff01; 1、题…

matlab欠驱动船舶模型预测控制

1、内容简介 matlab135-欠驱动船舶模型预测控制 可以交流、咨询、答疑 2、内容说明 略 针对在风 、 浪 、 流时变干扰下欠驱动水面船舶的轨迹跟踪控制问题 &#xff0c; 设计了一种基于模型 预测控制的轨迹跟踪控制器 &#xff0e; 考虑到欠驱动船舶在没有横向驱动力情况下…

2025年-数据库排名

2025年-数据库排名 https://db-engines.com/en/ranking RADB 完整排名 TOP 10 向量 DBMS 的 DB-Engines 排名 关系型 DBMS 的 DB-Engines 排名 搜索引擎的 DB-Engines 排名 键值存储的 DB-Engines 排名 文档存储的 DB-Engines 排名 图形 DBMS 的 DB-Engines 排名 时间序列 DBM…

sib报错:com.*.xctrunner is not in your device!

1、问题描述 在使用sonic集成IOS设备的时候,我们需要通过sonic-agent服务去识别IOS设备。但是在识别的时候提示如下问题: 本质就是在你这个设备中找不到这个设备也就是找不到WebDriverAgentRunner,但是确实安装了,甚至appium可以正常的调用。 或执行如下命令的时候报错:…

rabbitmq五种模式的总结——附java-se实现(详细)

rabbitmq五种模式的总结 完整项目地址&#xff1a;https://github.com/9lucifer/rabbitmq4j-learning 一、简单模式 &#xff08;一&#xff09;简单模式概述 RabbitMQ 的简单模式是最基础的消息队列模式&#xff0c;包含以下两个角色&#xff1a; 生产者&#xff1a;负责发…

LangChain大模型应用开发:提示词工程应用与实践

介绍 大家好&#xff0c;博主又来给大家分享知识了。今天给大家分享的内容是LangChain提示词工程应用与实践。 在如今火热的大语言模型应用领域里&#xff0c;LangChain可是一个相当强大且实用的工具。而其中的提示词(Prompt)&#xff0c;更是我们与语言模型进行有效沟通的关…

4.buuctf [SWPU2019]Web1及知识点

进入题目页面如下 猜测是二次注入 先注册一个账号 再登录&#xff0c;页面如下 点击申请发布广告 页面如上&#xff0c;存在注入点&#xff0c;尝试 判读是整数型注入还是字符型注入 猜解字段数&#xff0c;尝试发现or,#,空格等被过滤了&#xff0c;只能一个一个试 使用联合…

Lua笔记

Lua语法 --注释 #字符串长度、table从1开始连续元素的长度 ..字符串拼接 逻辑运算符 and or not 条件语句 if xxx then elseif yyy then else end 循环语句 for i1,xxx do end xLua AppDomain does not contain a definition for DefineDynamicAssembly&#xff…

开业盛典活动策划方案拆解

道叔来给大家详细剖析咱们方案库里刚收录的这份《蜀大侠火锅店武侠风开业盛典活动策划方案》了&#xff0c;保证让你看完直呼过瘾&#xff0c;收获满满&#xff01; 一、主题创意&#xff1a;武侠风&#xff0c;直击人心 首先&#xff0c;咱们得夸一下这活动的主题——“XXX‘…

三、Unity基础(主要框架)

一、Unity场景概念 如果把游戏运行过程理解成表演&#xff0c;那么场景就是舞台&#xff1b; 场景本质上是一个配置文件&#xff0c;这个配置文件决定了场景中有哪些东西&#xff1b; 二、Scene和Game窗口 1、Scene 滚轮缩放、拖动 单独选中也可以 最下面这个是全能工具…

微软官方出品GPT大模型编排工具:7个开源项目

今天一起盘点下&#xff0c;12月份推荐的7个.Net开源项目&#xff08;点击标题查看详情&#xff09;。 1、一个浏览器自动化操作的.Net开源库 这是一个基于 Google 开源的 Node.js 库 Puppeteer 的 .NET 开源库&#xff0c;方便开发人员使用无头 Web 浏览器抓取 Web、检索 Ja…

C++笔记之类型大小、变量大小,vector与string在栈上内存、堆上内存和总内存的关系

C++笔记之类型大小、变量大小,vector与string在栈上内存、堆上内存和总内存的关系 code review! 文章目录 C++笔记之类型大小、变量大小,vector与string在栈上内存、堆上内存和总内存的关系1.`std::vector<float>` 的内存占用2.`std::vector<float>` 的 `capaci…

华为昇腾920b服务器部署DeepSeek翻车现场

最近到祸一台HUAWEI Kunpeng 920 5250&#xff0c;先看看配置。之前是部署的讯飞大模型&#xff0c;发现资源利用率太低了。把5台减少到3台&#xff0c;就出了他 硬件配置信息 基本硬件信息 按照惯例先来看看配置。一共3块盘&#xff0c;500G的系统盘&#xff0c; 2块3T固态…

【工具变量】ZF引导基金合集(1900-2024年)

政府引导基金是以股权或债权等方式投资于创业风险投资机构或新设的创业风险投资基金&#xff0c;主要用于支持创业企业的发展。根据不同类型的基金&#xff0c;基金出资结构有所不同&#xff0c;可能由政府全额或部分出资&#xff0c;并吸引社会资本和金融机构的参与。 一、政府…