有问题,卡尺没做出来
代码
List<CogGraphicLabel> labels = new List<CogGraphicLabel>();
CogBlobTool blobTool = mToolBlock.Tools["CogBlobTool1"] as CogBlobTool;
CogCaliperTool caliperTool = mToolBlock.Tools["CogCaliperTool1"] as CogCaliperTool;
CogRectangleAffine caliperRegion = caliperTool.Region as CogRectangleAffine;
CogBlobResultCollection blobResults = blobTool.Results.GetBlobs() as CogBlobResultCollection;
labels.Clear();
foreach(CogBlobResult blob in blobResults)
{
caliperRegion.CenterX = blob.CenterOfMassX;
caliperRegion.CenterY = blob.CenterOfMassY;
mToolBlock.RunTool(caliperTool, ref message, ref result);
CogGraphicLabel myLabel = new CogGraphicLabel();
myLabel.Alignment = CogGraphicLabelAlignmentConstants.BaselineCenter;
if( caliperTool.Results.Count > 0 )
{
myLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "Good");myLabel.Color = CogColorConstants.Green;
}
else
{
myLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "Bad");myLabel.Color = CogColorConstants.Red;
labels.Add(myLabel);
}
}
foreach(CogGraphicLabel label in labels)
{ mToolBlock.AddGraphicToRunRecord(label, lastRecord, "CogBlobTool1.InputImage", "script");}