EasyObjectInertia
Support |
|
||||||||
Required licenses |
EasyObject |
||||||||
Recommended images |
The images Washer and Target 1 from the folder Sample Images\EasyGauge |
||||||||
Location |
Matching and Measurement\EasyObjectInertia \ |
||||||||
Direct links
|
Purpose
This sample program demonstrates how to:
□ | Find blobs (objects or holes that have the same gray level range) in the image. |
□ | Keep only the blobs whose area is in a given range. |
Code highlights
1. | Define an image encoder to encode an image (m_Image) into an object ECodedImage2 (m_CodedImage). |
EImageEncoder encoder;
encoder.Encode(m_Image, m_CodedImage);
2. | Add the objects to an object selection object (EObjectSelection m_Selection). |
// Select all the objects from the coded image
m_Selection.Clear();
m_Selection.AddObjects(m_CodedImage);
3. | Filter the selection of objects by removing all objects whose area is outside the range [50, 10 000]. |
// Remove objects too small or too large
m_Selection.RemoveUsingUnsignedIntegerFeature(EFeature_Area, 50, 10000, EDoubleThresholdMode_Outside);
4. | Draw the selected objects and their ellipse of inertia with their diagonals. |
// Draw all the selected objects
CodedImage.Draw(hDC, selection);
// Draw the ellipses of inertia with their diagonals, using a red pen
const ERGBColor redPen(255, 0, 0);
CodedImage.DrawFeature(hDC, redPen, EDrawableFeature_Ellipse, selection, 1.0f, 1.0f, 0.0f, 0.0f, true);