HALCON: Optimising Speed when using Shape-based Matching

HALCON’s pattern matching functions come with default settings that do the job for the vast majority of applications. This makes them easy-to-use. Sometimes, however, an object may evade detection or the performance may not be sufficient. In either case, some understanding of the internal parameters of these operators may help you achieve your performance objectives.

What should you do, for example, if the object is not being found? All pattern matching functions in HALCON provide a parameter to set the so-called minimum score or degree of similarity that is required for a valid match. If a model cannot be found, this generally means you have to lower the minimum score. Lowering the minimum score, however, also increases the run time and may lead to false positives. Another way to correct for missing matches is to check whether they are found on a higher pyramid level (to speed up detection HALCON looks for matches on multiple scales or pyramid levels). To return matches regardless of the pyramid level on which they are found, set the parameter NumLevels of  the operator find_shape_model to [0,-1]. This may help recover matches that are lost due to image blur or background texture that dominates at the full image resolution. If a match is not found, you can also try setting the parameter “Greediness” to 0. A smaller value means that HALCON performs a more conservative search increasing the likelihood that objects with a score close to the minimum score are being found. You will pay for that with an increase in run time.

If your application finds all objects but needs a performance boost, you can define a region of interest on the search image (with reduce_domain per usual). The only requirement is that the so called model reference point (center of the domain of the model image) is within the ROI.

The Pyramid level setting has a huge influence on the run time of a matching operator. Stepping up one layer in the pyramid means dividing the number of pixels by 4. Typically HALCON will use somewhere between 5 and 7 pyramid levels. The most time consuming task is typically the exhaustive search on the topmost pyramid level, although this depends, for example, on the size of the search space and number of candidates identified during the search. So the higher the pyramid level (few pixels in the search domain) the faster the search. For optimal performance, you should always remember to limit the search space (angle and scale range) as much as the application permits. It is also possible to search within 2 disjunct regions by using multiple models (use find_shape_models instead of find_shape_model).

Do you find this useful? Please contact us if require any further help with HALCON.