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

Measure Objects (measure_object)

Aim

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

Measured width should be presented in human-readable format and depicted in 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

The image of the measured object with its width drawn in the 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 the first part object should be found and after that calculated object's alignment should be used to perform measurements.

Create a template matching model for one of selected images. The template matching model does not have to include the entire object. It is recommended that the model contains only the object's characteristic part to make the matching process quite faster.

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

To measure the object width use MeasureObjectWidth which uses 1D Edge Detection technique.

Labeling connections is explained in this article.

You can learn how to turn on sections here.

Solution (AVS)

  1. Add LoadObject of Region type in the INITIALIZE section to load the region of inspection beforehand. Change the input of inFile input to the measure_object.67304a53.Region.avdata in the Properties window.

  2. Add the EnumerateImages filter in the ACQUIRE section to load images from the input directory.

  3. Add LocateSingleObject_Edges1 and connect outImage with inImage.

  4. Perform a single iteration of the program.

  5. The program should stop due to the lack of defining the mandatory input, so open the inEdgeModel editor to create a model:

    • 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:

  6. To measure the object width, add the ready-to-use tool MeasureObjectWidth. This filter uses 1D Edge Detection technique to measure width. The tool works like the ScanSingleStripe filter but is prepared for most commonly used tasks.

  7. Create scan field that will contain only parallel object edges. Image below shows selected scanning field:

  8. To get precise results set inScanCount to 20 to increase the number of scans to be performed.

  9. Set inStripeScanParams.StripePolarity to Dark because the object is clearly darker than the background.

  10. Create a new macrofilter DrawResults to convert the measured width to millimeters and to draw a result in the input image. Connect outImage from the EnumerateImages filter and outObjectWidth with the Draw Results macrofilter. The other input name inLength.

  11. Add Empty formula into DrawResults and create the inScale input of type Real and connect inLength with the formula.

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

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

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

  13. Add filter DrawStrings_SingleColor to draw the calculated width in the input image.

Macrofilter Main finds object and calculates object's width.

Macrofilter DrawResults draws measured width on the input image.

Further Readings