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.mzph.cn/web/69942.shtml

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

相关文章

RabbitMQ介绍以及基本使用

文章目录 一、什么是消息队列&#xff1f; 二、消息队列的作用&#xff08;优点&#xff09; 1、解耦 2、流量削峰 3、异步 4、顺序性 三、RabbitMQ基本结构 四、RabbitMQ队列模式 1、简单队列模式 2、工作队列模式 3、发布/订阅模式 4、路由模式 5、主题模式 6、…

服务器租用:虚拟化技术都包含哪些内容?

服务器作为常见的网络设备&#xff0c;有着物理服务器、云服务器和虚拟服务器等多种类型&#xff0c;其中虚拟服务器主要是依靠虚拟化技术将物理服务器划分成多个虚拟机&#xff0c;以此来充分利用服务器资源&#xff0c;那虚拟化技术都包含了哪些内容呢&#xff1f; 硬件虚拟化…

基于JAVA的幼儿园管理系统的设计与实现源码(springboot+vue+mysql)

项目简介 幼儿园管理系统实现了以下功能&#xff1a; 基于JAVA的幼儿园管理系统的设计与实现的主要使用者管理员可以管理系统基本信息&#xff1b;管理轮播图、系统简介、教师管理、课程管理、幼儿活动管理、餐饮管理、留言管理等功能&#xff1b;前台用户注册登录&#xff0…

sql难点

一、 假设你有一个查询&#xff0c;需要根据 id 是否为 null 来动态生成 SQL 条件&#xff1a; xml复制 <select id"getResources" resultType"Resource">SELECT * FROM resources<where><if test"id ! null">and id <!…

《Operating System Concepts》阅读笔记:p13-p16

《Operating System Concepts》学习第 4 天&#xff0c;p13-p16 总结&#xff0c;总计 4 页。 一、技术总结 1.storage 指令只能在 memory 上执行&#xff0c;所以要执行程序&#xff0c;那么就要加载到内存上。 2.primary storage primary storage 包含下面这些分类&…

最新国内 ChatGPT Plus/Pro 获取教程

最后更新版本&#xff1a;20250202 教程介绍&#xff1a; 本文将详细介绍如何快速获取一张虚拟信用卡&#xff0c;并通过该卡来获取ChatGPT Plus和ChatGPT Pro。 # 教程全程约15分钟开通ChatGPT Plus会员帐号前准备工作 一个尚未升级的ChatGPT帐号&#xff01;一张虚拟信用卡…

Python中使用Minio实现图像或视频文件的存储

目录 一、Minio的基本介绍1.Minio是什么2.Minio的优势 二、使用步骤1.启动Minio2.创建桶3.在Python中使用Minio3.1安装并导入minio包3.2创建mino_utils工具类 三、操作演示1.引入minio_utils工具类2.上传视频文件3.获取视频文件 总结 一、Minio的基本介绍 1.Minio是什么 Mini…

[JVM篇]虚拟机性能监控、故障处理工具

虚拟机性能监控、故障处理工具 基础故障处理工具 jps&#xff08;JVM Peocess Status Tool - 虚拟机进程状况工具&#xff09; jstat(JVM Statistics Monitoring Too - 虚拟机统计信息监视工具) jinfo( Configuration info for Java - Java配置信息工具) jmap(Memory Map for…

【数据结构】(9) 优先级队列(堆)

一、优先级队列 优先级队列不同于队列&#xff0c;队列是先进先出&#xff0c;优先级队列是优先级最高的先出。一般有两种操作&#xff1a;返回最高优先级对象&#xff0c;添加一个新对象。 二、堆 2.1、什么是堆 堆也是一种数据结构&#xff0c;是一棵完全二叉树&#xff0c…

快速设置 Docker 网络代理配置

Docker Client - 代理访问远程的 Docker Daemon 在 Client 端设置代理其实就是设置 Linux 系统的代理&#xff0c;从而让系统的命令行可以通过代理连接到外部的网络。一般只需要配置 HTTP_PROXY 与 HTTPS_PROXY 这两个即可。 临时生效&#xff1a; 在命令行中执行下面的命令&…

Vript-Hard——一个基于高分辨率和详细字幕的视频理解算法

一、概述 多模态学习的最新进展促进了对视频理解和生成模型的研究。随之而来的是&#xff0c;对高分辨率视频和详细说明所建立的高质量数据集的需求激增。然而&#xff0c;由于时间因素的影响&#xff0c;视频与文本的配对不像图像那样容易。准备视频和文本配对是一项困难得多…

记录阿里云CDN配置

网站接入CDN全流程&#xff0c;共4步&#xff01;-阿里云开发者社区 1、开通阿里云CDN服务 2、添加加速域名 3、验证域名归属权 4、域名添加CDN生成的CNAME解析 按照官网描述增加。细节点&#xff1a; 1. 域名和泛域名区别 2.开启https,要用nginx的证书&#xff0c;和项…

FFmpeg源码:url_find_protocol函数分析

一、url_find_protocol函数的定义 url_find_protocol函数定义在FFmpeg源码&#xff08;本文演示用的FFmpeg源码版本为7.0.1&#xff09;的源文件libavformat/avio.c中&#xff1a; static const struct URLProtocol *url_find_protocol(const char *filename) {const URLProt…

DeepSeek 助力 Vue 开发:打造丝滑的无限滚动(Infinite Scroll)

前言&#xff1a;哈喽&#xff0c;大家好&#xff0c;今天给大家分享一篇文章&#xff01;并提供具体代码帮助大家深入理解&#xff0c;彻底掌握&#xff01;创作不易&#xff0c;如果能帮助到大家或者给大家一些灵感和启发&#xff0c;欢迎收藏关注哦 &#x1f495; 目录 Deep…

【区块链】零知识证明基础概念详解

&#x1f308;个人主页: 鑫宝Code &#x1f525;热门专栏: 闲话杂谈&#xff5c; 炫酷HTML | JavaScript基础 ​&#x1f4ab;个人格言: "如无必要&#xff0c;勿增实体" 文章目录 零知识证明基础概念详解引言1. 零知识证明的定义与特性1.1 基本定义1.2 三个核心…

蓝桥杯篇---IAP15F2K61S2串口

文章目录 前言简介串口通信的基本参数1.波特率2.数据位3.停止位4.校验位 串口相关寄存器1.SCON2.SBUF3.PCON4.TMOD5.TH1/TL1 串口使用步骤1.配置波特率2.配置串口模式3.使能串口中断4.发送数据5.接收数据6.处理中断 示例代码&#xff1a;串口发送与接收示例代码&#xff1a;串口…

「vue3-element-admin」Vue3 + TypeScript 项目整合 Animate.css 动画效果实战指南

&#x1f680; 作者主页&#xff1a; 有来技术 &#x1f525; 开源项目&#xff1a; youlai-mall ︱vue3-element-admin︱youlai-boot︱vue-uniapp-template &#x1f33a; 仓库主页&#xff1a; GitCode︱ Gitee ︱ Github &#x1f496; 欢迎点赞 &#x1f44d; 收藏 ⭐评论 …

MyBatis:动态SQL高级标签使用方法指南

一、引言 目前互联网大厂在搭建后端Java服务时&#xff0c;常使用Springboot搭配Mybatis/Mybatis-plus的框架。Mybatis/Mybatis-plus之所以能成为当前国内主流的持久层框架&#xff0c;与其本身的优点有关&#xff1a;支持定制动态 SQL、存储过程及高级映射&#xff0c;简化数…

untiy3D 让角色动起来,角色动画的使用

1.untiy 商店下载动画模型 2.导入项目 模型拖入到场景中 3.创建动画器控制器 4.动画控制器挂载到plarer上 5.把动画idle和pickup拖入到动画器 6.右键动画创建过渡效果(Make Transition) 6.设置参数用条件控制 7.当选中参数时启动过渡 运行效果 119 (二)用脚本控制动画…

XXL-Job入门

XXL-Job入门 什么是xxl-job&#xff1f; ​ xxl-job是一个分布式的任务调度平台&#xff0c;其核心设计目标是&#xff1a;学习简单、开发迅速、轻量级、易扩展&#xff0c;现在已经开放源代码并接入多家公司的线上产品线&#xff0c;开箱即用。xxl是xxl-job的开发者…