F_VN_TrainImageColorExp_ITcVnMlModel
Create a new color model, describing the image color. (expert function)
Can use available TwinCAT Job Tasks for executing parallel code regions.
Can return partial results when canceled by Watchdog.
Syntax
Definition:
FUNCTION F_VN_TrainImageColorExp_ITcVnMlModel : HRESULT
VAR_INPUT
ipSrcImage : ITcVnImage;
ipColorModel : Reference To ITcVnMlModel;
nDifferentColors : UDINT;
eMethod : ETcVnColorTrainingMethod;
ipMask : ITcVnImage;
nSkipPixels : UDINT;
hrPrev : HRESULT;
END_VAR
Inputs
Name |
Type |
Description |
---|---|---|
ipSrcImage |
Source image (3 channels (RGB) of type USINT) | |
ipColorModel |
Reference To ITcVnMlModel |
Returns the color model |
nDifferentColors |
UDINT |
Number of different colors to distinguish |
eMethod |
Color training method | |
ipMask |
Optional image mask (1 channel of type USINT, set to 0 if not required) | |
nSkipPixels |
UDINT |
Number of pixels to skip between each evaluated color sample (to achieve a better performance). 0 takes every pixel into account and tends to be more accurate. |
hrPrev |
HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
Further information
The function F_VN_TrainImageColorExp_ITcVnMlModel
is the expert version of F_VN_TrainImageColor_ITcVnMlModel. It contains further parameters. The color model can be saved and loaded on the hard disk with the corresponding function blocks.
Parameter
Reference image
The reference image ipSrcImage
must have 3 channels in RGB format and the element type USINT
(8-bit).
Color model
The parameter ipColorModel
returns the trained color model. This is an interface pointer of type ITcVnMlModel.
Number of colors to be distinguished
The number nDifferentColors
defines the number of colors to be trained. Note that the image background, for example, can also have its own color.
Expert parameters
Additional parameters can be found in another expert version F_VN_TrainImageColorExp2_ITcVnMlModel.
Training methods
When selecting the training method, the LAB and RGB color spaces are available.
Mask
The mask ipMask
defines which pixels of the input image ipSrcImage
are taken into account in the calculation. It is described by a 1-channel image with the element type USINT, which has the same size as the input image ipSrcImage
. All pixels in the mask image with a value <> 0 are taken into account in the calculation of the cluster.
Pixel gap
For performance optimization, a number of pixels can be skipped so that fewer pixels need to be considered when dividing into the individual clusters.
Application
VAR
ipColorModel : ITcVnMlModel;
END_VAR
hr := F_VN_TrainImageColorExp_ITcVnMlModel (
ipSrcImage := ipImageRef,
ipColorModel := ipColorModel,
nDifferentColors:= 5, // 4 colors + 1 background = 5
eMethod := TCVN_CTM_LAB,
ipMask := 0,
nSkipPixels := 3,
hrPrev := hr);
Related functions
There are three ways to pass the reference color to the corresponding F_VN_ReferenceColorSimilarity
function:
- As a trained color model of the type
ITcVnColorModel
- As a trained color model of the type
ITcVnMlModel
- Directly with values in a
TcVnVector3_LREAL
For the color models there are corresponding functions for training and for all three data types one function each for execution:
- F_VN_TrainImageColor for the training of a color model
- F_VN_ReferenceColorSimilarity for segmentation by means of a color model
Required License
TC3 Vision Base
System Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT V3.1.4024.54 or later | PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU | Tc3_Vision |