best_match_mgT_best_match_mgBestMatchMgBestMatchMgbest_match_mg (Operator)

Name

best_match_mgT_best_match_mgBestMatchMgBestMatchMgbest_match_mg — Searching the best gray value matches in a pyramid.

Warning

best_match_mgbest_match_mgBestMatchMgBestMatchMgbest_match_mg is obsolete and is only provided for reasons of backward compatibility. The operator will be removed with HALCON 25.11. New applications should use the shape-based or NCC-based operators instead.

Signature

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]

Description

best_match_mgbest_match_mgBestMatchMgBestMatchMgbest_match_mg applies gray value matching using an image pyramid. best_match_mgbest_match_mgBestMatchMgBestMatchMgbest_match_mg works analogously to best_matchbest_matchBestMatchBestMatchbest_match, but it is faster due to the use of a pyramid. Input is an image with an optionally reduced domain. The template is searched within those points of the domain of the image, in which the model lies completely within the image. This means that the model will not be found if it extends beyond the borders of the image. The parameter MaxErrorMaxErrorMaxErrormaxErrormax_error specifies the maximum error for template matching. Using smaller values results in a reduced runtime but it is possible that the pattern might be missed. The value of MaxErrorMaxErrorMaxErrormaxErrormax_error has to be chosen larger compared with best_matchbest_matchBestMatchBestMatchbest_match, because the error at higher levels of the pyramid is often larger.

SubPixelSubPixelSubPixelsubPixelsub_pixel specifies if the result is calculated with sub pixel accuracy or not. A value of 1 for NumLevelsNumLevelsNumLevelsnumLevelsnum_levels results in an operator similar to best_matchbest_matchBestMatchBestMatchbest_match, i.e. only the original gray values are used. For values larger than 1, the algorithm starts at the lowest resolution and searches for a position with the lowest matching error. At the next higher resolution this position is refined. This is continued up to the maximum resolution (WhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels = 'all'"all""all""all""all"). As an alternative Method the mode WhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels with value 'original'"original""original""original""original" can be used. In this case not only the position with the lowest error but all points below MaxErrorMaxErrorMaxErrormaxErrormax_error are analyzed further on in the next higher resolution. This method is slower but it is more stable and the possibility to miss the correct position is very low. In this case it is often possible to start with a lower resolution (higher level in Pyramid, i.e. larger value for NumLevelsNumLevelsNumLevelsnumLevelsnum_levels) which leads to a reduced runtime. Besides the values 'all'"all""all""all""all" and 'original'"original""original""original""original" for WhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels you can specify the pyramid level explicitly where to switch between a “match all” and the ”best match”. Here 0 corresponds to 'original'"original""original""original""original" and NumLevelsNumLevelsNumLevelsnumLevelsnum_levels - 1 is equivalent to 'all'"all""all""all""all". A value in-between is in most cases a good compromise between speed and a stable detection. A larger value for WhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels results in a reduced runtime, a smaller value results in a more stable detection. The value of NumLevelsNumLevelsNumLevelsnumLevelsnum_levels has to be equal or smaller than the value used to create the template.

The position of the found matching position is returned in RowRowRowrowrow and ColumnColumnColumncolumncolumn. The corresponding error is given in ErrorErrorErrorerrorerror. If no point below MaxErrorMaxErrorMaxErrormaxErrormax_error is found a value of 255 for ErrorErrorErrorerrorerror and 0 for RowRowRowrowrow and ColumnColumnColumncolumncolumn is returned. If the desired object is missed (no object found or wrong position) you have to set MaxErrorMaxErrorMaxErrormaxErrormax_error higher or WhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels lower. Check also if the illumination has changed (see set_offset_templateset_offset_templateSetOffsetTemplateSetOffsetTemplateset_offset_template).

The maximum error of the position (without noise) is 0.1 pixel. The average error is 0.03 pixel.

Execution Information

Parameters

ImageImageImageimageimage (input_object)  singlechannelimage(-array) objectHImageHObjectHObjectHobject (byte)

Input image inside of which the pattern has to be found.

TemplateIDTemplateIDTemplateIDtemplateIDtemplate_id (input_control)  template HTemplate, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Template number.

MaxErrorMaxErrorMaxErrormaxErrormax_error (input_control)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

Maximal average difference of the gray values.

Default: 30.0

Suggested values: 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

Value range: 0 ≤ MaxError MaxError MaxError maxError max_error ≤ 255

Minimum increment: 1

Recommended increment: 3

SubPixelSubPixelSubPixelsubPixelsub_pixel (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Exactness in subpixels in case of 'true'"true""true""true""true".

Default: 'false' "false" "false" "false" "false"

List of values: 'false'"false""false""false""false", 'true'"true""true""true""true"

NumLevelsNumLevelsNumLevelsnumLevelsnum_levels (input_control)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Number of the used resolution levels.

Default: 4

Suggested values: 1, 2, 3, 4, 5, 6

WhichLevelsWhichLevelsWhichLevelswhichLevelswhich_levels (input_control)  integer HTupleUnion[str, int]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)

Resolution level up to which the method “best match” is used.

Default: 2

Suggested values: 'all'"all""all""all""all", 'original'"original""original""original""original", 0, 1, 2, 3, 4, 5, 6

RowRowRowrowrow (output_control)  point.y HTuplefloatHTupleHtuple (real) (double) (double) (double)

Row position of the best match.

ColumnColumnColumncolumncolumn (output_control)  point.x HTuplefloatHTupleHtuple (real) (double) (double) (double)

Column position of the best match.

ErrorErrorErrorerrorerror (output_control)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

Average divergence of the gray values in the best match.

Result

If the parameter values are correct, the operator best_match_mgbest_match_mgBestMatchMgBestMatchMgbest_match_mg returns the value 2 ( H_MSG_TRUE) . If the input is empty (no input images are available) the behavior can be set via set_system('no_object_result',<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>)set_system("no_object_result",<Result>). If necessary, an exception is raised.

Possible Predecessors

create_templatecreate_templateCreateTemplateCreateTemplatecreate_template, read_templateread_templateReadTemplateReadTemplateread_template, adapt_templateadapt_templateAdaptTemplateAdaptTemplateadapt_template, draw_regiondraw_regionDrawRegionDrawRegiondraw_region, draw_rectangle1draw_rectangle1DrawRectangle1DrawRectangle1draw_rectangle1, reduce_domainreduce_domainReduceDomainReduceDomainreduce_domain, set_reference_templateset_reference_templateSetReferenceTemplateSetReferenceTemplateset_reference_template, set_offset_templateset_offset_templateSetOffsetTemplateSetOffsetTemplateset_offset_template

Alternatives

fast_matchfast_matchFastMatchFastMatchfast_match, fast_match_mgfast_match_mgFastMatchMgFastMatchMgfast_match_mg, best_matchbest_matchBestMatchBestMatchbest_match, best_match_pre_mgbest_match_pre_mgBestMatchPreMgBestMatchPreMgbest_match_pre_mg, best_match_rotbest_match_rotBestMatchRotBestMatchRotbest_match_rot, best_match_rot_mgbest_match_rot_mgBestMatchRotMgBestMatchRotMgbest_match_rot_mg, exhaustive_matchexhaustive_matchExhaustiveMatchExhaustiveMatchexhaustive_match, exhaustive_match_mgexhaustive_match_mgExhaustiveMatchMgExhaustiveMatchMgexhaustive_match_mg

Module

Matching