F_VN_OCRExp
Detects and recognizes characters in a binary image (white characters on black background). (expert function)
Can use available TwinCAT Job Tasks for executing parallel code regions.
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
Inputs
|
Name |
Type |
Description |
|---|---|---|
|
ipSrcImage |
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 indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
Outputs
|
Name |
Type |
Description |
|---|---|---|
|
fMinConfidence |
REAL |
Returns the minimum value of the confidences |
Further information
The function F_VN_OCRExp is the Expert version 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:
!(exclamation mark) to ignore characters (does not apply to spaces).(point) for any character (does not apply to spaces)
The use of the point is only supported with the TCVN_OMT_NUMBERS_SC_UCLETTERS model, otherwise the point has the same effect as an exclamation mark and an S_FALSE is output._(underscore) for a space (independent ofeOcrOptions)d(number) for an expected number of0-9#(special character) for an expected special character, supported are. / - : = +u(capital letter) for an expected capital letter ofA-Z
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