CogBlobTool Run Method Cognex VisionPro
Runs the tool using the current parameter settings.

Namespace: Cognex.VisionPro.Blob
Assembly: Cognex.VisionPro.Blob (in Cognex.VisionPro.Blob.dll) Version: 65.1.0.0
Syntax

public override void Run()

Implements

ICogTool Run 
Events

Event TypeReason
ICogTool Running Fires before the tool runs.
ICogChangedEvent Changed

Fires when the tool runs. If the run was successful, results are generated; if the run was not successful, no results are generated and the previous results are cleared. Use RunStatus after CogBlobTool returns or in a event handler to determine whether a run was successful or unsuccessful.

The following state flags may be affected:

ICogTool Ran Fires after the tool runs.
Exceptions

ExceptionCondition
CogOperatorNoInputImageExceptionInputImage is NULL.
CogImageNoPixelsExceptionInputImage is not allocated.
CogOperatorInvalidRegionException The selected space of Region is not a valid space in InputImage.
CogOperatorInvalidRegionExceptionRegion is completely outside of InputImage.
CogBlobNoSubtractionImageException The segmentation mode is SubtractionImage and a NULL SubtractionImage was supplied.
CogBlobNoSubtractionImageException The segmentation mode is SubtractionImage and the SubtractionImage had no pixels.
CogBlobSubtractionImageAlignmentErrorException The segmentation mode is SubtractionImage and the SubtractionImage does not completely overlap Region of InputImage. This is usually because the subtraction image is too small or because incorrect offset values were supplied.
CogBlobDuplicateMeasureException The collection of run-time measures contains a duplicate. Only one object per measure is allowed.
CogBlobInvalidMeasureException One or more of the following measures was specified for whole-image blob analysis: BoundaryPixelLength, Perimeter, Acircularity, or AcircularityRms.
CogBlobDynamicThresholdNotComputedException The segmentation mode is HardDynamicThreshold but a dynamic threshold could not be computed, probably because you specified the same value for both the low and high tail percentages.
CogToolNoOperatorExceptionRunParams is NULL.
CogBlobSaveSegmentedImageErrorExceptionSaveSegmentedImage is set to False but SegmentedImage is set in LastRunRecordDiagEnable.
CogBlobSaveSegmentedImageBeforeMaskingErrorExceptionSaveSegmentedImageBeforeMasking is set to False but SegmentedImageBeforeMasking is set in LastRunRecordDiagEnable.
CogBlobSaveSegmentedImageBeforeMorphologyErrorExceptionSaveSegmentedImageBeforeMorphology is set to False but SegmentedImageBeforeMorphology is set in LastRunRecordDiagEnable.
Remarks

Performs blob analysis on the InputImage using the supplied RunParams. You can specify that analysis be limited to part of the input image by supplying a value for the Region property.

Note: This method does not actually raise the exceptions listed below. Use the RunStatus property to obtain a ICogRunStatus reference. Then use its Exception property to see if the Run method raised any exceptions.

Examples

using Cognex.VisionPro;
using Cognex.VisionPro.Blob;
using Cognex.VisionPro.ImageFile;

// This function finds two holes in the bracket. 
public void FindBlobs()
{
CogImageFileTool mCogImageFileTool = new CogImageFileTool();
CogBlobTool mCogBlobTool = new CogBlobTool();
CogBlobMeasure mAreaMeasure = new CogBlobMeasure();
CogBlobMeasure mElongationMeasure = new CogBlobMeasure();
CogBlobResultCollection mBlobResults;

// Load the breacket image as the input image.
mCogImageFileTool.Operator.Open(@"C:\Program Files\Cognex\VisionPro\images\bracket_std.idb",
CogImageFileModeConstants.Read);
mCogImageFileTool.Run();

mCogBlobTool.InputImage = (CogImage8Grey)mCogImageFileTool.OutputImage;
mCogBlobTool.RunParams.SegmentationParams.Polarity = CogBlobSegmentationPolarityConstants.LightBlobs;

// Set Area Filter, select blobs whose area is between 450 and 500.
mAreaMeasure.Measure = CogBlobMeasureConstants.Area;
mAreaMeasure.FilterMode = CogBlobFilterModeConstants.IncludeBlobsInRange;
mAreaMeasure.FilterRangeHigh = 550;
mAreaMeasure.FilterRangeLow = 450;
mAreaMeasure.Mode = CogBlobMeasureModeConstants.Filter;

// Set Elongation Filter from 0.8 to 1.2
mElongationMeasure.Measure = CogBlobMeasureConstants.Elongation;
mElongationMeasure.FilterMode = CogBlobFilterModeConstants.IncludeBlobsInRange;
mElongationMeasure.FilterRangeHigh = 1.2;
mElongationMeasure.FilterRangeLow = 0.8;
mElongationMeasure.Mode = CogBlobMeasureModeConstants.Filter;

mCogBlobTool.RunParams.RunTimeMeasures.Add(mAreaMeasure);
mCogBlobTool.RunParams.RunTimeMeasures.Add(mElongationMeasure);

mCogBlobTool.Run();
mBlobResults = mCogBlobTool.Results.GetBlobs();

Console.WriteLine("Number of Blobs: {0}", mBlobResults.Count);

// Print information for each blob found 
foreach (CogBlobResult blobResult in mBlobResults)
{
Console.WriteLine("ID: {0}, CenterX: {1}, CenterY: {2}, Area: {3}",
blobResult.ID, blobResult.CenterOfMassX, blobResult.CenterOfMassY, blobResult.Area);
}
}
Imports Cognex.VisionPro
Imports Cognex.VisionPro.Blob
Imports Cognex.VisionPro.ImageFile

Public Sub FindBlobs()
' This function finds two holes in the bracket.
Dim myCogImageFileTool As CogImageFileTool = New CogImageFileTool()
Dim myCogBlobTool As CogBlobTool = New CogBlobTool()
Dim myAreaMeasure As CogBlobMeasure = New CogBlobMeasure()
Dim myElongationMeasure As CogBlobMeasure = New CogBlobMeasure()
Dim myBlobResults As CogBlobResultCollection

' Load the breacket image as the input image.
myCogImageFileTool.Operator.Open("C:\Program Files\Cognex\VisionPro\images\bracket_std.idb", CogImageFileModeConstants.Read)
myCogImageFileTool.Run()

myCogBlobTool.InputImage = CType(myCogImageFileTool.OutputImage, CogImage8Grey)
myCogBlobTool.RunParams.SegmentationParams.Polarity = CogBlobSegmentationPolarityConstants.LightBlobs

' Set Area Filter
myAreaMeasure.Measure = CogBlobMeasureConstants.Area
myAreaMeasure.FilterMode = CogBlobFilterModeConstants.IncludeBlobsInRange
myAreaMeasure.FilterRangeHigh = 550
myAreaMeasure.FilterRangeLow = 450
myAreaMeasure.Mode = CogBlobMeasureModeConstants.Filter

' Set Elongation Filter
myElongationMeasure.Measure = CogBlobMeasureConstants.Elongation
myElongationMeasure.FilterMode = CogBlobFilterModeConstants.IncludeBlobsInRange
myElongationMeasure.FilterRangeHigh = 1.2
myElongationMeasure.FilterRangeLow = 0.8
myElongationMeasure.Mode = CogBlobMeasureModeConstants.Filter

myCogBlobTool.RunParams.RunTimeMeasures.Add(myAreaMeasure)
myCogBlobTool.RunParams.RunTimeMeasures.Add(myElongationMeasure)

myCogBlobTool.Run()
myBlobResults = myCogBlobTool.Results.GetBlobs()

Console.WriteLine("Number of Blobs: {0}", myBlobResults.Count)

' Print information for each blob found
For Each blobResult As CogBlobResult In myBlobResults
Console.WriteLine("ID: {0}, CenterX: {1}, CenterY: {2}, Area: {3}", _
blobResult.ID, blobResult.CenterOfMassX, blobResult.CenterOfMassY, blobResult.Area)
Next
End Sub
See Also