news 2026/4/29 4:51:57

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/4/28 5:59:16

导师推荐!2026本科生必用AI论文网站TOP10测评

导师推荐&#xff01;2026本科生必用AI论文网站TOP10测评 2026年本科生必备AI论文网站测评&#xff1a;如何挑选高效写作助手 随着人工智能技术的不断发展&#xff0c;AI论文辅助工具已经成为高校学生提升写作效率、优化内容质量的重要帮手。然而&#xff0c;面对市场上琳琅满目…

作者头像 李华
网站建设 2026/4/28 20:55:44

AI抠图也能本地运行?体验工业级Rembg稳定版镜像

AI抠图也能本地运行&#xff1f;体验工业级Rembg稳定版镜像 你是否曾为一张产品图背景杂乱而苦恼&#xff1f;是否在制作电商详情页时&#xff0c;因手动抠图耗时费力而效率低下&#xff1f;传统PS抠图不仅依赖操作技巧&#xff0c;面对复杂边缘&#xff08;如毛发、透明物体&…

作者头像 李华
网站建设 2026/4/28 22:33:12

Rembg抠图应用:电商主图制作的完整流程

Rembg抠图应用&#xff1a;电商主图制作的完整流程 1. 引言&#xff1a;智能万能抠图在电商场景中的核心价值 随着电商平台对商品视觉呈现要求的不断提升&#xff0c;高质量、高一致性的主图已成为提升转化率的关键因素。传统人工抠图耗时耗力&#xff0c;且难以保证边缘平滑…

作者头像 李华
网站建设 2026/4/23 11:10:41

Qwen2.5-7B-Instruct镜像部署全解析|支持vLLM与Chainlit调用

Qwen2.5-7B-Instruct镜像部署全解析&#xff5c;支持vLLM与Chainlit调用 引言&#xff1a;为何选择Qwen2.5-7B-Instruct进行本地化部署&#xff1f; 随着大模型在企业级应用和私有化场景中的需求激增&#xff0c;如何高效、稳定地将高性能语言模型部署到生产环境成为关键挑战…

作者头像 李华
网站建设 2026/4/27 18:01:03

基于深度学习的探地雷达目标识别与卷积神经网络优化研究【附代码】

✅ 博主简介&#xff1a;擅长数据搜集与处理、建模仿真、程序设计、仿真代码、论文写作与指导&#xff0c;毕业论文、期刊论文经验交流。✅成品或者定制&#xff0c;扫描文章底部微信二维码。城市道路地下空洞、疏松、富水等隐蔽病害是引发路面塌陷事故的主要诱因&#xff0c;严…

作者头像 李华
网站建设 2026/4/27 17:55:57

AI看懂世界的第一步|基于MiDaS镜像实现图像深度热力图生成

AI看懂世界的第一步&#xff5c;基于MiDaS镜像实现图像深度热力图生成 “让AI拥有三维感知”——这是计算机视觉迈向真实世界理解的关键一步。 一张二维照片&#xff0c;如何还原出空间的远近关系&#xff1f;物体离镜头有多远&#xff1f;哪些是前景&#xff0c;哪些是背景&am…

作者头像 李华