| Customize Help
| Save Settings

MbeadTrain



Function Map
Synopsis
Train the templates in a bead context.
Syntax
void MbeadTrain(
MIL_ID ContextBeadId, //in
MIL_ID TrainingImageBufId, //in
MIL_INT64 ControlFlag //in
)
Description

This function trains the templates for a verification operation and sets internal processing settings to optimize future calculations for speed and robustness. This function can also internally save or free a training image (TrainingImageBufId).

You must call this function before your first call to MbeadVerify(). Certain modifications to a bead context, such as adding, deleting, or modifying templates with MbeadTemplate(), or changing some control settings with MbeadControl(), require you to retrain the templates before any subsequent call to MbeadVerify().

To inquire the training status of the templates in the context, use MbeadInquire() with M_STATUS. Typically you should not call MbeadVerify() until all the templates in the context have been completely trained. You might have to modify your settings and retrain the templates more than once before you can perform a successful verification. To draw the templates in the context (trained or untrained), use MbeadDraw().

To train the templates, MIL must establish their trained points, which are based on the most current settings, such as the spacing between the expected position of the trained points, the template's path (polyline, circle, or segment), and width. To train the templates, MIL also uses the training image, if it is required by the template's settings.

By default, you must use a training image, since the default path a template follows is a polyline that is refined by the training image (MbeadControl() with M_TRAINING_PATH set to M_DEFAULT or M_POLYLINE_SEED). If a template follows a path that is a fixed polyline, circle, or segment (M_POLYLINE, M_CIRCLE, or M_SEGMENT), the path's position will not be refined, even if you specify a training image. Similarly, MIL uses the training image by default to establish the width of the template's path (MbeadControl() with M_WIDTH_NOMINAL_MODE set to M_DEFAULT or M_AUTO_...). If the nominal width is explicitly set, a training image is not required and is ignored if provided.

If you have associated the training image with a camera calibration context, you can specify that certain input settings for the training phase be interpreted in world units. To do so, use MbeadControl() with M_TEMPLATE_INPUT_UNITS and/or M_TRAINING_BOX_INPUT_UNITS set to M_WORLD. To use a calibrated training image, you can either pass one to this function, or you can specify the camera calibration context to associate to the training image, using MbeadControl() with M_ASSOCIATED_CALIBRATION. If both camera calibrations are available, MIL ignores the camera calibration set with M_ASSOCIATED_CALIBRATION. Note that if MIL is interpreting input settings for the training phase in world units, but you don't use a calibrated training image, MbeadTrain() will generate an error.

If you are specifying pixel units, make sure the pixel sizes are consistent across all camera calibrations (for example, pixel sizes should be the same in the training and verification images). When using different camera calibration contexts, it is recommended that you use world units.

Note that this function reference has not been updated for a MIL system added during a MIL update. Refer to the MIL system's release note to see which MIL system’s documentation you should use in its place and any possible differences.
Parameters
This function is not supported on the selected boards.
This function reference has not been updated for the selected MIL system. To show the content of this page, choose a second MIL system; refer to the MIL system's release note to see which MIL system’s documentation to choose and any possible differences.
Parameters
ContextBeadId

Specifies the identifier of the bead context that contains the templates to train. The bead context must have been previously allocated on the required system using MbeadAlloc().

TrainingImageBufId

Specifies the identifier of the image buffer containing the training image with which to train the templates, or specifies to train the templates without a training image (or with a previously saved training image).

This parameter should be set to one of the following values:

function map For specifying the source
Click to summarizeValue Description
Click to summarize M_NULL

Specifies no training image will be used to train the templates, unless a training image has been previously saved. In this case, MIL uses the saved training image (M_SAVE_TRAINING_IMAGE) to train the templates even if you specify M_NULL.

(summarize)
Click to summarize Image buffer identifier

Specifies the identifier of an image buffer containing the training image MIL will use to train the templates. The image buffer must be a 1-band 8-bit unsigned buffer. All templates in the context use the same training image.

If a training image has been internally saved (M_SAVE_TRAINING_IMAGE), it will be freed from memory and the newly specified image will be used to train the templates.

This image buffer must not have a region of interest (ROI) associated with it. Using an image buffer with an ROI will cause an error.

To train the templates, MIL extracts beads from the training image using processes based on the MIL Measurement module. Such processes use a one-dimensional analysis of differences in pixel intensities. For more information about this type of edge extraction, see the Search algorithm section of Chapter 16: Measurement.

(summarize)
ControlFlag

Specifies whether to save the training image (TrainingImageBufId). This parameter should be set to one of the following values:

function map For specifying whether to internally save the training image
Click to summarizeValue Description
Click to summarize M_DEFAULT

Specifies that the training image will not be saved. If a training image has been previously saved in the context, it will be freed and any memory associated with it will be released.

(summarize)
Click to summarize M_SAVE_TRAINING_IMAGE

Specifies that the bead context will store a copy of the training image.

Compilation information
Header Include mil.h.
Library Use mil.lib; milbead.lib.
DLL Requires mil.dll; milbead.dll.
NULL UNSIGNED PROC NONE DEFAULT SAVE TRAINING IMAGE