F_VN_OCRExp

F_VN_OCRExp 1:

Detects and recognizes characters in a binary image (white characters on black background). (expert function)

Syntax

Definition:

FUNCTION F_VN_OCRExp : HRESULT
VAR_INPUT
    ipSrcImage      : ITcVnImage;
    eModel          : ULINT;
    ipCharacters    : Reference To ITcVnContainer;
    sPattern        : STRING;
    eOcrOptions     : UDINT;
    ipBoundingBoxes : Reference To ITcVnContainer;
    ipConfidences   : Reference To ITcVnContainer;
    hrPrev          : HRESULT;
END_VAR
VAR_OUTPUT
    fMinConfidence  : REAL;
END_VAR

F_VN_OCRExp 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (USINT, 1 channel, binary)

eModel

ULINT

Selection of OCR model types (ETcVnOcrModelType)

ipCharacters

Reference To ITcVnContainer

Returns the recognized characters (ContainerType_Vector_String_SINT)

sPattern

STRING

String pattern containing the format in which characters are presented

eOcrOptions

UDINT

Specifies which options must be applied to the function (ETcVnOcrOptions)

ipBoundingBoxes

Reference To ITcVnContainer

Returns the corresponding bounding boxes of the recognized characters (ContainerType_Vector_TcVnRectangle_DINT, optional, set to 0 if not required)

ipConfidences

Reference To ITcVnContainer

Returns the corresponding classification confidences of the recognized characters (ContainerType_Vector_REAL, optional, set to 0 if not required)

hrPrev

HRESULT

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

F_VN_OCRExp 3: Outputs

Name

Type

Description

fMinConfidence

REAL

Returns the minimum value of the confidences

F_VN_OCRExp 4: Return value

HRESULT

Further information

The function F_VN_OCRExp is the expert variant of F_VN_OCR. It contains additional parameters.

Parameter

Input image

The input image that is transferred to ipSrcImage must be a 1-channel binary image. Only white characters on a black background are permitted.

Model

The model types of ETcVnOcrModelType that are to be used to classify the characters in a function call must be transferred to eModel. To be able to use several models with one function call, a string pattern must be specified via sPattern. The models can be linked with a OR.

To be able to use the individual models, they must first be initialized with the function block FB_VN_InitializeFunction.

Recognized characters

The recognized characters are returned via the reference ipCharacters.

String pattern

A string pattern with the expected format of the character string to be recognized can be transferred via sPattern.

Supported formatting and its meaning:

Options

With eOcrOptions, options (ETcVnOcrOptions) can be specified that influence the functionality and result output. If no options are required, a 0 must be passed.

Bounding Boxes

The reference ipBoundingBoxes can optionally be used to return the corresponding bounding boxes of the recognized characters. If no bounding boxes are required, the value 0 can be transferred.

Confidences

The reference ipConfidences can optionally be used to return the corresponding classification confidences of the recognized characters. If no confidences are required, the value 0 can be transferred.

Minimum confidence

The optional return value fMinConfidence returns the minimum confidence value of all characters found.

Application

For example, a call to the OCRExp function, with two models for recognizing numbers and capital letters, with subsequent string export looks like this:

sPattern := 'dd!uuu!dddd'; // e.g. 02-FEB-2024

hr := F_VN_OCRExp(
    ipSrcImage      := ipBinaryImage,
    eModel          := TCVN_OMT_NUMBERS OR TCVN_OMT_UCLETTERS,
    ipCharacters    := ipCharactersResults,
    sPattern        := sPattern,
    eOcrOptions     := eOcrOptions,
    ipBoundingBoxes := ipBoundingBoxes,
    ipConfidences   := ipConfidences,
    hrPrev          := hr,
    fMinConfidence  => fMinConfidence);

// Export character to string
hr := F_VN_ExportSubContainer_String(ipCharactersResults, 0, sText, 255, hr);

// Get the bounding box of the first element
hr := F_VN_GetAt_TcVnRectangle_DINT(ipBoundingBoxes, stRectangle, 0, hr);

// Get the Confidence value of the first element
hr := F_VN_GetAt_REAL(ipConfidences, fConfidence, 0, hr);

To evaluate the confidence values or to draw bounding boxes, individual elements of the containers can be accessed via GetAt. However, if you want to access several or all elements of a container, it is advisable to program a loop or export the ipConfidences container completely as an array.

Required License

TC3 Vision OCR

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