Template Matching¶
Function¶
This Step matches the objects in the input image with the 2D template to calculate the 2D poses of the objects.
Usage Scenario¶
This Step is used to locate the target objects in the image, in order to calculate the poses or the 2D transformation for image position and orientation correction in subsequent Steps.
Input and Output¶
Parameter Description¶
The workflow of adjusting the parameters of this Step is as follows:
- Gradient Magnitude Lower Threshold
- Object features must be extracted before matching. Pixels with gradient magnitudes greater than this threshold are regarded as feature pixels for matching.Default value: 60Instructions: a higher value gives a more accurate feature pixel extraction, but if the value is set too high, the extractable feature pixels may become too few.
The following figure shows the extracted feature pixels of the same object when Gradient Magnitude Lower Threshold is set to 10 (left) and 60 (right).
When set to 10, the feature pixel extraction is not quite accurate, and some feature pixels fall on the background. When set to 60, the feature pixel extraction is more accurate.
- Template Features Already Extracted
- Set whether feature pixels of the template image are extracted.Default setting: uncheckedInstructions:
When this Step is run for the first time, this option is unchecked by default. Therefore, the feature pixels of the imported template image (from Template Image File Path) are extracted and saved to Template Feature File Path. Then, the feature pixels of the input image are extracted, and matching is performed.
When this Step is run again, this option is automatically checked, and matching is performed using the saved feature pixels of the template image.
If you need to extract the feature pixels of the template image, such as when you changed the template image, please uncheck this option and run this Step.
Template Settings (Displayed when Template Features Already Extracted is unchecked)
- Template Feature File Path
Instructions: select the directory for saving the template feature files.- Template Image File Path
Instructions: select the template image output by Make Template.- Template Mask File Path
Instructions: select the template mask output by Make Template.
- Starting Angle
Starting Angle and End Angle specify the rotation range of the template in the input image during matching.Default value: -180.0- End Angle
Starting Angle and End Angle specify the rotation range of the template in the input image during matching.Default value: 180.0- Angle Step
Angle Step determines the rotation increment of matching attempts.Default value: 1.0- Starting Scale
Starting Scale and End Scale specify the scaling range of the template in the input image during matching.Default value: 0.80- End Scale
Starting Scale and End Scale specify the scaling range of the template in the input image during matching.Default value: 1.20- Scale Step
Scale Step determines the scaling increment of matching attempts.Default value: 0.20
Match Settings (Displayed when Template Features Already Extracted is checked)
- Matching Score Lower Threshold
Matching results with scores lower than this threshold are discarded, and the remaining results will be output after being filtered in the refinement process of this Step.Default value: 50.0Attention
If this threshold is set too high, all results might be discarded and none will be output.
If some objects are blocked by others, this threshold should be lowered accordingly.
- Upper Limit for Number of Matches
If the actual number of matching results is greater than this value, the results at the end of the list are discarded.Default value: 3
When Matching Score Lower Threshold is kept constant, the higher the value of Upper Limit for Number of Matches, the more matching results may be output. In the following figure, Matching Score Lower Threshold is set to 25, and Upper Limit for Number of Matches is set to 1 (left) or 4 (right). The number of matching results output is 1 and 4, respectively.
Note
The value of Upper Limit for Number of Matches doesn’t necessarily equal to the actual number of output matching results. With a high Matching Score Lower Threshold, more matching results are discarded, and the total number of output results may be less than the Upper Limit for Number of Matches.
When Upper Limit for Number of Matches is kept constant, the higher the value of Matching Score Lower Threshold, the fewer matching results may be output. In the following figure, Upper Limit for Number of Matches is set to 4, and Matching Score Lower Threshold is set to 25 (left) or 50 (right). The number of matching results output is 4 and 3, respectively.
In the figure above, the right one only output 3 results, despite Upper Limit for Number of Matches being set to 4. This is because only 3 matching results have scores higher than the set value of Matching Score Lower Threshold, so only 3 results at most can be output.
- Overlap Ratio Upper Threshold
If two matching results overlap and the overlap ratio exceeds this value, the result with the higher matching score is kept, and the other one is discarded.Default value: 0.40
Refinement Settings (Displayed when Template Features Already Extracted is checked)
- Search Radius
The search radius is used to find the correspondences in pose refinement. When the matching results are not very good, please increase this value accordingly.Default value: 10.0