VisionPro设置ToolGroup脚本获取找到圆的半径
using System; using Cognex.VisionPro; using Cognex.VisionPro3D; using Cognex.VisionPro.ToolGroup; using Cognex.VisionPro.Caliper; public class UserScript : CogToolGroupBaseScript { private double Radius; private CogFindCircleTool mCogFindCircleTool; // The GroupRun function is called when the tool group is run. The default // implementation provided here is equivalent to the normal behavior of the // tool group. Modifying this function will allow you to change the behavior // when the tool group is run. public override bool GroupRun(ref string message, ref CogToolResultConstants result) { // 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 in the tool group using the RunTool function for (Int32 toolIdx = 0; toolIdx < toolGroup.Tools.Count; toolIdx++) toolGroup.RunTool(toolGroup.Tools[toolIdx], ref message, ref result); //获取找到圆的半径 mCogFindCircleTool = (CogFindCircleTool) toolGroup.Tools["CogFindCircleTool1"]; Radius = mCogFindCircleTool.Results.GetCircle().Radius;//取得半径 // Returning False indicates we ran the tools in script, and they should not be // run by VisionPro return false; } #region "When the Current Run Record is Created" public override void ModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord) { } #endregion #region "When the Last Run Record is Created" // Allows you to add or modify the contents of the last run record when it is // created. For example, you might add custom graphics to the run record here. public override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord) { CogGraphicLabel ResultLabel = new CogGraphicLabel();//创建标签对象 string labelStr = string.Format("半径={0:F2} pixel",Radius); ResultLabel.SetXYText(mCogFindCircleTool.Results.GetCircle().CenterX,mCogFindCircleTool.Results.GetCircle().CenterY,labelStr);//设置标签 ResultLabel.Color = Cognex.VisionPro.CogColorConstants.Red;//将字体颜色设置成红色 toolGroup.AddGraphicToRunRecord(ResultLabel, lastRecord, "CogImageConvertTool1.OutputImage", "script");//将标签 } #endregion #region "When the Script is Initialized" // Perform any initialization required by your script here public override void Initialize(CogToolGroup host) { // DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE base.Initialize(host); } #endregion }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧