OCR

This group contains functions for Optical Character Recognition.

The OCR functions identify characters in an image and return the recognized characters as a string. The classification is based on classic Machine Learning models. The models are provided in a trained form so that the functions can be used directly. No additional settings or training are required. The supported characters and fonts depend on the data used in the training. For this reason, there are various models whose range of functions, as well as the general preconditions and requirements, are described below.

For all characters that are recognized in an image, the models assign each character to a known class with the highest match. The result therefore always consists of the known characters of the model used. Rejection or removal of unknown characters is not included.

The functions only support single-line character strings; several lines must be divided into individual ROIs and read with several function calls.

General requirements for recognizing characters:

General requirements for the image:

Requirements for the fonts:

Models:

The enum ETcVnOcrModelType allows access to the following models:

When using the combined model (TCVN_OMT_NUMBERS_SC_UCLETTERS), confusion can occur due to the great similarity of certain characters. Examples of this are O and 0, S and 5 and B and 8.

If the position of a number or letter is known, the Expert function with the formatting default (sPattern) and the combination of the separate models should be used as an alternative. Alternatively, the characters of the result string (ipCharacters) can also be analyzed individually, so that you can decide individually whether, for example, a 0 is also accepted instead of O.

Initialize functions

In order to be able to use the OCR function with one or more models, the function must first be initialized with the respective models using the function block FB_VN_InitializeFunction.

The time required to load the models depends on the performance of the IPC used and the model size and can take several hundred milliseconds or even several seconds. Therefore, cycle time overruns are to be expected with shorter task cycle times.

If the combined model TCVN_OMT_NUMBERS_SC_UCLETTERS is to be used, the router memory must be set to at least 512 MB due to the file size.

The exact size depends on the other use of the router memory and any existing fragmentation. If the function block FB_VN_InitializeFunction returns a return code 0x80004005, for example, this indicates insufficient router memory. The router memory should therefore be checked first and increased if necessary. After loading a model, a large part of the memory is released again and is available for the application.

Interpretation of the HRESULT

Examples for the use of sPattern

The F_VN_OCRExp provides additional options with the parameters sPattern and eOcrOptions. Depending on the combination of characters on the input image, the information from sPattern and eOcrOptions and the recognized characters, S_FALSE is returned if there is a mismatch. The characters of the result string (ipCharacters) can then also be analyzed individually, as S_FALSE is also returned if the length differs, for example. The examples refer to the use of the TCVN_OMT_NUMBERS_SC_UCLETTERS model.

Characters on the ipSrcImage

sPattern

eOcrOptions

ipCharacters

HRESULT

12/34

dd.dd

 

12/34

S_OK

12534

dd.dd

 

12534

S_OK

12/34

dd!dd

 

1234

S_OK

12 34

dd!d

 

124

S_OK

12534

dd!dd

 

1234

S_OK

12 34

dd_dd

 

12 34

S_OK

AB12/

uudd#

 

AB12/

S_OK

12 34

dddd

WITHBLANKS

12 34

S_OK

12/4

dd#d

WITHBLANKS

12/4

S_OK

12 34

dd_dd

WITHBLANKS

12 34

S_OK

12 34 56

dd_dddd

WITHBLANKS

12 34 56

S_OK

12 3 4

dd.dd

WITHBLANKS

12 3 4

S_FALSE

12 34

dd!dd

 

124

S_FALSE

12 34

dd.dd

 

1234

S_FALSE

1234

!dddd

 

234

S_FALSE

12 34

dd_dd

 

12.34

S_FALSE

12 3

dd_dd

 

123

S_FALSE

12 3 4

dd_d_d

 

123 4

S_FALSE

AB12/

uddd#

 

AB12/

S_FALSE

AB12/

uuddd

 

AB12/

S_FALSE