news 2026/9/24 19:24:22

ToolBlock高级脚本之显示XYA和二维码

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
ToolBlock高级脚本之显示XYA和二维码

显示XYA和二维码

usingCognex.VisionPro.ImageProcessing;usingCognex.VisionPro.CalibFix;usingCognex.VisionPro.PMAlign;usingCognex.VisionPro.Caliper;usingCognex.VisionPro.Dimensioning;usingCognex.VisionPro.ID;usingCognex.VisionPro.Blob;usingSystem.Collections.Generic;

一 定义全局变量

// 用于存储要在图像上显示的图形标签的列表List<CogGraphicLabel>graphics_label=newList<CogGraphicLabel>();// 建立List// 定义了一个Arial字体,大小为12磅FontmyFont1=newFont("Arial",12);// 字体12

二 定义显示标签方法

publicvoidShow_Label(doublex,doubley,CogColorConstantscolor,Fontfont,stringtext){CogGraphicLabellabel=newCogGraphicLabel();// 定义label标签label.Alignment=CogGraphicLabelAlignmentConstants.BaselineLeft;// 确定对齐方式label.BackgroundColor=CogColorConstants.Orange;//背景颜色label.SelectedSpaceName="#";//显示的空间名称label.SetXYText(x,y,text);//显示坐标,以及输入内容label.Color=color;//字体颜色label.Font=font;//字体大小graphics_label.Add(label);//添加进入list}

三 渲染

foreach(CogGraphicLabellabelingraphics_label){// 将所有图形标签添加到运行记录中// label 标签// lastRecord 渲染工具// "CogIPOneImageTool1.OutputImage":确定渲染放置位置// "" :附带参数mToolBlock.AddGraphicToRunRecord(label,lastRecord,"CogIPOneImageTool1.OutputImage","");}

四 加标签

// 用于存储要在图像上显示的图形标签的列表List<CogGraphicLabel>graphics_label=newList<CogGraphicLabel>();// 建立List// 定义了一个Arial字体,大小为12磅FontmyFont1=newFont("Arial",12);// 字体12
//工具引用CogPMAlignToolpm=mToolBlock.Tools["CogPMAlignTool1"]asCogPMAlignTool;mToolBlock.Outputs["X"].Value=pm.Results[0].GetPose().TranslationX;mToolBlock.Outputs["Y"].Value=pm.Results[0].GetPose().TranslationY;mToolBlock.Outputs["A"].Value=pm.Results[0].GetPose().Rotation;
publicoverrideboolGroupRun(refstringmessage,refCogToolResultConstantsresult){// 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(ICogTooltoolinmToolBlock.Tools)mToolBlock.RunTool(tool,refmessage,refresult);//工具引用CogPMAlignToolpm=mToolBlock.Tools["CogPMAlignTool1"]asCogPMAlignTool;CogIDToolid1=mToolBlock.Tools["CogIDTool1"]asCogIDTool;CogIDToolid2=mToolBlock.Tools["CogIDTool2"]asCogIDTool;Show_Label(0,100,CogColorConstants.DarkGrey,myFont1,"X:"+pm.Results[0].GetPose().TranslationX.ToString("f3"));Show_Label(0,140,CogColorConstants.DarkGrey,myFont1,"Y:"+pm.Results[0].GetPose().TranslationY.ToString("f3"));Show_Label(0,180,CogColorConstants.DarkGrey,myFont1,"A:"+pm.Results[0].GetPose().Rotation.ToString("f3"));if(id1.Results.Count>0){Show_Label(0,220,CogColorConstants.DarkGrey,myFont1,"R1Barcode1:"+id1.Results[0].DecodedData.DecodedString);}else{Show_Label(0,220,CogColorConstants.DarkGrey,myFont1,"NG");}if(id2.Results.Count>0){Show_Label(0,260,CogColorConstants.DarkGrey,myFont1,"R1Barcode2:"+id2.Results[0].DecodedData.DecodedString);}else{Show_Label(0,260,CogColorConstants.DarkGrey,myFont1,"NG");}returnfalse;}
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/19 10:58:35

Burp Suite插件 | AI连接本地工具、数据库或远程 Agent,辅助安全测试

工具介绍 BurpAgent 将大语言模型 (LLM) 和 MCP (Model Context Protocol) 引入 Burp Suite&#xff0c;使其能够连接本地工具、数据库或远程 Agent&#xff0c;辅助安全测试。工具功能 1. 流量分析 利用 GPT-4/DeepSeek 等模型对 HTTP 请求/响应进行分析。支持自定义 Prompt 模…

作者头像 李华
网站建设 2026/9/24 5:11:29

6.面向对象初级

类与对象的概述1.类的定义&#xff1a;类是抽象的概念的&#xff0c;代表一类事物&#xff08;比如人类&#xff0c;猫类&#xff09;&#xff0c;本质是一种数据类型&#xff0c;类将这一类对象所共有的属性和行为进行定义&#xff08;比如猫都有名字&#xff0c;颜色&#xf…

作者头像 李华
网站建设 2026/9/18 19:50:59

万字长文,全面解析“黑、骇、白、红”客:他们的技术与使命

黑客 起源 “黑客”一词是英文Hacker的音译。这个词早在莎士比亚时代就已存在了&#xff0c;但是人们第一次真正理解它时&#xff0c;却是在计算机问世之后。根据《牛津英语词典》解释&#xff0c;“hack”一词最早的意思是劈砍&#xff0c;而这个词意很容易使人联想到计算机…

作者头像 李华