You are here: Start » User Interface » Creating Models for Template Matching

Creating Models for Template Matching

Introduction

Template Matching tools are very often used as one of the first steps in industrial inspection applications. The goal is to detect the location of an object, but before this can be done the user has to create a model representing the expected object's shape or structure. To make this step straightforward, Adaptive Vision Studio provides an easy user interface. We call it "GUI for Template Matching".

The GUI for Template Matching is an editor for values of two types: EdgeModel and GrayModel. This means that to open it the user has to select a template matching filter in the program and then click on the button at the inGrayModel or inEdgeModel input in the Properties window:

Opening GUI for Template Matching.

Creating a Model

The window that opens up contains the following elements:

  1. At the top: a list of possible template (reference) images
  2. Below: a simple toolbar that also contains a button for loading a reference image from a file
  3. On the left: a set of tools for marking the template region
  4. On the right: parameters of the model and some options related to the view
  5. In the center: an area for marking the template region in the context of the selected reference image

GUI for Template Matching window

To create a template matching model you need to:

  1. Choose a template image from the list.
  2. Mark the template region using the drawing tools (please note, that the button above the tools switches the current color, i.e. you can both draw or erase shapes)
  3. Edge-base matching only: Set the inSmoothingStdDev, inEdgeMagnitudeThreshold and inEdgeHysteresis parameters to values that result in the best quality of the found edges. It is advisable to first set inEdgeHysteresis to zero, then choose a value for inEdgeMagnitudeThreshold that assures that all edges have some parts detected and then increase inEdgeHysteresis. Small noise might by removed by change the value of parameter inSmoothingStdDev. For example:

    Low quality edges

    High quality edges

  4. Set the inMinAngle and inMaxAngle parameters accordingly to the expected range of object rotations (the smaller the range, the faster the matching).
  5. Set the inAnglePrecision to a value lower that 1.0 if you prefer to lower the angular precision for the benefit of speed.
  6. Set the inMinScale, inMaxScale and inScalePrecision to appropriate value if you need to detect objects in different scale. You should be aware of longer detection time when you detect objects in scale.
  7. Click the "Refresh" button or check "Update preview after each modification" to review the results.
  8. Click the "Next >" button to select template rectangle that represents the entire object of interest (the expected result of matching)

    Template rectangle selection

  9. Click "OK" to close the window and generate the model.

Performing Template Matching

When the model is ready, performing template matching in an application is straightforward – after connecting the filters and setting the matching parameters, the results are on the outputs of the LocateSingleObject_Edges filter (or similar):

Example result of template matching

See also:

Template Matching guide, Template Matching filters
Previous: Creating Macrofilters Next: Creating Lens Undistortion Maps