best_match_mgT_best_match_mgBestMatchMgBestMatchMgbest_match_mg最佳匹配多重网格(算子)

名称

best_match_mgT_best_match_mgBestMatchMgBestMatchMgbest_match_mg — 在金字塔中搜索最佳灰度值匹配。

警告

best_match_mgbest_match_mgBestMatchMgBestMatchMgBestMatchMgbest_match_mg 已过时,仅出于向后兼容性考虑而保留。新应用程序应改用基于形状或基于 NCC 的算子。

签名

best_match_mg(Image : : TemplateID, MaxError, SubPixel, NumLevels, WhichLevels : Row, Column, Error)

Herror T_best_match_mg(const Hobject Image, const Htuple TemplateID, const Htuple MaxError, const Htuple SubPixel, const Htuple NumLevels, const Htuple WhichLevels, Htuple* Row, Htuple* Column, Htuple* Error)

void BestMatchMg(const HObject& Image, const HTuple& TemplateID, const HTuple& MaxError, const HTuple& SubPixel, const HTuple& NumLevels, const HTuple& WhichLevels, HTuple* Row, HTuple* Column, HTuple* Error)

void HTemplate::BestMatchMg(const HImage& Image, double MaxError, const HString& SubPixel, Hlong NumLevels, const HTuple& WhichLevels, double* Row, double* Column, double* Error) const

void HTemplate::BestMatchMg(const HImage& Image, double MaxError, const HString& SubPixel, Hlong NumLevels, Hlong WhichLevels, double* Row, double* Column, double* Error) const

void HTemplate::BestMatchMg(const HImage& Image, double MaxError, const char* SubPixel, Hlong NumLevels, Hlong WhichLevels, double* Row, double* Column, double* Error) const

void HTemplate::BestMatchMg(const HImage& Image, double MaxError, const wchar_t* SubPixel, Hlong NumLevels, Hlong WhichLevels, double* Row, double* Column, double* Error) const   ( Windows only)

void HImage::BestMatchMg(const HTemplate& TemplateID, double MaxError, const HString& SubPixel, Hlong NumLevels, const HTuple& WhichLevels, double* Row, double* Column, double* Error) const

void HImage::BestMatchMg(const HTemplate& TemplateID, double MaxError, const HString& SubPixel, Hlong NumLevels, Hlong WhichLevels, double* Row, double* Column, double* Error) const

void HImage::BestMatchMg(const HTemplate& TemplateID, double MaxError, const char* SubPixel, Hlong NumLevels, Hlong WhichLevels, double* Row, double* Column, double* Error) const

void HImage::BestMatchMg(const HTemplate& TemplateID, double MaxError, const wchar_t* SubPixel, Hlong NumLevels, Hlong WhichLevels, double* Row, double* Column, double* Error) const   ( Windows only)

static void HOperatorSet.BestMatchMg(HObject image, HTuple templateID, HTuple maxError, HTuple subPixel, HTuple numLevels, HTuple whichLevels, out HTuple row, out HTuple column, out HTuple error)

void HTemplate.BestMatchMg(HImage image, double maxError, string subPixel, int numLevels, HTuple whichLevels, out double row, out double column, out double error)

void HTemplate.BestMatchMg(HImage image, double maxError, string subPixel, int numLevels, int whichLevels, out double row, out double column, out double error)

void HImage.BestMatchMg(HTemplate templateID, double maxError, string subPixel, int numLevels, HTuple whichLevels, out double row, out double column, out double error)

void HImage.BestMatchMg(HTemplate templateID, double maxError, string subPixel, int numLevels, int whichLevels, out double row, out double column, out double error)

def best_match_mg(image: HObject, template_id: HHandle, max_error: float, sub_pixel: str, num_levels: int, which_levels: Union[str, int]) -> Tuple[float, float, float]

描述

best_match_mgbest_match_mgBestMatchMgBestMatchMgBestMatchMgbest_match_mg 采用图像金字塔实现灰度值匹配。best_match_mgbest_match_mgBestMatchMgBestMatchMgBestMatchMgbest_match_mg 工作原理与 best_matchbest_matchBestMatchBestMatchBestMatchbest_match 类似,但因使用金字塔结构而运行速度更快。输入是一张具有可选缩小域的图像。模板仅在图像域中那些完全包含模型的点内进行搜索。这意味着若模型超出图像边界,则无法被检索到。参数 MaxErrorMaxErrorMaxErrorMaxErrormaxErrormax_error 指定模板匹配的最大误差值。使用较小的值可缩短运行时间,但可能导致模式匹配失败。MaxErrorMaxErrorMaxErrorMaxErrormaxErrormax_error 需设置得比 best_matchbest_matchBestMatchBestMatchBestMatchbest_match 更大,因为金字塔更高层级的误差通常更大。

SubPixelSubPixelSubPixelSubPixelsubPixelsub_pixel 参数用于指定计算结果是否采用亚像素精度。当 NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels 值设为 1 时,算子将类似于 best_matchbest_matchBestMatchBestMatchBestMatchbest_match 算子,即仅使用原始灰度值进行计算。对于大于 1 的值,算法从最低分辨率开始,寻找匹配误差最小的位置。在下一级更高分辨率下,该位置将得到精确定位。此过程将持续进行直至达到最高分辨率(即 WhichLevelsWhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels = 'all'"all""all""all""all""all")。作为替代方案,可使用模式 WhichLevelsWhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels 并设置其值为 'original'"original""original""original""original""original"。在此情况下,不仅会分析误差最小的位置,所有低于 MaxErrorMaxErrorMaxErrorMaxErrormaxErrormax_error 的点都会在更高分辨率下进行进一步分析。该方法虽然速度较慢,但稳定性更高,且漏检正确位置的可能性极低。在这种情况下,通常可以从较低的分辨率开始(即金字塔中的更高层级,也就是 NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels 参数取更大值),从而缩短运行时间。除了 WhichLevelsWhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels'all'"all""all""all""all""all"'original'"original""original""original""original""original" 值外,您还可以明确指定金字塔层级,在该层级上切换 “match all” 匹配所有和 “best match” 最佳匹配。此处 0 对应 'original'"original""original""original""original""original" 状态,NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels - 1 等同于 'all'"all""all""all""all""all"。中间值通常能在速度与稳定检测之间取得良好平衡。WhichLevelsWhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels 值越大,运行时间越短;数值越小,检测结果越稳定。NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels 的值必须等于或小于创建模板时使用的数值。

匹配位置的坐标以 RowRowRowRowrowrowColumnColumnColumnColumncolumncolumn 形式返回。对应的误差值存储在 ErrorErrorErrorErrorerrorerror。若未找到低于 MaxErrorMaxErrorMaxErrorMaxErrormaxErrormax_error 的点,则返回 ErrorErrorErrorErrorerrorerror = 255RowRowRowRowrowrowColumnColumnColumnColumncolumncolumn 等于 0。若目标对象未被识别(未找到对象或位置错误),需提高 MaxErrorMaxErrorMaxErrorMaxErrormaxErrormax_error 或降低 WhichLevelsWhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels 参数。同时检查照明条件是否发生变化(参见 set_offset_templateset_offset_templateSetOffsetTemplateSetOffsetTemplateSetOffsetTemplateset_offset_template)。

位置的最大误差(无噪声)为 0.1 像素。 平均误差为 0.03 像素。

执行信息

参数

ImageImageImageImageimageimage (输入对象)  singlechannelimage(-array) objectHImageHObjectHImageHobject (byte)

需要在其中查找模式的输入图像。

TemplateIDTemplateIDTemplateIDTemplateIDtemplateIDtemplate_id (输入控制)  template HTemplate, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

模板编号。

MaxErrorMaxErrorMaxErrorMaxErrormaxErrormax_error (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

灰度值的最大平均差值。

默认值: 30.0

建议值: 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 11.0, 15.0, 17.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0

值范围: 0 ≤ MaxError MaxError MaxError MaxError maxError max_error ≤ 255

最小增量: 1

建议增量: 3

SubPixelSubPixelSubPixelSubPixelsubPixelsub_pixel (输入控制)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

当为 'true'"true""true""true""true""true" 时,精确到亚像素。

默认值: 'false' "false" "false" "false" "false" "false"

值列表: 'false'"false""false""false""false""false", 'true'"true""true""true""true""true"

NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

使用的分辨率级别数量。

默认值: 4

建议值: 1, 2, 3, 4, 5, 6

WhichLevelsWhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels (输入控制)  integer HTupleUnion[str, int]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)

使用“最佳匹配”方法的分辨率上限。

默认值: 2

建议值: 'all'"all""all""all""all""all", 'original'"original""original""original""original""original", 0, 1, 2, 3, 4, 5, 6

RowRowRowRowrowrow (输出控制)  point.y HTuplefloatHTupleHtuple (real) (double) (double) (double)

最佳匹配的行位置。

ColumnColumnColumnColumncolumncolumn (输出控制)  point.x HTuplefloatHTupleHtuple (real) (double) (double) (double)

最佳匹配的列位置。

ErrorErrorErrorErrorerrorerror (输出控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

最佳匹配的灰度值平均差异。

结果

如果参数值正确,算子 best_match_mgbest_match_mgBestMatchMgBestMatchMgBestMatchMgbest_match_mg 返回值 2 ( H_MSG_TRUE )。当输入为空(没有可用输入图像)时,可设置行为通过算子 set_system('no_object_result',<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>)set_system("no_object_result",<Result>)。如有必要,则抛出异常。

可能的前趋

create_templatecreate_templateCreateTemplateCreateTemplateCreateTemplatecreate_template, read_templateread_templateReadTemplateReadTemplateReadTemplateread_template, adapt_templateadapt_templateAdaptTemplateAdaptTemplateAdaptTemplateadapt_template, draw_regiondraw_regionDrawRegionDrawRegionDrawRegiondraw_region, draw_rectangle1draw_rectangle1DrawRectangle1DrawRectangle1DrawRectangle1draw_rectangle1, reduce_domainreduce_domainReduceDomainReduceDomainReduceDomainreduce_domain, set_reference_templateset_reference_templateSetReferenceTemplateSetReferenceTemplateSetReferenceTemplateset_reference_template, set_offset_templateset_offset_templateSetOffsetTemplateSetOffsetTemplateSetOffsetTemplateset_offset_template

替代

fast_matchfast_matchFastMatchFastMatchFastMatchfast_match, fast_match_mgfast_match_mgFastMatchMgFastMatchMgFastMatchMgfast_match_mg, best_matchbest_matchBestMatchBestMatchBestMatchbest_match, best_match_pre_mgbest_match_pre_mgBestMatchPreMgBestMatchPreMgBestMatchPreMgbest_match_pre_mg, best_match_rotbest_match_rotBestMatchRotBestMatchRotBestMatchRotbest_match_rot, best_match_rot_mgbest_match_rot_mgBestMatchRotMgBestMatchRotMgBestMatchRotMgbest_match_rot_mg, exhaustive_matchexhaustive_matchExhaustiveMatchExhaustiveMatchExhaustiveMatchexhaustive_match, exhaustive_match_mgexhaustive_match_mgExhaustiveMatchMgExhaustiveMatchMgExhaustiveMatchMgexhaustive_match_mg

模块

匹配