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

input/input-image-address

string

(empty)

Data Layer address of the image to cut from. Required

input/crop/startX

int32

0

Left edge of the region, in pixels from the left of the image

input/crop/startY

int32

0

Top edge of the region, in pixels from the top of the image

input/crop/width

int32

0

Width of the region in pixels. Must be greater than 0

input/crop/height

int32

0

Height of the region in pixels. Must be greater than 0

input/template-name

string

(empty)

Name to save under. .png is added if you give no extension. Use a lower case name: only lower case .png files appear on system/templates. Required

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

output/template-path

string

Path of the written file, relative to the configuration directory

output/status-code

int16

Execution status

output/status-text

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

  1. Make sure the camera application has captured an image.

  2. Set input/input-image-address.

  3. Set the four input/crop/ values to the region containing the part.

  4. Set input/template-name.

  5. Write to system/create-template/execute.

  6. Read output/status-code. On 1, output/template-path names 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.