CogBlob Execute Method Cognex VisionPro 9.8
Performs blob analysis on the provided InputImage and optional Region, creating a CogBlobResults object which provides the results of the analysis. If Region is nothing then blob analysis will be performed on the entire InputImage.

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

public CogBlobResults Execute(
	ICogImage inputImage,
	ICogRegion region
)

Parameters

inputImage
Type: Cognex.VisionPro ICogImage
The input image to analyze. May be either a CogImage8Grey or a CogImage16Grey.
region
Type: Cognex.VisionPro ICogRegion
An optional CogRegion. If supplied, only the pixels which lie within this region (subject to the value of RegionMode) will be analyzed.

Return Value

Type: CogBlobResults
A CogBlobResults containing the results of the analysis.
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 the SubtractionImage was NULL.
CogBlobNoSubtractionImagePixelsException The segmentation mode is SubtractionImage and the SubtractionImage has 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.
Remarks

Performs blob analysis on the supplied inputImage and optional region, creating a CogBlobResults object which provides the results of the analysis. If region is nothing then blob analysis will be performed on the entire input image.

Examples

Imports Cognex.VisionPro
Imports Cognex.VisionPro.Blob

Dim myBlob As New CogBlob
Dim myAreaMeasure As New CogBlobMeasure
Dim myPerimeterMeasure As New CogBlobMeasure
Dim myBlobResults As CogBlobResults

Try
  ' Find all blobs with an area greater than 10 and' a perimeter greater than 100 pixels
  myAreaMeasure.Measure = CogBlobMeasureConstants.Area
  myAreaMeasure.FilterMode = CogBlobFilterModeConstants.IncludeBlobsInRange
  myAreaMeasure.FilterRangeLow = 10
  myAreaMeasure.FilterRangeHigh = 500000
  myAreaMeasure.Mode = CogBlobMeasureModeConstants.Filter

  myPerimeterMeasure.Measure = CogBlobMeasureConstants.Perimeter
  myPerimeterMeasure.FilterMode = CogBlobFilterModeConstants.IncludeBlobsInRange
  myPerimeterMeasure.FilterRangeLow = 100
  myPerimeterMeasure.FilterRangeHigh = 500000
  myPerimeterMeasure.Mode = CogBlobMeasureModeConstants.Filter
  myBlob.RunTimeMeasures.Add(myAreaMeasure)
  myBlob.RunTimeMeasures.Add(myPerimeterMeasure)

  myBlob.ConnectivityCleanup = CogBlobConnectivityCleanupConstants.Fill
  myBlob.SegmentationParams.Mode = CogBlobSegmentationModeConstants.HardDynamicThreshold
  myBlob.MorphologyOperations.Add(CogBlobMorphologyConstants.CloseSquare)
  ' mobjImage is an acquired image' txtUtil is a text box
  myBlobResults = myBlob.Execute(mobjImage, r)
  Debug.WriteLine(myBlobResults.GetBlobs.Count.ToString)
  Dim aResult As CogBlobResult
  Dim avgArea As Double
  For Each aResult In myBlobResults.GetBlobs
    avgArea = avgArea + aResult.Area
  Next

  avgArea = avgArea / myBlobResults.GetBlobs.Count
  Debug.WriteLine(" AvgArea:" + avgArea.ToString)

Catch ex As Exception
  Debug.WriteLine("Following Error Occurred:" + ex.Message)

End Try
using Cognex.VisionPro; 
using Cognex.VisionPro.Blob;

private void doBlob()
{
  CogBlob myBlob=new CogBlob(); 
  CogBlobMeasure myAreaMeasure=new CogBlobMeasure();  
  CogBlobMeasure myPerimeterMeasure=new CogBlobMeasure(); 
  CogBlobResults myBlobResults; 
  Double avgArea=0;
  try
{
  // Find all blobs with an area greater than 10 and' a perimeter greater than 100 pixels
  myAreaMeasure.Measure = CogBlobMeasureConstants.Area;
  myAreaMeasure.FilterMode = CogBlobFilterModeConstants.IncludeBlobsInRange;
  myAreaMeasure.FilterRangeLow = 10;
  myAreaMeasure.FilterRangeHigh = 500000;
  myAreaMeasure.Mode = CogBlobMeasureModeConstants.Filter;

  myPerimeterMeasure.Measure = CogBlobMeasureConstants.Perimeter;
  myPerimeterMeasure.FilterMode = CogBlobFilterModeConstants.IncludeBlobsInRange;
  myPerimeterMeasure.FilterRangeLow = 100;
  myPerimeterMeasure.FilterRangeHigh = 500000;
  myPerimeterMeasure.Mode = CogBlobMeasureModeConstants.Filter;
  myBlob.RunTimeMeasures.Add(myAreaMeasure);
  myBlob.RunTimeMeasures.Add(myPerimeterMeasure);

  myBlob.ConnectivityCleanup = CogBlobConnectivityCleanupConstants.Fill;
  myBlob.SegmentationParams.Mode = CogBlobSegmentationModeConstants.HardDynamicThreshold;
  myBlob.MorphologyOperations.Add(CogBlobMorphologyConstants.CloseSquare);
  // mobjImage is an acquired image' txtUtil is a text box
  myBlobResults = myBlob.Execute(mobjImage, r);
  Debug.WriteLine(myBlobResults.GetBlobs(true).Count.ToString());

  foreach (CogBlobResult aResult in myBlobResults.GetBlobs(true))
  {
    avgArea = avgArea + aResult.Area;
  }

  avgArea =avgArea / myBlobResults.GetBlobs(true).Count;
  Debug.WriteLine(" AvgArea:" + avgArea.ToString());
}
  catch (System.Exception ex)
  {
    Debug.WriteLine("Following Error Occurred:" + ex.Message);
  }


}
See Also