You are here: Start » Tutorial Exercises » Measure Objects (measure_object)

Measure Objects (measure_object)

Aim

Devise an algorithm that measures the width of objects depicted in the provided images.

Measured width should presented in human readable format and should be depicted on an input image.

Assume that the camera is calibrated and pixels to millimeters scale equals 18,00.

Input

The set of images with a single mount depicted.

Images are stored in measure_objects directory.

Output

Image of the measured object with its width drawn on an input image.

The measured value should be presented in millimeters.

Hints

This exercise can be solved using two most frequently used techniques: 1D Edge detection and Template Matching. In first part object should be found and after that calculated object's alignment should be used to perform measurements.

Select one of input images to create a template matching model on it. The template matching model does not have to include entire object. Model may contain only object's characteristic part. Selecting part of the object may also make the matching process quite faster.

The prepared model should be used to locate the object on the image. Use LocateSingleObject_Edges because always only one object is depicted on the image.

To measure object width use MeasureObjectWidth which is using 1D Edge Detection technique.

Solution (AVS)

  1. Add EnumerateImages filter to load images from directory the input directory,

  2. Perform single iteration of project,

  3. Add filter LocateSingleObject_Edges and open editor for input inEdgeModel:

    • Select output of EnumerateImages as the editor background.

    • In first step of the dialog mark the border of mount and the smallest hole in the middle. This selection will be sufficient to detect other objects. The image below shows the selected part of the mount.

    • In the second step mark the whole mount.

  4. To measure objects width ready-to-use tool MeasureObjectWidth. This filter uses 1D Edge Detection technique to measure width. Tool works like ScanSingleStripe filter but is prepared for most commonly used tasks.

  5. To measure object width select scan field that will contain only parallel object edges. Image below shows selected scanning field.

  6. To get precise results set inScanCount to 20.

  7. Set inStripeScanParams.StripePolarity to Dark.

  8. Create a new macrofilter DrawResults which converts found width to millimeters and draws result on an input image.

  9. Add Empty Formula to DrawResults and create two inputs: inLength (Real) and inScale (Real).

  10. Add new output "outLabel" of type String and enter the following formula:

    outLabel = "Size: " + toString(inLength/inScale) + "mm"

    This formula calculates object width in millimeters and converts this result to human-readable text.

  11. Add filter DrawStrings_SingleColor to draw calculated width on the input image.

Macrofilter Main finds object and calculates object's width.

Macrofilter DrawResults draws measured width on the input image.