当前位置: 首页 > news >正文

传感器测量(图片流程)

效果图

 

 

 

 

重点工具使用流程

CogFindLineTool工具

步骤一:使用找线工具将传感器左边特征给寻找出来;

 步骤二:使用找线工具将传感器右边特征给寻找出来;

 步骤三:使用找线工具将传感器上边特征给寻找出来;

 步骤四:使用找线工具将传感器下边特征给寻找出来;

CogIntersectLineLineTool工具

步骤一:将左边直线和上直线进行交叉处理;

 步骤二:将右边直线和上直线进行交叉处理;

 步骤三:将左边直线和下直线进行交叉处理;

步骤四:将右边直线和下直线进行交叉处理; 

CogCreateSegmentTool工具

步骤一:将右边直线和上直线进行交叉与左边直线和下直线进行交叉,实现右倾斜进行测量···

 步骤二:将右边直线和上直线进行交叉和右边直线和下直线进行交叉,实现右倾斜进行测量···

CogIntersectSegmentSegmentTool工具

将CogCreateSegmentTool工具1和CogCreateSegmentTool工具2计算两条线段(Segment)的交点坐标,然后计算出传感器所需要的宽高。

传感器脚本

#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.PMAlign;
using Cognex.VisionPro.CalibFix;
using Cognex.VisionPro.Caliper;
using Cognex.VisionPro.Dimensioning;
#endregionpublic class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{#region Private Member Variablesprivate Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;private CogDistanceSegmentLineTool width;private CogDistanceSegmentLineTool length;private CogGraphicLabel widthLabel;private CogGraphicLabel lengthLabel;#endregion/// <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){width = new CogDistanceSegmentLineTool();length = new CogDistanceSegmentLineTool();widthLabel = new CogGraphicLabel();lengthLabel = new CogGraphicLabel();// 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// Run each tool using the RunTool functionforeach(ICogTool tool in mToolBlock.Tools)mToolBlock.RunTool(tool, ref message, ref result);width = mToolBlock.Tools["CogDistanceSegmentLineTool_width"]as CogDistanceSegmentLineTool;length = mToolBlock.Tools["CogDistanceSegmentLineTool_length"]as CogDistanceSegmentLineTool;widthLabel.Color = CogColorConstants.Green;lengthLabel.Color = CogColorConstants.Green;widthLabel.SetXYText(200, 200, "width:" + width.Distance.ToString("0.00"));lengthLabel.SetXYText(200, 250, "length:" + length.Distance.ToString("0.00"));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(widthLabel, lastRecord, "CogImageConvertTool1.OutputImage", "script");mToolBlock.AddGraphicToRunRecord(lengthLabel, lastRecord, "CogImageConvertTool1.OutputImage", "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}

相关文章:

  • 经典算法 区间统计种类
  • Opencv图像处理:旋转、打包、多图像匹配
  • TinyVue v3.22.0 正式发布:深色模式上线!集成 UnoCSS 图标库!TypeScript 类型支持全面升级!
  • Python 面向对象练习
  • 日内组合策略思路
  • 强化学习(Reinforcement Learning, RL)和深度学习(Deep Learning, DL)
  • 数据结构——栈与队列
  • 简单场景下的目标关联算法:GNN全局最近邻与匈牙利算法
  • 制作一款打飞机游戏20:敌人被击中时的视觉效果
  • 理解js函数(Ⅱ)
  • 嵌入式Linux驱动开发:LED实验
  • Spring Boot中自定义404异常处理问题学习笔记
  • Android学习总结之Room篇
  • 发送网络请求
  • 《无尽的尽头》今日开播 刘家祎大胆演绎林磊儿的“另一面”
  • RAG(检索增强生成)技术详解与应用实践:从原理到落地
  • 简单几步,开启 Intel VT-x 让电脑“解开CPU封印”
  • 蓝桥杯 20. 压缩变换
  • 数据分析之 商品价格分层之添加价格带
  • 欧姆龙NJ系列PLC通讯
  • 2025年全国贸易摩擦应对工作会议在京召开
  • 海南高院通报去年知产领域司法保护状况:审结民事一审案件4847起
  • 印度加大应对力度,吊销所有巴基斯坦公民签证
  • 国家发改委:更大力度、更实举措促进民营经济高质量发展
  • 阿联酋首个AI博士项目设立,助力人才培养与科技转型
  • 城事|喊侬白相,长兴太湖9号公路邀上海市民共赴诗意之旅