F_VN_TrainImageColorExp

F_VN_TrainImageColorExp 1:

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 : HRESULT
VAR_INPUT
    ipSrcImage       : ITcVnImage;
    ipColorModel     : Reference To ITcVnColorModel;
    nDifferentColors : UDINT;
    eMethod          : ETcVnColorTrainingMethod;
    ipMask           : ITcVnImage;
    nSkipPixels      : UDINT;
    hrPrev           : HRESULT;
END_VAR

F_VN_TrainImageColorExp 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (3 channels (RGB) of type USINT)

ipColorModel

Reference To ITcVnColorModel

Returns the color model

nDifferentColors

UDINT

Number of different colors to distinguish

eMethod

ETcVnColorTrainingMethod

Color training method

ipMask

ITcVnImage

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

HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.)

F_VN_TrainImageColorExp 3: Return value

HRESULT

Further information

The function F_VN_TrainImageColorExp is the expert version of F_VN_TrainImageColor. It contains further parameters. If the trained color model is to be saved to disk, the F_VN_TrainImageColorExp_ITcVnMlModel with the type ITcVnMlModel must be used.

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 the type ITcVnColorModel.

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.

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    :   ITcVnColorModel;
END_VAR

hr := F_VN_TrainImageColor(
            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:

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