Creating a Template
A template is a small picture of the part you want to find. This operation cuts one out of a live camera image and saves it, so the template comes from the real camera in the real lighting.
The operation belongs to the whole application, not to a module, so it sits on the system node:
hdvisionsystems/lumiscan-template-finder/system/create-template/
Inputs
| Node | Type | Default | Description |
|---|---|---|---|
|
string |
(empty) |
Data Layer address of the image to cut from. Required |
|
int32 |
|
Left edge of the region, in pixels from the left of the image |
|
int32 |
|
Top edge of the region, in pixels from the top of the image |
|
int32 |
|
Width of the region in pixels. Must be greater than 0 |
|
int32 |
|
Height of the region in pixels. Must be greater than 0 |
|
string |
(empty) |
Name to save under. |
The template is written into system/template-dir, which the whole application shares, so it is
usable by every module as soon as it is saved.
Outputs
| Node | Type | Description |
|---|---|---|
|
string |
Path of the written file, relative to the configuration directory |
|
int16 |
Execution status |
|
string |
The same outcome in words |
output/template-path is split the way the search expects it: templates/screw.png means set the
search’s template directory to templates and its template name to screw.png.
Procedure
-
Make sure the camera application has captured an image.
-
Set
input/input-image-address. -
Set the four
input/crop/values to the region containing the part. -
Set
input/template-name. -
Write to
system/create-template/execute. -
Read
output/status-code. On1,output/template-pathnames the new template.
|
Immediately search the same image for the template you just cut. It must be found at exactly the centre of the region you specified, with a confidence near 1. If it is not, the problem is the region or the image source - not the search parameters. This takes a few seconds and saves a lot of guessing later. |
Choosing a good region
- Include what identifies the part, exclude what varies
-
Background that changes from part to part lowers every score.
- Keep it small, but distinctive
-
Matching cost grows with template area. A small, high-contrast feature is both faster and more reliable than the whole part.
- Stay away from the image border
-
A template that touches the edge of the image cannot be found near the opposite edge, because the template must fit entirely inside the searched image.
- Think about binning
-
If the search will run with binning, the template must still be recognisable after downsampling. At a bin size of 4, a feature 20 pixels wide becomes 5.
Written file
The region is written as a standard 8-bit RGB PNG, whatever the camera’s pixel format - Bayer images are converted to colour and 12-bit images scaled down first.
The destination directory is created if it does not exist.
|
An existing file with the same name is overwritten without warning. Use a new template name if you want to keep the old one. |