F_VN_OCR
Detects and recognizes characters in a binary image (white characters on black background).
Can use available TwinCAT Job Tasks for executing parallel code regions.
Syntax
Definition:
FUNCTION F_VN_OCR : HRESULT
VAR_INPUT
ipSrcImage : ITcVnImage;
eModel : ULINT;
ipCharacters : Reference To ITcVnContainer;
hrPrev : HRESULT;
END_VAR
Inputs
Name | Type | Description |
|---|---|---|
ipSrcImage | Source image (USINT elements, 1 or 3 channels). The required number of channels depends on the selected model type. | |
eModel | ULINT | Selection of OCR model types (ETcVnOcrModelType) |
ipCharacters | Reference To ITcVnContainer | Returns the recognized characters (ContainerType_Vector_String_SINT) |
hrPrev | HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
Further information
The function F_VN_OCR detects and recognizes characters in a binary image and returns the recognized characters in a container.
Parameter
Input image
The format of the input image that must be provided to ipSrcImage depends on the model used:
- For models whose names begin with
TCVN_OMT_, you must provide a 1-channel binary image that permits only white characters on a black background. - For the model that begins with
TCVN_OMT_CNN_, a 1-channel or 3-channel image of type USINT (8 bits) must be passed, which is automatically converted internally. The specific input format and size of the model are listed in the description of ETcVnOcrModelType. In order to reduce the internal conversion steps and thus also the computing time required, it is recommended to transfer the image with the same number of channels if it already exists in the form before the call. In general, it should be ensured that the aspect ratio of the input image is as similar as possible to that of the model. Otherwise, the internal scaling may result in distortions that impair the detection quality.
Model
A model type of ETcVnOcrModelType, which is to be used in a function call to classify the characters, must be transferred to eModel. This function only supports the use of one model per function call.
To be able to use a model, it must first be initialized with the function block FB_VN_InitializeFunction.
Recognized characters
The recognized characters are returned via the reference ipCharacters.
Expert parameters
The expert variant F_VN_OCRExp contains additional parameters.
Application
For example, a call of the OCR function, with a model for recognizing numbers, with subsequent string export looks like this:
hr := F_VN_OCR(
ipSrcImage := ipBinaryImage,
eModel := TCVN_OMT_NUMBERS,
ipCharacters := ipCharactersResults,
hrPrev := hr);
// Export character to string
hr := F_VN_ExportSubContainer_String(ipCharactersResults, 0, sText, 255, hr);Examples:
Required License
TC3 Vision OCR
System Requirements
Development environment | Target platform | PLC libraries to include |
|---|---|---|
TwinCAT V3.1.4024.59 or later | PC or CX (x64) with min. PL50, e.g. Intel 4-core Atom CPU | Tc3_Vision |
Return value