news 2026/5/12 15:02:16

VisionPro之引导定位

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
VisionPro之引导定位

VisionPro之引导定位

#regionnamespace importsusing 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;using Cognex.VisionPro.PixelMap;using Cognex.VisionPro.Blob;#endregionpublic class CogToolBlockAdvancedScript:CogToolBlockAdvancedScriptBase{#regionPrivate Member Variablesprivate Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;Cognex.VisionPro.CogGraphicCollection graphics1=newCogGraphicCollection();Cognex.VisionPro.CogGraphicCollection graphics2=newCogGraphicCollection();Cognex.VisionPro.CogGraphicCollection graphics3=newCogGraphicCollection();//Cognex.VisionPro.CogCircle cogcir = new CogCircle();//Cognex.VisionPro.CogCircularArc circular = new CogCircularArc();CogPMAlignTool[]pma=new CogPMAlignTool[5];CogFixtureTool[]fix=new CogFixtureTool[3];CogFindCircleTool[]findcircle=new CogFindCircleTool[2];CogFitLineTool fitline=newCogFitLineTool();CogFindLineTool findline=newCogFindLineTool();CogFindLineTool findline2=newCogFindLineTool();#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 boolGroupRun(ref string message,ref CogToolResultConstants result){// To let the execution stop in this script when a debugger is attached, uncomment the following lines.// #if DEBUGif(System.Diagnostics.Debugger.IsAttached)System.Diagnostics.Debugger.Break();// #endif// Run each tool using the RunTool function#regionmToolBlock.Outputs["Data"].Value="2";mToolBlock.Outputs["X"].Value=999;mToolBlock.Outputs["Y"].Value=999;mToolBlock.Outputs["R"].Value=999;string tBdata=string.Empty;string data2=string.Empty;string data3=string.Empty;string data4=string.Empty;doublet1=666;graphics1.Clear();graphics2.Clear();graphics3.Clear();intproductnum=0;#endregiontry{//foreach(ICogTool tool in mToolBlock.Tools)// mToolBlock.RunTool(tool, ref message, ref result);CogPMAlignTool pma1=(CogPMAlignTool)mToolBlock.Tools["正平面"];// CogPMAlignTool pma2 = (CogPMAlignTool)mToolBlock.Tools["反斜面"];CogToolBlock tb1=(CogToolBlock)mToolBlock.Tools["正面坐标计算"];CogToolBlock tb2=(CogToolBlock)mToolBlock.Tools["反面坐标计算"];CogBlobTool blob=(CogBlobTool)mToolBlock.Tools["CogBlobTool1"];pma1.Run();blob.Run();// pma2.Run();for(inti=0;i<blob.Results.GetBlobs().Count;i++){productnum++;if(blob.Results.GetBlobs()[i].Area>2000&&blob.Results.GetBlobs()[i].Area<4000){productnum++;}elseif(blob.Results.GetBlobs()[i].Area>4000){intnum=Convert.ToInt32(blob.Results.GetBlobs()[i].Area/2000);for(intj=0;j<num-1;j++){productnum++;}}}if(pma1.Results.Count>0&&productnum>0){tb2.Run();tBdata=(string)tb2.Outputs["Data"].Value;if(tBdata=="4"){mToolBlock.Outputs["X"].Value=(double)tb2.Outputs["X"].Value;mToolBlock.Outputs["Y"].Value=(double)tb2.Outputs["Y"].Value;mToolBlock.Outputs["R"].Value=(double)tb2.Outputs["R"].Value;mToolBlock.Outputs["Graphics"].Value=(CogGraphicCollection)tb2.Outputs["Graphics"].Value;}else{tb1.Run();tBdata=(string)tb1.Outputs["Data"].Value;if(tBdata=="1"){mToolBlock.Outputs["X"].Value=(double)tb1.Outputs["X"].Value;mToolBlock.Outputs["Y"].Value=(double)tb1.Outputs["Y"].Value;mToolBlock.Outputs["R"].Value=(double)tb1.Outputs["R"].Value;mToolBlock.Outputs["Graphics"].Value=(CogGraphicCollection)tb1.Outputs["Graphics"].Value;}}if(productnum>=8){mToolBlock.Outputs["Data"].Value=tBdata;}else{mToolBlock.Outputs["Data"].Value="3";}}elseif(productnum<3){mToolBlock.Outputs["Data"].Value="3";mToolBlock.Outputs["X"].Value=t1;mToolBlock.Outputs["Y"].Value=t1;mToolBlock.Outputs["R"].Value=t1;}else{mToolBlock.Outputs["Data"].Value="3";mToolBlock.Outputs["X"].Value=t1;mToolBlock.Outputs["Y"].Value=t1;mToolBlock.Outputs["R"].Value=t1;}DisplayLabel(100,300,"数量: "+productnum.ToString(),CogColorConstants.Green,1);mToolBlock.Outputs["Graphics2"].Value=graphics2;}catch{DisplayLabel(100,100,"计算ERROR",CogColorConstants.Red,1);mToolBlock.Outputs["Data"].Value="2";mToolBlock.Outputs["X"].Value=t1;mToolBlock.Outputs["Y"].Value=t1;mToolBlock.Outputs["R"].Value=t1;mToolBlock.Outputs["Graphics"].Value=graphics2;}returnfalse;}publicvoidDisplayLabel(doublex,doubley,string text,CogColorConstants color,intindex){CogGraphicLabel displaylabel=newCogGraphicLabel();displaylabel.Alignment=CogGraphicLabelAlignmentConstants.TopLeft;displaylabel.LineWidthInScreenPixels=100;displaylabel.Font=newFont("微软雅黑",12);if(index==2){displaylabel.Font=newFont("微软雅黑",20);}displaylabel.Color=CogColorConstants.Black;displaylabel.SelectedSpaceName="@";displaylabel.SetXYText(x,y,text);displaylabel.BackgroundColor=color;graphics1.Add(displaylabel);}publicvoidDebugLabel(doublex,doubley,string text,CogColorConstants color){CogGraphicLabel debuglabel=newCogGraphicLabel();debuglabel.Alignment=CogGraphicLabelAlignmentConstants.TopLeft;debuglabel.LineWidthInScreenPixels=100;debuglabel.Font=newFont("微软雅黑",15);debuglabel.BackgroundColor=CogColorConstants.Green;debuglabel.SetXYText(x,y,text);debuglabel.Color=color;graphics2.Add(debuglabel);}publicvoidGraph_Circle(doublex,doubley,doubleradius,CogColorConstants color){CogCircle cir=newCogCircle();cir.Color=color;cir.DragLineWidthInScreenPixels=50;cir.LineWidthInScreenPixels=5;cir.CenterX=x;cir.CenterY=y;cir.Radius=radius;graphics3.Add(cir);}#regionWhen 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 overridevoidModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord){}#endregion#regionWhen 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 overridevoidModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord){foreach(ICogGraphic gra in graphics1){mToolBlock.AddGraphicToRunRecord(gra,lastRecord,"正平面.InputImage","");}foreach(ICogGraphic gra in graphics2){mToolBlock.AddGraphicToRunRecord(gra,lastRecord,"CogPMAlignTool1.InputImage","");}}#endregion#regionWhen the Script is Initialized/// <summary>/// Perform any initialization required by your script here/// </summary>/// <param name="host">The host tool</param>public overridevoidInitialize(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}
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/12 10:03:33

Qwen2.5-7B-Instruct镜像部署实践:vLLM+Chainlit快速上手

Qwen2.5-7B-Instruct镜像部署实践&#xff1a;vLLMChainlit快速上手 一、业务场景与痛点分析 随着大语言模型在企业级应用中的广泛落地&#xff0c;如何高效地将高性能模型部署为可交互服务成为关键挑战。传统推理框架往往面临吞吐量低、显存占用高、响应延迟大等问题&#xff…

作者头像 李华
网站建设 2026/5/10 3:53:42

SpringBoot+Vue 美发门店管理系统平台完整项目源码+SQL脚本+接口文档【Java Web毕设】

摘要 随着美发行业的快速发展&#xff0c;传统门店管理模式逐渐暴露出效率低下、客户管理混乱等问题。信息化管理系统的引入成为提升门店运营效率的关键。美发门店管理系统通过数字化手段整合客户信息、预约管理、员工调度及财务统计等功能&#xff0c;帮助门店实现精细化运营。…

作者头像 李华
网站建设 2026/5/9 22:06:34

从目录到架构:彻底理解 Metasploit Framework 的模块与载荷设计

—— 官方 MSF 源码级视角下的工程哲学与实战路径 引言&#xff1a;为什么“找不到 payload 文件”是一个必然问题&#xff1f; 几乎所有真正深入使用 Metasploit Framework&#xff08;MSF&#xff09; 的人&#xff0c;都会在某一个时间点遇到同一个问题&#xff1a; “我在 …

作者头像 李华
网站建设 2026/5/12 13:33:15

智能万能抠图Rembg:内容创作者的秘密武器

智能万能抠图Rembg&#xff1a;内容创作者的秘密武器 1. 引言&#xff1a;智能万能抠图 - Rembg 在数字内容创作日益普及的今天&#xff0c;图像处理已成为设计师、电商运营、短视频制作者乃至普通用户不可或缺的一环。其中&#xff0c;图像去背景&#xff08;即“抠图”&…

作者头像 李华
网站建设 2026/5/12 3:26:54

11种前沿AI论文生成工具,支持LaTeX格式与自动校对

工具对比排名 工具名称 核心优势 支持LaTeX 适用场景 aibiye AIGC率降个位数&#xff0c;兼容知网规则 是 AI痕迹强处理 aicheck 学术改写优化&#xff0c;语义保留佳 是 格式统一化 askpaper 降重降AI一体&#xff0c;20分钟快速响应 是 初稿优化 秒篇 人类特…

作者头像 李华
网站建设 2026/5/9 13:57:47

基于深度学习的高分辨率遥感影像建筑物提取与变化检测研究【附代码】

✅ 博主简介&#xff1a;擅长数据搜集与处理、建模仿真、程序设计、仿真代码、论文写作与指导&#xff0c;毕业论文、期刊论文经验交流。✅成品或者定制&#xff0c;扫描文章底部微信二维码。随着对地观测技术的飞速发展&#xff0c;高分辨率遥感影像数据的获取变得日益便捷&am…

作者头像 李华