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(
-
polar.InputImage, // 输入图像
-
polar.Region, // 处理区域
-
x, // 输出图像中的X坐标
-
y, // 输出图像中的Y坐标
-
out lastx, // 输出:对应的输入图像中的X坐标
-
out lasty // 输出:对应的输入图像中的Y坐标 );
注意事项:
- 方法的作用:该方法的主要作用是将输出图像中的坐标映射回输入图像中的坐标,通常用于图像变换后的逆向坐标查找。
- 参数检查:确保
polar.InputImage和polar.Region已正确初始化,并且x, y坐标在有效的范围内。 - 返回值:
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}
相关文章:
Visonpro 检测是否有缺齿
一、效果展示 二、上面是原展开工具CogPolarUnwrapTool; 第二种方法: 用Blob 和 CogCopyRegionTool 三、 用预处理工具 加减常数,让图片变得更亮点 四、圆展开工具 五、模板匹配 六、代码分解 1.创建集合和文子显示工具 CogGraphicCollec…...
第1章大型互联网公司的基础架构——1.6 RPC服务
你可能在1.1节的引言中注意到业务服务层包括HTTP服务和RPC服务,两者的定位不一样。一般来说,一个业务场景的核心逻辑都是在RPC服务中实现的,强调的是服务于后台系统内部,所谓的“微服务”主要指的就是RPC服务;而HTTP服…...
今日AI和商界事件(2025-02-15)
根据2025年2月15日的科技动态,以下是今日AI领域的重要事件及相关进展总结: 1. DeepSeek日活突破3000万,开源生态加速AI普惠 里程碑意义:开源大模型DeepSeek宣布日活跃用户数突破3000万,其R1模型凭借开源策略和低成本优…...
算法题(69):搜索插入位置
审题: 需要我们在有序数组中找到等于target值的元素的下标若没有则返回target按顺序会插入的位置的索引 思路 : 我们可以使用二分查找的方法 方法一:二分查找 和普通的二分查找不同,本题若没有找到就需要返回它按顺序插入的位置的…...
在 Linux 系统中,tc(Traffic Control) QoS 常用命令简介
在 Linux 系统中,tc(Traffic Control)命令是一个强大的工具,用于配置和管理网络流量控制。以下是 tc 命令的常用功能和基本用法: 1. 查看当前队列规则 使用以下命令查看指定网络接口上的队列规则: tc qd…...
如何画产品功能图、结构图
功能图的类型 常见的功能图包括数据流图、用例图、活动图、状态图、类图、组件图、部署图等等,不同的应用场景和目标下,需要确定不同的功能图类型。 数据流图 用例图 状态图 类图 组件图 组件图是由软件系统、组件和组件之间的关系组成的图形…...
4090单卡挑战DeepSeek r1 671b:尝试量化后的心得的分享
引言: 最近,DeepSeek-R1在完全开源的背景下,与OpenAI的O1推理模型展开了激烈竞争,引发了广泛关注。为了让更多本地用户能够运行DeepSeek,我们成功将R1 671B参数模型从720GB压缩至131GB,减少了80%ÿ…...
SpringBoot速成(12)文章分类P15-P19
1.新增文章分类 1.Postman登录不上,可以从头registe->login一个新的成员:注意,跳转多个url时,post/get/patch记得修改成controller类中对应方法上写的 2.postman运行成功: 但表中不更新:细节有问题: c是…...
C++17中的clamp函数
一、std::clamp() 其实在前面简单介绍过这个函数,但当时只是一个集中的说明,为了更好的理解std::clamp的应用,本篇再详细进行阐述一次。std::clamp在C17中其定义的方式为: template< class T > constexpr const T& cl…...
配置Open-R1,评测第三方蒸馏模型的性能1
年前DeepSeek不温不火,问题的响应极。一回车,就看模型如口吐莲花般,先是输出思维过程,虽然中间绕来绕去,但是输出回答时还是准确而简洁的。比如,用它来读当时出来的几篇文章,确实大大提升了效率…...
Chrome插件开发流程
Chrome插件开发流程可以分为以下几个主要步骤: ### 1. 确定插件功能和目标 在开始开发之前,首先需要明确插件的功能和目标。这包括: - **功能定义**:确定插件要解决的问题或提供的功能。 - **市场分析**:了解目标用户群…...
物联网行业通识:从入门到深度解析
物联网行业通识:从入门到深度解析 (图1:物联网生态示意图) 一、引言:万物互联时代的到来 根据IDC最新预测,到2025年全球物联网设备连接数将突破410亿,市场规模达1.1万亿美元。物联网ÿ…...
【做一个微信小程序】校园事件页面实现
前言 为了进一步扩展校园事件页面的功能,我们可以添加 搜索、分类筛选 和 渐变卡片色 等特性。以下是详细的方案和源码实现。 扩展功能设计 1. 搜索功能 在页面顶部添加搜索框,用户输入关键词后,筛选出匹配的事件。2. 分类筛选 在页面顶部添加分类标签(如“全部”、“活动…...
C++基础系列【14】继承与多态
博主介绍:程序喵大人 35- 资深C/C/Rust/Android/iOS客户端开发10年大厂工作经验嵌入式/人工智能/自动驾驶/音视频/游戏开发入门级选手《C20高级编程》《C23高级编程》等多本书籍著译者更多原创精品文章,首发gzh,见文末👇…...
DeepSeek-R1 大模型本地部署指南
文章目录 一、系统要求硬件要求软件环境 二、部署流程1. 环境准备2. 模型获取3. 推理代码配置4. 启动推理服务 三、优化方案1. 显存优化技术2. 性能加速方案 四、部署验证健康检查脚本预期输出特征 五、常见问题解决1. CUDA内存不足2. 分词器警告处理3. 多GPU部署 六、安全合规…...
在conda环境下,安装Pytorch和CUDA
系统 : Ubuntu20.04 显卡:NVIDIA GTX1650 显卡驱动已经装好(命令 nvidia-smi 查看显卡配置) (主要看一下第一行的参数,最大支持的CUDA版本为12.4 ) Aanconda 版本(安装指南)(似乎…...
Java里int和Integer的区别?
大家好,我是锋哥。今天分享关于【Java里int和Integer的区别?】面试题。希望对大家有帮助; Java里int和Integer的区别? 1000道 互联网大厂Java工程师 精选面试题-Java资源分享网 在 Java 中,int 和 Integer 都是用来表…...
【第13章:自监督学习与少样本学习—13.4 自监督学习与少样本学习的未来研究方向与挑战】
凌晨三点的实验室里,博士生小张盯着屏幕上的训练曲线——他设计的跨模态少样本学习模型在医疗影像诊断任务上突然出现了诡异的性能断崖。前一秒还在92%的准确率高位运行,下一秒就暴跌到47%。这个看似灾难性的现象,却意外揭开了自监督学习与少样本学习技术深藏的核心挑战… 一…...
【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 词…...
deepseek r1从零搭建本地知识库10:嵌入模型和知识库建设
一、嵌入模型(Embedding Model)是什么? 1. 定义 嵌入模型是一种将文本、图像、音频等非结构化数据转化为**低维稠密向量(Dense Vector)**的算法模型,这些向量(通常几百到几千维)能够…...
5大实战技巧:用GRETNA脑网络分析工具包解决神经影像研究难题
5大实战技巧:用GRETNA脑网络分析工具包解决神经影像研究难题 【免费下载链接】GRETNA A Graph-theoretical Network Analysis Toolkit in MATLAB 项目地址: https://gitcode.com/gh_mirrors/gr/GRETNA GRETNA(Graph-theoretical Network Analysis…...
如何为Royal TSX打造完美中文体验?完整汉化包使用指南
如何为Royal TSX打造完美中文体验?完整汉化包使用指南 【免费下载链接】Royal_TSX_Chinese_Language_Pack Royal_TSX的简体中文汉化包 项目地址: https://gitcode.com/gh_mirrors/ro/Royal_TSX_Chinese_Language_Pack Royal_TSX_Chinese_Language_Pack是一个…...
拆解一个开源ETL工具:我是如何复用Kettle Web版前端,快速搭建内部数据集成平台的
拆解开源ETL工具:复用Kettle Web前端构建轻量级数据集成平台 在中小企业数据治理的实践中,ETL(数据抽取、转换、加载)工具是数据仓库建设的核心组件。当团队需要快速搭建内部数据集成平台时,完全从零开发显然效率低下&…...
5个关键技巧掌握Arduino CLI:从零开始构建你的硬件开发工作流
5个关键技巧掌握Arduino CLI:从零开始构建你的硬件开发工作流 【免费下载链接】arduino-cli Arduino command line tool 项目地址: https://gitcode.com/gh_mirrors/ar/arduino-cli 你是否曾经想过,如果Arduino开发能像Linux命令行一样高效流畅会…...
免费开源电路板查看器:OpenBoardView 终极解决方案
免费开源电路板查看器:OpenBoardView 终极解决方案 【免费下载链接】OpenBoardView View .brd files 项目地址: https://gitcode.com/gh_mirrors/op/OpenBoardView 对于电子工程师、维修技术人员和硬件爱好者而言,查看和分析.brd电路板文件是一项…...
基于Bubble Tea的Docker/Podman TUI管理工具goManageDocker实战指南
1. 项目概述:告别命令行记忆,用TUI高效管理Docker与Podman 作为一名常年和容器打交道的开发者,我猜你肯定有过这样的经历:临时需要重启一个容器,却死活想不起来 docker restart 后面是该跟容器ID还是容器名ÿ…...
蓝桥杯单片机备赛:手把手教你用DS1302实现一个带暂停/调整功能的电子时钟(附完整代码)
蓝桥杯单片机备赛:手把手教你用DS1302实现一个带暂停/调整功能的电子时钟(附完整代码) 在蓝桥杯单片机竞赛中,实时时钟模块是常见的基础功能之一。DS1302作为一款经典的时钟芯片,以其简单可靠的特性成为比赛中的热门选…...
GetQzonehistory:三步轻松备份你的QQ空间完整历史说说
GetQzonehistory:三步轻松备份你的QQ空间完整历史说说 【免费下载链接】GetQzonehistory 获取QQ空间发布的历史说说 项目地址: https://gitcode.com/GitHub_Trending/ge/GetQzonehistory 你是否曾经担心QQ空间里那些记录青春岁月的说说会随着时间流逝而消失&…...
ChatGPT API响应延迟优化实战:连接池与流式处理提升交互体验
1. 项目概述:当ChatGPT“卡顿”时,我们到底在修复什么?如果你经常使用基于OpenAI API构建的各类应用,无论是自己开发的聊天机器人、集成到工作流中的智能助手,还是第三方客户端,大概率都遇到过这种情况&…...
在openclaw agent工作流中接入taotoken实现模型调度
在OpenClaw Agent工作流中接入Taotoken实现模型调度 对于使用OpenClaw构建智能体工作流的开发者而言,灵活调度不同的大模型是提升应用能力的关键。Taotoken作为一个提供统一API接口的平台,能够简化这一过程。本文将引导你完成在OpenClaw Agent中配置Tao…...



