CogCalibCheckboardTool1工具将像素转换成实际距离
CogPMAlignTool1工具抓取感兴趣图像的坐标
CogFindCircleTool1找圆
需要的中心点坐标位置
#region Private Member Variables
private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
CogGraphicCollection G = new CogGraphicCollection();//文本集合
#endregion
将需要的圆的中心xy传到找圆工具 确定显示位置
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 using the RunTool function
foreach(ICogTool tool in mToolBlock.Tools)
mToolBlock.RunTool(tool, ref message, ref result);
CogPMAlignTool P = mToolBlock.Tools["CogPMAlignTool1"] as CogPMAlignTool;
CogFindCircleTool C = mToolBlock.Tools["CogFindCircleTool1"] as CogFindCircleTool;
G.Clear();
foreach(CogPMAlignResult item in P.Results){
C.RunParams.ExpectedCircularArc.CenterX = item.GetPose().TranslationX;
C.RunParams.ExpectedCircularArc.CenterY = item.GetPose().TranslationY;
C.Run();
CogGraphicLabel L = new CogGraphicLabel ();
L.Color = CogColorConstants.Red;
L.Font = new Font("楷体", 10);
L.SetXYText(item.GetPose().TranslationX,item.GetPose().TranslationY,"直径:"+(C.Results.GetCircle().Radius*2).ToString("F2"));
G.Add(L);
}
return false;
}
循环显示即可
public override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord)
{
CogPMAlignTool P = mToolBlock.Tools["CogPMAlignTool1"] as CogPMAlignTool;
foreach(ICogGraphic item in G){
mToolBlock.AddGraphicToRunRecord(item,lastRecord,"CogPMAlignTool1.InputImage","");
}
if(P.Results.Count==0){
G.Clear();//没有图片清除显示信息
}
}