TrainImageColor

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:

HRESULT TrainImageColor(
    HRESULT                  hrPrev,
    ITcVnImage*              ipSrcImage,
    ITcVnColorModel*&        ipColorModel,
    ULONG                    nDifferentColors,
    ETcVnColorTrainingMethod eMethod = CTM_LAB,
    ITcVnImage*              ipMask = nullptr,
    ULONG                    nSkipPixels = 0,
    ETcVnClusteringAlgorithm eClusteringAlgorithm = CA_KMEANSPP,
    LONG                     nMaxClusterRadius = 50,
    bool                     bSingleSplitSteps = true
)

Parameters

Name

Type

Default

Description

hrPrev

HRESULT

 

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

ipSrcImage

ITcVnImage*

 

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

ipColorModel

ITcVnColorModel*&

 

Returns the color model

nDifferentColors

ULONG

 

Maximum number of different colors to distinguish (if LBG is used as a clustering algorithm, the result might have less different colors, depending on nMaxClusterRadius)

eMethod

ETcVnColorTrainingMethod

CTM_LAB

Color training method

ipMask

ITcVnImage*

nullptr

Optional image mask (1 channel of type USINT, set to 0 if not required)

nSkipPixels

ULONG

0

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.

eClusteringAlgorithm

ETcVnClusteringAlgorithm

CA_KMEANSPP

Clustering algorithm

nMaxClusterRadius

LONG

50

Only used for the LBG clustering algorithm. Maximum allowed radius (> 0) of a single cluster, i.e. clusters with a higher radius will be split into smaller ones, until a global number of nDifferentColors is reached.

bSingleSplitSteps

bool

true

Only used for the LBG clustering algorithm. If true, the global optimization is always run after a single cluster has been split. If false, several clusters are split within the same step before applying the global optimization. Applying the global optimization less often is faster, but can lead to less optimal results, especially having 2 nearby clusters that could be represented by 1)

TrainImageColor 1: Return value

HRESULT

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