Finding a Template
Searches a live camera image for a stored template and reports every occurrence found.
Address, relative to the module:
find-template/
Inputs
The two required values are the image to search and the template to look for. Everything else has a working default; the parameters that control the search itself are described in Tuning the Search.
| Node | Type | Default | Description |
|---|---|---|---|
|
string |
(empty) |
Data Layer address of the image to search. Required |
|
string |
(empty) |
Template to search for, as listed on |
The directory it is read from is system/template-dir, which the whole application shares - see
Template Storage.
Outputs
| Node | Type | Description |
|---|---|---|
|
flatbuffer |
The matches found, sorted by confidence |
|
int16 |
Execution status |
|
string |
The same outcome in words |
The result
output/result is a hdv.template_match.Result flatbuffer:
| Field | Type | Description |
|---|---|---|
|
array |
One entry per occurrence found, sorted by confidence, highest first |
|
ulong |
Index of the best match. Always |
|
float |
Confidence of the best match, or |
|
string |
The template used for this run |
|
string |
The matching algorithm used |
|
float |
The threshold applied |
|
uint |
Size of the searched image, so coordinates can be normalised |
|
ulong |
Microseconds since the epoch, taken when the search finished |
Each entry in matches contains:
| Field | Type | Description |
|---|---|---|
|
struct |
|
|
float |
Match score between 0 and 1 |
|
float |
The template scaling factor this match was found at |
|
float |
The template rotation this match was found at, in degrees |
|
An empty |
Procedure
-
Set
input/input-image-addressandinput/template-name. -
Adjust the search parameters if the defaults do not fit - see Tuning the Search.
-
Write to
find-template/execute. -
Read
output/status-code.1means the search ran. -
Read
output/resultfor the matches, oroutput/status-textif the status code was negative.
Once the inputs are set they keep their values, so a repeated search is a single write to execute.
Common failures
Failures are described step by step in Troubleshooting:
Searching only part of the image
input/crop/ limits the search to a rectangle - faster, and it avoids matching a part that happens to
appear elsewhere in the frame. All four values are uint16.
A zero width or height means "as far as the image goes" on that axis:
| Setting | Region searched |
|---|---|
all four zero (the default) |
the whole image |
|
from (100, 50) to the bottom-right corner |
|
a 200 pixel band reaching the right edge |
A region reaching past an edge is refused, not trimmed - searching a smaller area than asked for
would show up much later as matches that are simply missing. The reason names the input and the
limit it broke, for example
crop/startX + crop/width (100 + 541 = 641) exceeds the image width 640. A region smaller than the
template is refused too, with status -5.
Which image the positions refer to
input/result-coordinate decides what the positions in output/result are measured against:
| Value | Meaning |
|---|---|
|
The full image at |
|
The searched region, whose top left corner is (0,0) |
It changes only how the result is reported, never what is found. image_width and image_height in
the result follow the same choice.
What a failed search leaves behind
The matches are cleared before the search starts, so a run that fails for any reason leaves
output/result empty rather than holding the hits from an earlier image. Reading the result without
checking output/status-code therefore shows nothing, not a stale match.
Status -1 (busy) is the exception: that call never ran, so it leaves the result of the search that
is in progress alone.
Searching every frame of a camera
find-template searches one image per call. To have a module search every frame a camera streams,
with the same inputs, see
Finding Templates on an Image Stream (Experimental).