Tuning the Search
All of these are inputs of find-template. The defaults search the template at its original size
and orientation, which is the fastest configuration and the right starting point.
Search range
| Node | Type | Default | Description |
|---|---|---|---|
|
double |
|
Smallest template scaling factor. Must be greater than 0 |
|
double |
|
Largest template scaling factor |
|
double |
|
Increment between the scales searched |
|
double |
|
Smallest rotation in degrees, 0 to 360 |
|
double |
|
Largest rotation in degrees, 0 to 360 |
|
double |
|
Increment between the rotations searched. Must be greater than 0 |
Setting the minimum equal to the maximum searches that single value and ignores the step.
|
The work is one pass per combination. Searching 5 scales and 36 rotations is 180 passes over the image, not 41. Widen a range only as far as the parts actually vary, and prefer a coarse step: a rotation step of 5 degrees usually locates a part well enough for a follow-up measurement. |
Matching
| Node | Type | Default | Description |
|---|---|---|---|
|
double |
|
Minimum acceptable score, 0 to 1 |
|
string |
|
Matching algorithm |
|
bool |
|
Match on grayscale when the images have colour |
match-mode accepts TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF and
TM_CCOEFF_NORMED. Scores from different modes are not comparable, which is why the mode used is
included in the result.
use-grayscale makes matching roughly three times faster by not correlating each colour channel
separately, and costs little accuracy in most industrial scenes. Turn it off when colour is what
distinguishes the part.
Understanding the confidence
The confidence is not an absolute measure of similarity. The score map is rescaled once for every scale/rotation step, which has two consequences worth knowing:
-
The best location of every step reaches a confidence near 1, even when that step’s scale fits nothing in the image.
-
match-threshtherefore acts per step rather than globally, as soon as you search a range.
A single-scale, single-rotation search behaves as you would expect. A wide search can report weak matches at unrelated places alongside the real one. The true match is still the highest-confidence entry, at index 0.
If you see spurious matches, raise match-thresh or narrow the range.
The application also removes duplicates: without that, a search over 10 steps would report the same part up to 10 times. Only repeats at the same location are removed, which is why a weak match somewhere else can still appear.
Pre-processing
| Node | Type | Default | Description |
|---|---|---|---|
|
double |
|
Gaussian blur strength in X. 0 or less turns blurring off |
|
double |
|
Blur strength in Y. 0 means the same as X |
|
uint32 |
|
Blur kernel width. 0 derives it from the blur strength; otherwise an odd number |
|
uint32 |
|
Blur kernel height. 0 derives it from the blur strength; otherwise an odd number |
|
int32 |
|
Shrink both images by this factor before matching. 1 turns it off |
Blurring suppresses sensor noise, at the cost of some positional precision. The default is a mild blur that suits most cameras.
Binning is the most effective speed control: matching cost falls with the square of the factor, so a bin size of 2 is roughly four times faster. The limit is the template - once a distinguishing feature shrinks below a few pixels it stops being distinguishable. Small or thin templates should stay at 1.
A practical order
-
Start at the defaults and search for a template cut from the same setup. Confirm it is found.
-
If the parts vary in orientation, widen the rotation range with a coarse step.
-
If they vary in distance, widen the scale range.
-
If it is too slow, raise
bin-sizeto 2 and check the confidence is still acceptable. -
If spurious matches appear, raise
match-thresh.