F_VN_TrainImageColor

F_VN_TrainImageColor 1:

Create a new color model, describing the image color.
Can use available TwinCAT Job Tasks for executing parallel code regions.
Can return partial results when canceled by Watchdog.

Syntax

Definition:

FUNCTION F_VN_TrainImageColor : HRESULT
VAR_INPUT
    ipSrcImage       : ITcVnImage;
    ipColorModel     : Reference To ITcVnColorModel;
    nDifferentColors : UDINT;
    hrPrev           : HRESULT;
END_VAR

F_VN_TrainImageColor 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

hrPrev

HRESULT

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

F_VN_TrainImageColor 3: Return value

HRESULT

Further information

The function F_VN_TrainImageColor trains a color model on the basis of a reference image. If the trained color model is to be saved to disk, the F_VN_TrainImageColor_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

Further parameters can be found in the expert version F_VN_TrainImageColorExp.

Application

The training of a color model for a reference image with 4 differently colored objects and a dark background looks like this, for example:

VAR
    ipColorModel    :   ITcVnColorModel;
END_VAR

hr := F_VN_TrainImageColor(
            ipSrcImage      := ipImageRef,
            ipColorModel    := ipColorModel,
            nDifferentColors:= 5, // 4 colors + 1 background = 5
            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