Selecting and Sorting Blobs¶
This code snippet shows how to build blobs, select some of them and sort the selected ones.
C++¶
#include <eVision/EasyObject/EasyObject2/EImageEncoder.h>
using namespace eVision;
// Image constructor
EImageBW8 srcImage;
// Image encoder
EImageEncoder encoder;
// Coded image
ECodedImage2 codedImage;
// ...
// Encode the source image
encoder.Encode(srcImage, codedImage);
// Create a blob selection
EObjectSelection selection;
selection.AddObjects(codedImage);
// Remove the Small blobs
selection.RemoveUsingUnsignedIntegerFeature(EFeature_Area, 100, ESingleThresholdMode_Less);
// Retrieve the number of remaining blobs
unsigned int numBlobs = selection.GetElementCount();
// Sort the remaining blobs based on their area
selection.Sort(EFeature_Area, ESortDirection_Ascending);
// Retrieve the selected blobs
for (unsigned int index = 0; index < numBlobs; index++)
{
float centerX = selection.GetElement(index).GetGravityCenterX();
float centerY = selection.GetElement(index).GetGravityCenterY();
}
C#¶
using eVision;
// Image constructor
EImageBW8 srcImage = new EImageBW8();
// Image encoder
EImageEncoder encoder = new EImageEncoder();
// Coded image
ECodedImage2 codedImage = new ECodedImage2();
// ...
// Encode the source image
encoder.Encode(srcImage, codedImage);
// Create a blob selection
EObjectSelection selection = new EObjectSelection();
selection.AddObjects(codedImage);
// Remove the small blobs
selection.RemoveUsingUnsignedIntegerFeature(EFeature.Area, 100, ESingleThresholdMode.Less);
// Retrieve the number of remaining blobs
uint numBlobs = selection.ElementCount;
// Sort the remaining blobs based on their area
selection.Sort(EFeature.Area, ESortDirection.Ascending);
// Retrieve the selected blobs
for (uint index = 0; index < numBlobs; index++)
{
float centerX = selection.GetElement(index).GravityCenterX;
float centerY = selection.GetElement(index).GravityCenterY;
}
Python¶
import eVision
# Image constructor
src_image = eVision.EImageBW8()
# Image encoder
encoder = eVision.EImageEncoder()
# Coded image
codedImage = eVision.ECodedImage2()
# ...
# Encode the source image
encoder.Encode(src_image, codedImage)
# Create a blob selection
selection = eVision.EObjectSelection()
selection.AddObjects(codedImage)
# Remove the small blobs
selection.RemoveUsingUnsignedIntegerFeature(eVision.EFeature.Area, 100, eVision.ESingleThresholdMode.Less)
# Retrieve the number of remaining blobs
numBlobs = selection.ElementCount
# Sort the remaining blobs based on their area
selection.Sort(eVision.EFeature.Area, eVision.ESortDirection.Ascending)
# Retrieve the selected blobs
for index in range(numBlobs):
centerX = selection.GetElement(index).GravityCenterX
centerY = selection.GetElement(index).GravityCenterY