Measure Objects (measure_object)
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.
The set of images with a single mount depicted.
Images are stored in
The image of the measured object with its width drawn in the input image.
The measured value should be presented in millimeters.
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_Edges 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.
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.
Add the EnumerateImages filter in the ACQUIRE section to load images from the input directory.
Perform a single iteration of the program.
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:
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.
Create scan field that will contain only parallel object edges. Image below shows selected scanning field:
To get precise results set inScanCount to 20 to increase the number of scans to be performed.
Set inStripeScanParams.StripePolarity to Dark because the object is clearly darker than the background.
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.
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.
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.
- Template Matching - Most detailed description of the Template Matching technique.