Visionpro 齿轮测量

  效果展示

一、题目要求 

求出最大值,最小值,平均值

二、分析

1.首先要进行模板匹配

2.划清匹配范围

3.匹配小三角的模板匹配

4.卡尺

5.用找圆工具 

工具

1.CogPMAlignTool

2.CogCaliperTool

3.CogFindCircleTool

4.CogFixtureTool

三、模板匹配工具

1.搜索区域

2.齿轮匹配

3.设置参数

 4.卡尺设置

 

5.找圆工具

 

四、代码分析

1.声明集合,文字显示工具,线段

 CogGraphicCollection dt = new CogGraphicCollection();CogGraphicLabel label;CogLineSegment line;

2.将工具进行实例化

 dt.Clear();CogPMAlignTool pma = mToolBlock.Tools["CogPMAlignTool2"]as CogPMAlignTool;CogCaliperTool caliper = mToolBlock.Tools["CogCaliperTool1"]as CogCaliperTool;CogFindCircleTool find = mToolBlock.Tools["CogFindCircleTool1"]as CogFindCircleTool;

3.解决实例化问题

4.声明List  弧度转角度(角度转弧度)遍历卡尺数量

公式:  弧度=角度/180*Math.PI

             角度=弧度*180/MathPI

 List<double> distance = new List<double>();for(int i = 0;i < pma.Results.Count;i++){double angle = pma.Results[i].GetPose().Rotation * 180 / Math.PI;double rad = (angle - 90) / 180 * Math.PI;caliper.Region.CenterX = pma.Results[i].GetPose().TranslationX;caliper.Region.CenterY = pma.Results[i].GetPose().TranslationY;caliper.Region.Rotation = rad;caliper.Run();

 5.卡尺找到的地方声明线段

 line = new CogLineSegment();line.SetStartEnd(find.Results.GetCircle().CenterX, find.Results.GetCircle().CenterY, caliper.Results[0].Edge0.PositionX, caliper.Results[0].Edge0.PositionY);line.LineWidthInScreenPixels = 1;line.Color = CogColorConstants.Red;dt.Add(line);

6.实例化点到点的距离工具 链接

  CogDistancePointPointTool dis = new CogDistancePointPointTool();dis.InputImage = mToolBlock.Inputs["OutputImage"].Value as CogImage8Grey;dis.StartX = find.Results.GetCircle().CenterX;dis.StartY = find.Results.GetCircle().CenterY;dis.EndX = caliper.Results[0].Edge0.PositionX;dis.EndY = caliper.Results[0].Edge0.PositionY;dis.Run();distance.Add(dis.Distance);

7.放置每个角的长度位置

 label = new CogGraphicLabel();label.Font = new Font("楷体", 8);label.Color = CogColorConstants.Purple;label.SetXYText(caliper.Results[0].Edge0.PositionX, caliper.Results[0].Edge0.PositionY, dis.Distance.ToString("F2"));dt.Add(label);

五、找出最大,最小,平均值

double Max = 0;double Small = distance[0];double total = 0;double average;for(int i = 0;i < distance.Count;i++){if(distance[i] > Max){Max = distance[i];}if(distance[i] < Small){Small = distance[i];}total += distance[i];}average = total / distance.Count;CogGraphicLabel label1 = new CogGraphicLabel();CogGraphicLabel label2 = new CogGraphicLabel();CogGraphicLabel label3 = new CogGraphicLabel();label1.SetXYText(100, 100, "最大值是:" + Max.ToString("F2"));label2.SetXYText(100, 130, "最小值是:" + Small.ToString("F2"));label3.SetXYText(100, 160, "平均值是:" + average.ToString("F2"));label1.Color = CogColorConstants.Red;label1.Font = new Font("楷体", 20);label2.Color = CogColorConstants.Red;label2.Font = new Font("楷体", 20);label3.Color = CogColorConstants.Red;label3.Font = new Font("楷体", 20);dt.Add(label1);dt.Add(label2);dt.Add(label3);

六、实现在图片工具图上

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

七、愚公搬代码

#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.Caliper;
using System.Collections.Generic;
using Cognex.VisionPro.Dimensioning;
#endregionpublic class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{#region Private Member Variablesprivate Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;#endregionCogGraphicCollection dt = new CogGraphicCollection();CogGraphicLabel label;CogLineSegment line;/// <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();CogPMAlignTool pma = mToolBlock.Tools["CogPMAlignTool2"]as CogPMAlignTool;CogCaliperTool caliper = mToolBlock.Tools["CogCaliperTool1"]as CogCaliperTool;CogFindCircleTool find = mToolBlock.Tools["CogFindCircleTool1"]as CogFindCircleTool;List<double> distance = new List<double>();// Run each tool using the RunTool functionforeach(ICogTool tool in mToolBlock.Tools)mToolBlock.RunTool(tool, ref message, ref result);for(int i = 0;i < pma.Results.Count;i++){double angle = pma.Results[i].GetPose().Rotation * 180 / Math.PI;double rad = (angle - 90) / 180 * Math.PI;caliper.Region.CenterX = pma.Results[i].GetPose().TranslationX;caliper.Region.CenterY = pma.Results[i].GetPose().TranslationY;caliper.Region.Rotation = rad;caliper.Run();line = new CogLineSegment();line.SetStartEnd(find.Results.GetCircle().CenterX, find.Results.GetCircle().CenterY, caliper.Results[0].Edge0.PositionX, caliper.Results[0].Edge0.PositionY);line.LineWidthInScreenPixels = 1;line.Color = CogColorConstants.Red;dt.Add(line);CogDistancePointPointTool dis = new CogDistancePointPointTool();dis.InputImage = mToolBlock.Inputs["OutputImage"].Value as CogImage8Grey;dis.StartX = find.Results.GetCircle().CenterX;dis.StartY = find.Results.GetCircle().CenterY;dis.EndX = caliper.Results[0].Edge0.PositionX;dis.EndY = caliper.Results[0].Edge0.PositionY;dis.Run();distance.Add(dis.Distance);label = new CogGraphicLabel();label.Font = new Font("楷体", 8);label.Color = CogColorConstants.Purple;label.SetXYText(caliper.Results[0].Edge0.PositionX, caliper.Results[0].Edge0.PositionY, dis.Distance.ToString("F2"));dt.Add(label);}double Max = 0;double Small = distance[0];double total = 0;double average;for(int i = 0;i < distance.Count;i++){if(distance[i] > Max){Max = distance[i];}if(distance[i] < Small){Small = distance[i];}total += distance[i];}average = total / distance.Count;CogGraphicLabel label1 = new CogGraphicLabel();CogGraphicLabel label2 = new CogGraphicLabel();CogGraphicLabel label3 = new CogGraphicLabel();label1.SetXYText(100, 100, "最大值是:" + Max.ToString("F2"));label2.SetXYText(100, 130, "最小值是:" + Small.ToString("F2"));label3.SetXYText(100, 160, "平均值是:" + average.ToString("F2"));label1.Color = CogColorConstants.Red;label1.Font = new Font("楷体", 20);label2.Color = CogColorConstants.Red;label2.Font = new Font("楷体", 20);label3.Color = CogColorConstants.Red;label3.Font = new Font("楷体", 20);dt.Add(label1);dt.Add(label2);dt.Add(label3);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 s in dt){mToolBlock.AddGraphicToRunRecord(s, 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 REMOVEbase.Initialize(host);// Store a local copy of the script hostthis.mToolBlock = ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));}#endregion}

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

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

相关文章

【ISO 14229-1:2023 UDS诊断(会话控制0x10服务)测试用例CAPL代码全解析②】

ISO 14229-1:2023 UDS诊断【会话控制0x10服务】_TestCase02 作者&#xff1a;车端域控测试工程师 更新日期&#xff1a;2025年02月15日 关键词&#xff1a;UDS诊断、0x10服务、诊断会话控制、ECU测试、ISO 14229-1:2023 TC10-002测试用例 用例ID测试场景验证要点参考条款预期…

AlmaLinux使用Ansible自动部署k8s集群

一、环境准备 节点规划&#xff08;最低要求&#xff09; 1台Master节点&#xff08;4核/8GB内存&#xff09;2台Worker节点&#xff08;2核/4GB内存&#xff09;1台Ansible控制机&#xff08;可复用Master节点&#xff09; 系统配置 # 所有节点执行 sudo hostnamectl set-hos…

机器学习:十大算法实现汇总

机器学习十大算法代码实现&#xff1a;使用numpy、pandas&#xff0c;不调用机器学习相关库。 已将代码和相关文档上传到了github&#xff1a;golitter/Decoding-ML-Top10: 使用 Python 优雅地实现机器学习十大经典算法。 (github.com) 一元线性回归&#xff1a;机器学习&…

ffmpeg学习:ubuntu下编译Android版ffmpeg-kit

文章目录 前言一. 配置环境1.1 虚拟机版本1.2 安装Android环境1.2.1 Android SDK安装1.2.2 Android NDK安装 1.3 编译前的准备工作1.3.1 libtasn1-1安装1.3.2 meson安装1.3.3 harfbuzz下载 二. 编译ffmpeg-kit三. 总结 前言 ffmpeg-kit是一款跨多个平台的&#xff0c;用于在应…

Qt使用pri和pro文件进行模块化编程

假如我想要做一个功能&#xff0c;这个功能用代码模块化实现出来&#xff0c;方便将来移植&#xff0c;比如音视频播放器的界面&#xff0c;将来想要在其他工程使用时&#xff0c;只需要将widget提升为音视频播放界面即可。 当我们其他工程需要这个功能时&#xff0c;我们在调用…

C# windowForms 的DataGridView控件的使用

C# Windows Forms DataGridView 控件使用详解 DataGridView 是 Windows Forms 中用于显示和编辑表格数据的核心控件。它支持高度自定义的列类型、数据绑定、事件处理和丰富的样式配置。以下是其详细使用方法。 目录 基础使用 数据绑定 列类型与自定义

PyQt 界面编程:QDialog、QWidget、QMainWindow 的面向过程与面向对象编程

文章目录 一、PyQt简介二、面向过程编程三、面向对象编程(推荐)3.1 QWidget窗口3.2 QMainWindow窗口3.3 QDialog窗口文档: https://www.riverbankcomputing.com/static/Docs/PyQt5/ 一、PyQt简介 PyQt简介:PyQt 是一个用于创建图形用户界面(GUI)的 Python 库,它将 Qt …

Jvascript网页设计案例:通过js实现一款密码强度检测,适用于等保测评整改

本文目录 前言功能预览样式特点总结&#xff1a;1. 整体视觉风格2. 密码输入框设计3. 强度指示条4. 结果文本与原因说明 功能特点总结&#xff1a;1. 密码强度检测2. 实时反馈机制3. 详细原因说明4. 视觉提示5. 交互体验优化 密码强度检测逻辑Html代码Javascript代码 前言 能满…

智能车摄像头开源—8 元素处理

目录 一、前言 二、无元素状态 三、直线与弯道 四、十字与环岛 1、十字识别处理 2、环岛识别处理 五、坡道 六、障碍物 七、斑马线 八、入库 九、出界停车 一、前言 在写这篇文章之前&#xff0c;考虑了很久到底该写到什么程度&#xff0c;但思来想去&#xff0c;不同…

微信服务号推送消息

这里如果 没有 就需要点新的功能去申请一下 申请成功之后就可以设置模版消息 推送到用户接受的页面是 需要后端调用接口 传递token 发送给客户

matlab汽车动力学半车垂向振动模型

1、内容简介 matlab141-半车垂向振动模型 可以交流、咨询、答疑 2、内容说明 略 3、仿真分析 略 4、参考论文 略

1-10 github注册仓库

如何在github中注册一个仓库&#xff1f; 1.0 注册仓库 1-1 GitHub的账号注册教程_github注册-CSDN博客 2.0 删除仓库 1-2 从github中删除创建的仓库_github删除仓库-CSDN博客 3.0 创建仓库 1-3 【教程】GitHub新建仓库新手教程_github仓库-CSDN博客 4.0 github操作 1-4 1-9 克…

EasyRTC智能硬件:小体积,大能量,开启音视频互动新体验

在万物互联的时代&#xff0c;智能硬件正以前所未有的速度融入我们的生活。然而&#xff0c;受限于硬件性能和网络环境&#xff0c;许多智能硬件在音视频互动体验上仍存在延迟高、卡顿、回声等问题&#xff0c;严重影响了用户的使用体验。 EasyRTC智能硬件&#xff0c;凭借其强…

PHP 面向对象编程

PHP 学习资料 PHP 学习资料 PHP 学习资料 在 PHP 编程领域&#xff0c;面向对象编程&#xff08;OOP&#xff09;是一种强大的编程范式&#xff0c;它提供了更高效的代码组织和复用方式&#xff0c;使程序的结构更清晰、易维护。接下来&#xff0c;我们将深入探讨 PHP 面向对…

2021年全国研究生数学建模竞赛华为杯E题信号干扰下的超宽带(UWB)精确定位问题求解全过程文档及程序

2021年全国研究生数学建模竞赛华为杯 E题 信号干扰下的超宽带(UWB)精确定位问题 原题再现&#xff1a; 一、背景   UWB&#xff08;Ultra-Wideband&#xff09;技术也被称之为“超宽带”&#xff0c;又称之为脉冲无线电技术。这是一种无需任何载波&#xff0c;通过发送纳秒…

matlab飞行姿态pid控制

1、内容简介 matlab139-飞行姿态pid控制 可以交流、咨询、答疑 2、内容说明 略 3、仿真分析 略 4、参考论文 略

easyexcel快速使用

1.easyexcel EasyExcel是一个基于ava的简单、省内存的读写Excel的开源项目。在尽可能节约内存的情况下支持读写百M的Excel 即通过java完成对excel的读写操作&#xff0c; 上传下载 2.easyexcel写操作 把java类中的对象写入到excel表格中 步骤 1.引入依赖 <depen…

网络基础 【UDP、TCP】

1.UDP 首先我们学习UDP和TCP协议 要从这三个问题入手 1.报头和有效载荷如何分离、有效载荷如何交付给上一层的协议&#xff1f;2.认识报头3.学习该协议周边的问题 UDP报头 UDP我们先从示意图来讲解&#xff0c;认识报头。 UDP协议首部有16位源端口号&#xff0c;16位目的端…

基于SpringBoot的医院药房管理系统【源码+答辩PPT++项目部署】高质量论文1-1.5W字

作者简介&#xff1a;✌CSDN新星计划导师、Java领域优质创作者、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流。✌ 主要内容&#xff1a;&#x1f31f;Java项目、Python项目、前端项目、PHP、ASP.NET、人工智能…

25/2/16 <算法笔记> DirectPose

DirectPose 是一种直接从图像中预测物体的 6DoF&#xff08;位姿&#xff1a;6 Degrees of Freedom&#xff09;姿态 的方法&#xff0c;包括平移和平面旋转。它在目标检测、机器人视觉、增强现实&#xff08;AR&#xff09;和自动驾驶等领域中具有广泛应用。相比于传统的位姿估…