Visionpro 齿轮测量

news2025/3/12 19:09:01

  效果展示

一、题目要求 

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

二、分析

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;
#endregion

public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
  #region Private Member Variables
  private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
  #endregion
  CogGraphicCollection 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 function
    foreach(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 REMOVE
    base.Initialize(host);


    // Store a local copy of the script host
    this.mToolBlock = ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));
  }
  #endregion

}

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

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

相关文章

索引以及索引底层数据结构

一、什么是索引&#xff1f; 索引&#xff08;index&#xff09;是数据库高效获取数据的数据结构&#xff08;有序&#xff09;。在数据之外&#xff0c;数据库系统还维护着满足特定查找算法的数据结构&#xff08;B树&#xff09;&#xff0c;这些数据结构以某种方式指向真在…

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

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

API 接口自动化

HTTP协议 - 白月黑羽 HTTP协议简介 如果客户端是浏览器&#xff0c;如何在chrome浏览器中查看 请求和响应的HTTP消息&#xff1f;按f12-》network 清除当前信息 响应的消息体在Response里看 点preview&#xff0c;可以看响应的消息体展开的格式 HTTP请求消息 请求头 reques…

安全测试|SSRF请求伪造

前言 SSRF漏洞是一种在未能获取服务器权限时&#xff0c;利用服务器漏洞&#xff0c;由攻击者构造请求&#xff0c;服务器端发起请求的安全漏洞&#xff0c;攻击者可以利用该漏洞诱使服务器端应用程序向攻击者选择的任意域发出HTTP请求。 很多Web应用都提供了从其他的服务器上…

智能编程助手功能革新与价值重塑之:GitHub Copilot

引言&#xff1a; GitHub Copilot 的最新更新为开发者带来了显著变化&#xff0c;其中 Agent Mode 功能尤为引人注目。该模式能够自动识别并修复代码错误、自动生成终端命令&#xff0c;并具备多级任务推理能力&#xff0c;这使得开发者在开发复杂功能时&#xff0c;可大幅减少…

物联网行业通识:从入门到深度解析

物联网行业通识&#xff1a;从入门到深度解析 &#xff08;图1&#xff1a;物联网生态示意图&#xff09; 一、引言&#xff1a;万物互联时代的到来 根据IDC最新预测&#xff0c;到2025年全球物联网设备连接数将突破410亿&#xff0c;市场规模达1.1万亿美元。物联网&#xff…

ABP - 事件总线之分布式事件总线

ABP - 事件总线之分布式事件总线 1. 分布式事件总线的集成1.2 基于 RabbitMQ 的分布式事件总线 2. 分布式事件总线的使用2.1 发布2.2 订阅2.3 事务和异常处理 3. 自己扩展的分布式事件总线实现 事件总线可以实现代码逻辑的解耦&#xff0c;使代码模块之间功能职责更清晰。而分布…

再谈SpringCloud Gateway源码

再谈SpringCloud Gateway源码 一、整体请求流程二、前置对象准备1、实例化HandlerMapping2、实例化Route3、实例化WebHandler 三、实践业务扩展点1、定义扩展Route对象2、Filter能做什么3、定义扩展Filter对象4、定义父类Filter简化请求参数处理 前言&#xff1a; 之前有阅读过…

把 CSV 文件摄入到 Elasticsearch 中 - CSVES

在我们之前的很多文章里&#xff0c;我有讲到这个话题。在今天的文章中&#xff0c;我们就提重谈。我们使用一种新的方法来实现。这是一个基于 golang 的开源项目。项目的源码在 https://github.com/githubesson/csves/。由于这个原始的代码并不支持 basic security 及带有安全…

C进阶 数据的存储

目录 前言 一&#xff0c;VS的知识储备 二&#xff0c;有趣的scanf()读取 三&#xff0c;数据的存储 引言 四&#xff0c;整数存储 五&#xff0c;小数存储 总结 前言 这里将深入计算机&#xff0c;看计算机是如何进行数据的存储的&#xff0c;怎么在计算机里面筑巢 为…

【c++】【Linux】【进程】线程终止/崩溃 会导致进程终止/崩溃 吗?

【c】【Linux】【进程】线程终止/崩溃 会导致进程终止/崩溃 吗&#xff1f; 1.线程终止会导致进程终止吗&#xff1f; 在操作系统中&#xff0c;线程是进程的基本执行单元&#xff0c;一个进程可以包含一个或多个线程。 当一个子线程终止时&#xff0c;进程并不会因此自动终…

springcloud集成gateway

本篇文章只介绍gateway模块的搭建步骤&#xff0c;并无gateway详细介绍 gateway详解请查看&#xff1a;SpringCloudGateway官方文档详解 前置处理 父模块中已指定版本 不知道如何选择版本看这篇&#xff1a; 手把手教你梳理springcloud与springboot与springcloudalibaba的版本…

pandas(13 Caveats Gotchas和SQL比较)

前面内容&#xff1a;pandas(12 IO工具和稀松数据) 目录 一、Caveats警告 & Gotchas预见 1.1 在Pandas中使用if/Truth语句 1.2 位运算布尔 1.3 isin操作 1.4 重新索引reindex和 loc&iloc 使用注意事项 1.5 loc和iloc 二、Python Pandas 与SQL的比较 2.1 数…

Android的Activity生命周期知识点总结,详情

一. Activity生命周期 1.1 返回栈知识点 二. Activity状态 2.1 启动状态 2.2 运行状态 2.3 暂停状态 2.4 停止状态 2.5 销毁状态 三. Activity生存期 3.1 回调方法 3.2 生存期 四. 体验Activity的生命周期 五. Activity被回收办法 引言&#xff1a; 掌握Acti…

基于Python的Flask微博话题舆情分析可视化系统

2024数据 ✅️标价源码 远程部署加 20 ✅️爬虫可用 有六月数据 ✅️修复bug不会突然打不开网页 系统稳定 系统的功能如下: 1.数据的爬取 2.用户的登录注册 3.热词统计&#xff0c;舆情统计 4.文章统计分析 5.发布地址统计 6.评论统计 7.情感分类统计 编程语言&#xff1a;py…

【油漆面积——线段树,扫描线,不用pushdown的特例,pushup兼有cal的性质】

题目 分析 不用pushdown是因为&#xff1a; 对于modify&#xff0c;操作是互逆过程&#xff0c;因此不会存在向下结算的pushdown过程 对于query&#xff0c;操作始终针对最上层的tr[1]&#xff0c;也不需要pushdown 对于pushdown&#xff0c;一则是怕不结算就标记&#xff0c;会…

深度学习(1)-简单神经网络示例

我们来看一个神经网络的具体实例&#xff1a;使用Python的Keras库来学习手写数字分类。在这个例子中&#xff0c;我们要解决的问题是&#xff0c;将手写数字的灰度图像&#xff08;28像素28像素&#xff09;划分到10个类别中&#xff08;从0到9&#xff09;​。我们将使用MNIST…

硬件学习笔记--42 电磁兼容试验-6 传导差模电流干扰试验介绍

目录 电磁兼容试验-传导差模电流试验 1.试验目的 2.试验方法 3.判定依据及意义 电磁兼容试验-传导差模电流干扰试验 驻留时间是在规定频率下影响量施加的持续时间。被试设备&#xff08;EUT&#xff09;在经受扫频频带的电磁影响量或电磁干扰的情况下&#xff0c;在每个步进…

Shader示例 6: 卡渲基础 - 描边 + 着色

0 、获取原神模型&#xff1a; 【游戏开发实战】下载原神模型&#xff0c;PMX转FBX&#xff0c;导入到Unity中&#xff0c;卡通渲染&#xff0c;绑定人形动画&#xff08;附Demo工程&#xff09;-CSDN博客 《原神》公测视频征集计划 一、描边pass&#xff1a;Outline 1. …

Cherno C++ P55 宏

这篇文章我们讲一下C当中的宏。其实接触过大型项目的朋友可能都被诡异的宏折磨过。 宏是在预处理当中&#xff0c;通过文本替换的方式来实现一些操作&#xff0c;这样可以不用反复的输入代码&#xff0c;帮助我们实现自动化。至于预处理的过程&#xff0c;其实就是文本编辑&am…