Generate and Edit Matching Templates in Mech-MSR

You are currently viewing the documentation for the latest version (2.2.2). To access a different version, click the "Switch version" button located in the upper-right corner of the page.

■ If you are not sure which version of the product you are currently using, please feel free to contact Mech-Mind Technical Support.

In Mech-MSR, use the 2D template editor to define 2D regions of interest (ROIs) on the image. Data within the ROI is used to extract edge features for generating a 2D matching template.

The extracted edge features should meet the following requirements:

  • Common to all images: If the extracted edge features are not present in all images, matching between the images and the template may fail.

  • Representative: Extracted edge features must be representative to ensure unique and accurate matching; otherwise, matching results may be incorrect.

  • Moderate quantity: In general, more extracted edge features improve matching accuracy. However, an excessive number may reduce matching speed.

Start the Feature

In the parameter configuration panel of the Step, click the Open the editor button to open the 2D Template Editor.

Matching templates cannot be used across scenarios.

Preparations

  1. Ensure that the Step has proper input.

  2. Under Parameters in the parameter configuration panel of the Step, click the Open the editor button to open the 2D Template Editor. This tool will automatically obtain the input image of the Step.

  • Click the Get current input or Rerun project button in the editor’s parameter panel on the right to update the input image.

    • Get current input: Get the image already available at the input port of the current Step without rerunning the project. Suitable for generating a template using the existing input image.

    • Rerun project: Rerun the project to obtain a new input image for the current Step. Suitable when no valid input image is available or when a new input image is needed to generate a template.

  • When the X-axis resolution and the Y-axis resolution of an image differ, the software will automatically adjust the image so that its resolution ratio is 1:1. After returning to the main interface, the image display returns to normal.

resolution change for image

Workflow

  1. Rename the default template or click the + New button to create a new template.

    After selecting a template from the template list, right-click and select the Rename option, enter a custom name, and click the OK button to rename the template.
    2d template rename 1
  2. Select an ROI. Ensure that the edge features in the ROI are representative and not excessive.

    Instruction: Click the icon on the toolbar to the right of the template list to select the appropriate ROI tool and create ROIs in the image. Note that the extracted edge features will only take effect when a feature region or ROI is used in the Step. Otherwise, the generated matching template will lead to matching failure.

    • In the ROI list section at the bottom left of the interface, right-click an ROI and select Enable, Disable, etc., to set the drawn ROI.

    • For overlapping areas, Disable has priority over Enable. In other words, when one region is set to Enabled and an overlapping region to Disabled, the overlapping area is effectively Disabled; edge features within it are ignored and not used for template generation.

      overlap region status
  1. Set the template coordinate system. Click Edit origin to set the coordinate system origin, and adjust Angle as needed to set the coordinate system direction.

  2. Set Feature parameters.

  3. Click the Generate template button in the lower-right corner to generate and preview the template.

    generated model
  4. Click the Save button in the lower-right corner to save the generated template.

    If you only clicked the Save button in the lower-right corner and did not generate a template, the edited template would be saved but would not work.

After configuration, close the editor. Click under the Open the editor button in the Step and then select the corresponding template in the drop-down menu.

ROI Drawing Tools

The usage instructions on ROI drawing tools are shown in the table below.

Icon Tool Instructions
circle roi

Circle ROI Tool

Use the Circle ROI Tool to draw a circular ROI.

  1. Click the Circle ROI Tool icon on the toolbar to the right of the template list circle roi.

  2. Press and hold the left mouse button and drag the crosshair cursor in the drawing area to draw a circle.

  3. Release the left mouse button to finish the drawing.

rectangle roi

Rectangle ROI Tool

Use the Rectangle ROI Tool to draw a rectangular ROI.

  1. Click the Rectangle ROI Tool icon on the toolbar to the right of the template list rectangle roi.

  2. Press and hold the left mouse button and drag the crosshair cursor in the drawing area to draw a rectangle.

  3. Release the left mouse button to finish the drawing.

polygon roi

Polygon ROI Tool

Use the Polygon ROI Tool to draw a polygonal ROI.

  1. Click the Polygon ROI Tool icon on the toolbar to the right of the template list polygon roi.

  2. Click the first position (vertex) in the drawing area, then click the second one, etc., to draw the polygon. (At least three vertices are required.)

  3. Right-click to finish.

roi eraser

ROI Eraser Tool

Use the ROI Eraser Tool to erase the drawn ROI, and the points in the erased parts will not be used to generate the template.

  1. Click the ROI Eraser Tool icon on the toolbar to the right of the template list roi eraser.

  2. In the upper-left corner of the ROI drawing area, drag the slider or change the pixel value to adjust the eraser size.

  3. Press and hold the left mouse button and drag in any direction in the drawing area to determine the drawn regions to be erased.

  4. Release the left mouse button to finish the drawing.

select tool

Select Tool

Use the Select Tool to select and edit the drawn ROI.

  1. Click Select Tool icon on the toolbar to the right of the template list select tool.

  2. Select an ROI from ROI list, or click an ROI in the drawing area. At this point, vertices appear on the edges of the ROI, and the mouse cursor changes to an open-hand cursor when positioned over the ROI hand icon .

  3. Press and hold the left mouse button and drag the ROI in any direction. The open-hand cursor hand icon changes to a closed-hand cursor fist icon. Release the left mouse button to complete the move.

  4. Hover the cursor over a vertex. When the cursor changes to a hand pointerpoint icon, press and hold the left mouse button and drag the vertex to change the shape or size of the ROI. Release the left mouse button to finish.

  • After drawing an ROI, click the Select Tool select tool on the toolbar to edit the ROI.

  • The Select Tool cannot be used to edit the regions erased by the ROI Eraser Tool.

Set the Template Coordinate System

Origin X, Origin Y, and Angle jointly define the template coordinate system:

  • Origin X and Origin Y: Define the position of the template coordinate system origin in the current image.

  • Angle: Defines the direction of the template coordinate system, that is, the angle between the positive X-axis of the template coordinate system and that of the image coordinate system. Clockwise is positive, and counterclockwise is negative.

The template coordinate system is saved with the template. The 2D Matching, 2D Alignment, Surface Matching, and Surface Alignment Steps output Object Pose based on the template coordinate system. When Object Pose is input to downstream Steps, these Steps can adjust their ROIs or feature regions according to changes in the workpiece pose.

Setting Method

Set the template coordinate system as follows:

  1. In the Set template coordinate system section, click Edit origin.

  2. In the drawing area, select an easily identifiable feature point with a stable position, such as the center of a circular hole, and click it to set the template coordinate system origin. Alternatively, set Origin X and Origin Y to specify the origin position precisely.

  3. Adjust Angle to set the positive X-axis direction of the template coordinate system.

  4. Click Generate template, and then click Save.

After changing the template coordinate system, you do not need to regenerate the template, but you must save it again. Otherwise, the new template coordinate system will not take effect.

Applicable Scenarios

When creating a template for the first time, you must click Edit origin to establish the template coordinate system. To adjust the coordinate system direction, set Angle to define the positive X-axis direction.

For a project in which the positioning or measurement process has already been configured, you may need to recreate a template for the same workpiece while continuing to use the existing ROIs or feature regions in downstream Steps. In this case, ensure that the workpiece has the same imaging scale in the new and original templates, and configure the new template based on the original template as follows:

  • Set the coordinate system origin of the new template at the same feature position on the workpiece.

  • Make the X-axes of the new and original templates point in the same direction relative to the workpiece.

When setting the coordinate system of the new template, you do not need to calculate the angle difference between the new and original templates based on the angle of the original template. With the workpiece as the reference, simply keep the origins and X-axis directions of the two template coordinate systems consistent.

As shown below, the workpiece has different angles in the original and new templates. The coordinate system origins of both templates are located at the same circular feature on the workpiece, and both X-axes point from that circular feature toward the curved outer edge of the workpiece. Therefore, the two template coordinate systems have the same position and direction relative to the workpiece.

original template coordinate system
new template coordinate system

Original Template

New Template

After switching to the new template, the existing ROIs or feature regions in downstream Steps still cover the original target areas on the workpiece and do not need to be adjusted again.

roi after template replacement
This effect applies only when downstream Steps use Object Pose to adjust their ROIs or feature regions. When Alignment Parameter Group is used, adjustment is still required after switching templates.

Feature Parameters

Parameter Description

Search scale

The downsampling scale applied to the template image during the fast search phase. A larger scale increases the search speed but reduces feature resolution. In Auto Mode, the system selects the optimal search scale based on the image content.

Search step

The search step size, at the subpixel level, during fine matching. A smaller step improves search accuracy but increases computation.

Edge threshold

Points with a gradient magnitude greater than or equal to this value are considered edge features and used for template matching.

Min chain length

The minimum number of feature points required for an edge contour. Contours with fewer points are removed to filter out noise.

After confirming that the edge features in the ROI are stable and representative, you can quickly adjust the feature parameters along the following steps:

  • Prefer Auto Mode for Search scale.

  • Inaccurate positioning: Decrease Search step as appropriate.

It is recommended to adjust only one parameter at a time and observe the result after regenerating the template.

Is this page helpful?

You can give a feedback in any of the following ways:

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.