news 2026/3/10 22:21:39

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/3/10 13:41:45

Rembg抠图性能瓶颈:识别与优化策略

Rembg抠图性能瓶颈&#xff1a;识别与优化策略 1. 智能万能抠图 - Rembg 在图像处理与内容创作领域&#xff0c;自动去背景&#xff08;Background Removal&#xff09;是一项高频且关键的需求。从电商商品图精修、社交媒体内容制作&#xff0c;到AI生成图像的后处理&#xf…

作者头像 李华
网站建设 2026/3/8 20:26:45

Rembg抠图模型优化:提升推理速度的5个技巧

Rembg抠图模型优化&#xff1a;提升推理速度的5个技巧 1. 智能万能抠图 - Rembg 在图像处理与内容创作领域&#xff0c;自动去背景&#xff08;Image Matting / Background Removal&#xff09;是一项高频且关键的需求。无论是电商商品图精修、社交媒体内容制作&#xff0c;还…

作者头像 李华
网站建设 2026/3/3 18:35:02

Rembg抠图技巧:反光物体处理方法

Rembg抠图技巧&#xff1a;反光物体处理方法 1. 智能万能抠图 - Rembg 在图像处理与内容创作领域&#xff0c;精准、高效的背景去除技术一直是核心需求之一。无论是电商产品精修、广告设计还是AI生成内容&#xff08;AIGC&#xff09;预处理&#xff0c;高质量的抠图能力都直…

作者头像 李华
网站建设 2026/3/3 20:06:35

构建本地大模型应用首选|Qwen2.5-7B-Instruct + vLLM + Chainlit集成方案

构建本地大模型应用首选&#xff5c;Qwen2.5-7B-Instruct vLLM Chainlit集成方案 在当前AI大模型快速发展的背景下&#xff0c;越来越多开发者希望将高性能语言模型部署到本地环境&#xff0c;以实现数据隐私保护、低延迟响应和定制化服务。然而&#xff0c;传统部署方式往往…

作者头像 李华
网站建设 2026/3/10 9:27:34

Rembg抠图对比测试:不同光照条件下的表现

Rembg抠图对比测试&#xff1a;不同光照条件下的表现 1. 引言 1.1 智能万能抠图 - Rembg 在图像处理与内容创作领域&#xff0c;精准、高效的背景去除技术一直是核心需求。传统手动抠图耗时费力&#xff0c;而基于深度学习的自动去背方案正逐步成为主流。其中&#xff0c;Re…

作者头像 李华
网站建设 2026/3/11 14:36:46

Rembg模型更新:v2.0新特性详解

Rembg模型更新&#xff1a;v2.0新特性详解 1. 引言&#xff1a;智能万能抠图的进化之路 随着AI图像处理技术的快速发展&#xff0c;自动去背景&#xff08;Image Matting&#xff09;已成为内容创作、电商展示、设计修图等领域的刚需。在众多开源方案中&#xff0c;Rembg 凭借…

作者头像 李华