create_templateT_create_templateCreateTemplateCreateTemplatecreate_template (算子)
名称
create_templateT_create_templateCreateTemplateCreateTemplatecreate_template — 准备模板匹配模式。
警告
create_templatecreate_templateCreateTemplateCreateTemplateCreateTemplatecreate_template 已过时,仅出于向后兼容性考虑而保留。新应用程序应改用基于形状或基于 NCC 的算子。
签名
void CreateTemplate(const HObject& Template, const HTuple& FirstError, const HTuple& NumLevel, const HTuple& Optimize, const HTuple& GrayValues, HTuple* TemplateID)
void HTemplate::HTemplate(const HImage& Template, Hlong FirstError, Hlong NumLevel, const HString& Optimize, const HString& GrayValues)
void HTemplate::HTemplate(const HImage& Template, Hlong FirstError, Hlong NumLevel, const char* Optimize, const char* GrayValues)
void HTemplate::HTemplate(const HImage& Template, Hlong FirstError, Hlong NumLevel, const wchar_t* Optimize, const wchar_t* GrayValues)
(
Windows only)
void HTemplate::CreateTemplate(const HImage& Template, Hlong FirstError, Hlong NumLevel, const HString& Optimize, const HString& GrayValues)
void HTemplate::CreateTemplate(const HImage& Template, Hlong FirstError, Hlong NumLevel, const char* Optimize, const char* GrayValues)
void HTemplate::CreateTemplate(const HImage& Template, Hlong FirstError, Hlong NumLevel, const wchar_t* Optimize, const wchar_t* GrayValues)
(
Windows only)
HTemplate HImage::CreateTemplate(Hlong FirstError, Hlong NumLevel, const HString& Optimize, const HString& GrayValues) const
HTemplate HImage::CreateTemplate(Hlong FirstError, Hlong NumLevel, const char* Optimize, const char* GrayValues) const
HTemplate HImage::CreateTemplate(Hlong FirstError, Hlong NumLevel, const wchar_t* Optimize, const wchar_t* GrayValues) const
(
Windows only)
static void HOperatorSet.CreateTemplate(HObject template, HTuple firstError, HTuple numLevel, HTuple optimize, HTuple grayValues, out HTuple templateID)
public HTemplate(HImage template, int firstError, int numLevel, string optimize, string grayValues)
void HTemplate.CreateTemplate(HImage template, int firstError, int numLevel, string optimize, string grayValues)
HTemplate HImage.CreateTemplate(int firstError, int numLevel, string optimize, string grayValues)
描述
算子 create_templatecreate_templateCreateTemplateCreateTemplateCreateTemplatecreate_template preprocesses a pattern
(TemplateTemplateTemplateTemplatetemplatetemplate),
which is passed as an image, for the template matching.
After the transformation, a number (TemplateIDTemplateIDTemplateIDTemplateIDtemplateIDtemplate_id) is
assigned to the template for being used in the further process.
The shape and the size of TemplateTemplateTemplateTemplatetemplatetemplate can be
chosen arbitrarily.
You have to be aware, that the matching is only applied
to that part of an image where TemplateTemplateTemplateTemplatetemplatetemplate fits
completely into the image.
The template has been chosen such that it contains no pixels of the
(changing) background.
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
thresholdthresholdThresholdThresholdThresholdthreshold or one of the draw_* operators.
In the case of sub pixel accurate matching
TemplateTemplateTemplateTemplatetemplatetemplate 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
erosion_circleerosion_circleErosionCircleErosionCircleErosionCircleerosion_circle。
The parameter NumLevelNumLevelNumLevelNumLevelnumLevelnum_level specifies the number
of pyramid levels (NumLevelNumLevelNumLevelNumLevelnumLevelnum_level = 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).
The parameter GrayValuesGrayValuesGrayValuesGrayValuesgrayValuesgray_values defines, whether
the original gray values ('original'"original""original""original""original""original", 'normalized'"normalized""normalized""normalized""normalized""normalized") or
the edge amplitude ('gradient'"gradient""gradient""gradient""gradient""gradient", 'sobel'"sobel""sobel""sobel""sobel""sobel") is used.
With 'original'"original""original""original""original""original" the sum of the differences is used
as feature which is very stable and fast if there is no change
in illumination. 'normalized'"normalized""normalized""normalized""normalized""normalized" is used if the
illumination changes. The method is a bit slower and not quite as
stable. Note that 'normalized'"normalized""normalized""normalized""normalized""normalized" allows to compensate additive
illumination changes. If also multiplicative variations of the gray values
occur, correlation-based matching should be used (create_ncc_modelcreate_ncc_modelCreateNccModelCreateNccModelCreateNccModelcreate_ncc_model).
If there is no change in illumination the mode
'original'"original""original""original""original""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'"gradient""gradient""gradient""gradient""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 GrayValuesGrayValuesGrayValuesGrayValuesgrayValuesgray_values leads automatically
to calling the appropriate filter during the matching, if necessary.
As an alternative to the gradient approach the operator
set_offset_templateset_offset_templateSetOffsetTemplateSetOffsetTemplateSetOffsetTemplateset_offset_template can be used,
if the change in illumination is known.
The parameter OptimizeOptimizeOptimizeOptimizeoptimizeoptimize 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 set_reference_templateset_reference_templateSetReferenceTemplateSetReferenceTemplateSetReferenceTemplateset_reference_template。
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 adapt_templateadapt_templateAdaptTemplateAdaptTemplateAdaptTemplateadapt_template。
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
此算子返回一个句柄。请注意,即使该句柄被用作特定算子的输入参数,这些算子仍可能改变此句柄类型的实例状态。
参数
TemplateTemplateTemplateTemplatetemplatetemplate (输入对象) singlechannelimage → objectHImageHObjectHImageHobject (byte)
Input image whose domain will be processed
for the pattern matching.
FirstErrorFirstErrorFirstErrorFirstErrorfirstErrorfirst_error (输入控制) integer → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
Not yet in use.
默认值:
255
值列表:
255
NumLevelNumLevelNumLevelNumLevelnumLevelnum_level (输入控制) integer → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
Maximal number of pyramid levels.
默认值:
4
值列表:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
OptimizeOptimizeOptimizeOptimizeoptimizeoptimize (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
Kind of optimizing.
默认值:
'sort'
"sort"
"sort"
"sort"
"sort"
"sort"
值列表:
'none'"none""none""none""none""none", 'sort'"sort""sort""sort""sort""sort"
GrayValuesGrayValuesGrayValuesGrayValuesgrayValuesgray_values (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
Kind of gray values.
默认值:
'original'
"original"
"original"
"original"
"original"
"original"
值列表:
'gradient'"gradient""gradient""gradient""gradient""gradient", 'normalized'"normalized""normalized""normalized""normalized""normalized", 'original'"original""original""original""original""original", 'sobel'"sobel""sobel""sobel""sobel""sobel"
TemplateIDTemplateIDTemplateIDTemplateIDtemplateIDtemplate_id (输出控制) template → HTemplate, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
模板编号。
结果
如果参数有效,算子
create_templatecreate_templateCreateTemplateCreateTemplateCreateTemplatecreate_template 返回值 2 ( H_MSG_TRUE )。如有必要,则抛出异常。
可能的前趋
draw_regiondraw_regionDrawRegionDrawRegionDrawRegiondraw_region,
reduce_domainreduce_domainReduceDomainReduceDomainReduceDomainreduce_domain,
thresholdthresholdThresholdThresholdThresholdthreshold
可能的后继
adapt_templateadapt_templateAdaptTemplateAdaptTemplateAdaptTemplateadapt_template,
set_reference_templateset_reference_templateSetReferenceTemplateSetReferenceTemplateSetReferenceTemplateset_reference_template,
clear_templateclear_templateClearTemplateClearTemplateClearTemplateclear_template,
write_templatewrite_templateWriteTemplateWriteTemplateWriteTemplatewrite_template,
set_offset_templateset_offset_templateSetOffsetTemplateSetOffsetTemplateSetOffsetTemplateset_offset_template,
best_matchbest_matchBestMatchBestMatchBestMatchbest_match,
best_match_mgbest_match_mgBestMatchMgBestMatchMgBestMatchMgbest_match_mg,
fast_matchfast_matchFastMatchFastMatchFastMatchfast_match,
fast_match_mgfast_match_mgFastMatchMgFastMatchMgFastMatchMgfast_match_mg
替代
create_ncc_modelcreate_ncc_modelCreateNccModelCreateNccModelCreateNccModelcreate_ncc_model,
create_template_rotcreate_template_rotCreateTemplateRotCreateTemplateRotCreateTemplateRotcreate_template_rot,
read_templateread_templateReadTemplateReadTemplateReadTemplateread_template
模块
匹配