create_template — Preparing a pattern for template matching.
create_template is obsolete and is only provided for
reasons of backward compatibility. New applications should use the
shape-based or NCC-based operators instead.
create_template preprocesses a pattern
which is passed as an image, for the template matching.
After the transformation, a number (
assigned to the template for being used in the further process.
The shape and the size of
Template can be
You have to be aware, that the matching is only applied
to that part of an image where
completely into the image.
The template has been chosen such that it contains no pixels of the
Here you can make use of the arbitrary shape of a template
which is not restricted to a rectangle.
To create a template region you can use segmentation operators like
threshold or one of the draw_* operators.
In the case of sub pixel accurate matching
Template has in addition to be one pixel smaller
than the pattern (i.e. one pixel border to the changing background).
This can be done e.g., by applying the operator
NumLevel specifies the number
of pyramid levels (
NumLevel = 1 means only
original gray values) which can be used for matching.
The number of levels used later for matching will be below or
equal this value.
If the pattern becomes too small due to zooming,
the maximum number of pyramid levels is automatically
reduced (without error message).
GrayValues defines, whether
the original gray values ('original', 'normalized') or
the edge amplitude ('gradient', 'sobel') is used.
With 'original' the sum of the differences is used
as feature which is very stable and fast if there is no change
in illumination. 'normalized' is used if the
illumination changes. The method is a bit slower and not quite as
stable. Note that 'normalized' allows to compensate additive
illumination changes. If also multiplicative variations of the gray values
occur, correlation-based matching should be used (
If there is no change in illumination the mode
'original' should be used.
The edge amplitude is another method to be invariant to changes
in illumination. The disadvantage is the increased execution time
and the higher sensitivity to changes in the shape of the pattern.
The mode 'gradient' is slightly faster
but more sensitive to noise.
The maximum error for matching has typically to be chosen higher
when using the edge amplitude.
The mode chosen by
GrayValues leads automatically
to calling the appropriate filter during the matching, if necessary.
As an alternative to the gradient approach the operator
set_offset_template can be used,
if the change in illumination is known.
Optimize specifies if the pattern
has to be optimized for runtime. This optimization results
in a longer time to create the template but reduces the
time for matching. In addition the optimization
leads to a more stable matching, i.e., the possibilty
to miss good matches is reduced.
The optimization process selects the most stable and
significant gray values to be
tested first during the matching process. Using this technique a wrong
match can be eliminated very early.
The reference position for the template is its center of gravity.
I.e. if you apply the template to the original image the
center of gravity is returned. This default reference
can be adapted using the operator
In sub pixel mode a special position correction is calculated which is added after each matching: The template is applied to the original image and the difference between the found position and the center of gravity is used as a correction vector. This is important for patterns in a textured context or for asymmetric pattern. For most templates this correction vector is near null.
Before the use of the template, which is stored independently of the
image size, it can be adapted explicitly to
the size of a definite image size by using
This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.
Input image whose domain will be processed for the pattern matching.
Not yet in use.
Default value: 255
List of values: 255
Maximal number of pyramid levels.
Default value: 4
List of values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Kind of optimizing.
Default value: 'sort'
List of values: 'none', 'sort'
Kind of gray values.
Default value: 'original'
List of values: 'gradient', 'normalized', 'original', 'sobel'
If the parameters are valid, the operator
create_template returns the value 2 (H_MSG_TRUE).
If necessary an exception is raised.