Skip to content

do_ocr_word_mlpdo_ocr_word_mlpDoOcrWordMlpDoOcrWordMlpdo_ocr_word_mlpT_do_ocr_word_mlpπŸ”—

Short descriptionπŸ”—

do_ocr_word_mlpdo_ocr_word_mlpDoOcrWordMlpDoOcrWordMlpdo_ocr_word_mlpT_do_ocr_word_mlp β€” Classify a related group of characters with an OCR classifier.

SignatureπŸ”—

do_ocr_word_mlp( region Character, image Image, ocr_mlp OCRHandle, string Expression, integer NumAlternatives, integer NumCorrections, out string Class, out real Confidence, out string Word, out real Score )do_ocr_word_mlp( Character, Image : : OCRHandle, Expression, NumAlternatives, NumCorrections : Class, Confidence, Word, Score )void DoOcrWordMlp( const HObject& Character, const HObject& Image, const HTuple& OCRHandle, const HTuple& Expression, const HTuple& NumAlternatives, const HTuple& NumCorrections, HTuple* Class, HTuple* Confidence, HTuple* Word, HTuple* Score )static void HOperatorSet.DoOcrWordMlp( HObject character, HObject image, HTuple OCRHandle, HTuple expression, HTuple numAlternatives, HTuple numCorrections, out HTuple classVal, out HTuple confidence, out HTuple word, out HTuple score )def do_ocr_word_mlp( character: HObject, image: HObject, ocrhandle: HHandle, expression: str, num_alternatives: int, num_corrections: int ) -> Tuple[Sequence[str], Sequence[float], str, float]

def do_ocr_word_mlp_s( character: HObject, image: HObject, ocrhandle: HHandle, expression: str, num_alternatives: int, num_corrections: int ) -> Tuple[str, float, str, float]Herror T_do_ocr_word_mlp( const Hobject Character, const Hobject Image, const Htuple OCRHandle, const Htuple Expression, const Htuple NumAlternatives, const Htuple NumCorrections, Htuple* Class, Htuple* Confidence, Htuple* Word, Htuple* Score )

HTuple HRegion::DoOcrWordMlp( const HImage& Image, const HOCRMlp& OCRHandle, const HString& Expression, Hlong NumAlternatives, Hlong NumCorrections, HTuple* Confidence, HString* Word, double* Score ) const

HString HRegion::DoOcrWordMlp( const HImage& Image, const HOCRMlp& OCRHandle, const HString& Expression, Hlong NumAlternatives, Hlong NumCorrections, double* Confidence, HString* Word, double* Score ) const

HString HRegion::DoOcrWordMlp( const HImage& Image, const HOCRMlp& OCRHandle, const char* Expression, Hlong NumAlternatives, Hlong NumCorrections, double* Confidence, HString* Word, double* Score ) const

HString HRegion::DoOcrWordMlp( const HImage& Image, const HOCRMlp& OCRHandle, const wchar_t* Expression, Hlong NumAlternatives, Hlong NumCorrections, double* Confidence, HString* Word, double* Score ) const (Windows only)

HTuple HOCRMlp::DoOcrWordMlp( const HRegion& Character, const HImage& Image, const HString& Expression, Hlong NumAlternatives, Hlong NumCorrections, HTuple* Confidence, HString* Word, double* Score ) const

HString HOCRMlp::DoOcrWordMlp( const HRegion& Character, const HImage& Image, const HString& Expression, Hlong NumAlternatives, Hlong NumCorrections, double* Confidence, HString* Word, double* Score ) const

HString HOCRMlp::DoOcrWordMlp( const HRegion& Character, const HImage& Image, const char* Expression, Hlong NumAlternatives, Hlong NumCorrections, double* Confidence, HString* Word, double* Score ) const

HString HOCRMlp::DoOcrWordMlp( const HRegion& Character, const HImage& Image, const wchar_t* Expression, Hlong NumAlternatives, Hlong NumCorrections, double* Confidence, HString* Word, double* Score ) const (Windows only)

HTuple HRegion.DoOcrWordMlp( HImage image, HOCRMlp OCRHandle, string expression, int numAlternatives, int numCorrections, out HTuple confidence, out string word, out double score )

string HRegion.DoOcrWordMlp( HImage image, HOCRMlp OCRHandle, string expression, int numAlternatives, int numCorrections, out double confidence, out string word, out double score )

HTuple HOCRMlp.DoOcrWordMlp( HRegion character, HImage image, string expression, int numAlternatives, int numCorrections, out HTuple confidence, out string word, out double score )

string HOCRMlp.DoOcrWordMlp( HRegion character, HImage image, string expression, int numAlternatives, int numCorrections, out double confidence, out string word, out double score )

DescriptionπŸ”—

do_ocr_word_mlpDoOcrWordMlp works like do_ocr_multi_class_mlpDoOcrMultiClassMlp insofar as it computes the best class for each of the characters given by the regions Charactercharactercharacter and the gray values Imageimageimage with the OCR classifier OCRHandleOCRHandleocrhandle, and returns the classes in ClassclassValclass and the corresponding confidences (probabilities) of the classes in Confidenceconfidenceconfidence.

In contrast to do_ocr_multi_class_mlpDoOcrMultiClassMlp, do_ocr_word_mlpDoOcrWordMlp treats the group of characters as an entity which yields a Wordwordword by concatenating the class names for each character region. This allows to restrict the allowed classification results on a textual level by specifying an Expressionexpressionexpression describing the expected word.

The Expressionexpressionexpression may restrict the word to belong to a predefined lexicon created using create_lexiconCreateLexicon or import_lexiconImportLexicon, by specifying the name of the lexicon in angular brackets as in '<mylexicon>'"<mylexicon>". If the Expressionexpressionexpression is of any other form, it is interpreted as a regular expression with the same syntax as specified for tuple_regexp_matchTupleRegexpMatch. Note that you will usually want to use an expression of the form β€˜^…$’ when using variable quantifiers like β€˜*β€˜, to ensure that the entire word is used in the expression. Also note that in contrast to tuple_regexp_matchTupleRegexpMatch, do_ocr_word_mlpDoOcrWordMlp does not support passing extra options in an expression tuple.

If the word derived from the best class for each character does not match the Expressionexpressionexpression, do_ocr_word_mlpDoOcrWordMlp attempts to correct it by considering the NumAlternativesnumAlternativesnum_alternatives best classes for each character. The alternatives used are identical to those returned by do_ocr_single_class_mlpDoOcrSingleClassMlp for a single character. It does so by testing all possible corrections for which the classification result is changed for at most NumCorrectionsnumCorrectionsnum_corrections character regions. Note that NumAlternativesnumAlternativesnum_alternatives and NumCorrectionsnumCorrectionsnum_corrections affect the complexity of the algorithm, so that in some cases internal restrictions are made. See the section β€˜Complexity’ below for further information.

In case the Expressionexpressionexpression is a lexicon and the above procedure did not yield a result, the most similar word in the lexicon is returned as long as it requires less than NumCorrectionsnumCorrectionsnum_corrections edit operations for the correction (see suggest_lexiconSuggestLexicon).

The resulting word is graded by a Scorescorescore between 0.0 (no correction found) and 1.0 (original word correct). The Scorescorescore is lowered by adding a penalty according to the number of corrected characters and another (minor) penalty depending on how many classes with higher confidences have been ignored in order to match the Expressionexpressionexpression:

\[\begin{eqnarray*} \textrm{Score}=1.0-\texttt{PenaltyCorrections}-\texttt{PenaltyAlternatives} \end{eqnarray*}\]
\[\begin{eqnarray*} \texttt{PenaltyCorrections} & = & \alpha * \texttt{num\_corr} \\ \texttt{PenaltyAlternatives} & = & \alpha * \beta * \texttt{num\_alt} \end{eqnarray*}\]

with num_corr being the actual number of applied corrections and num_alt the total number of discarded alternatives.

\[\begin{eqnarray*} \alpha & = & \frac{1}{\textrm{NumCorrections}+1} \\ \beta & = & \frac{1}{\textrm{NumCorrections}*( \textrm{NumAlternatives}-1)+2} \end{eqnarray*}\]

Note that this is a combinatorial score which does not reflect the original Confidenceconfidenceconfidence of the best ClassclassValclass.

A string of the number \('\backslash 032'\) (alternatively displayed as \('\backslash 0x1A'\)) in ClassclassValclass signifies that the region has been classified as rejection class.

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

ParametersπŸ”—

Charactercharactercharacter (input_object) region(-array) β†’ objectobjectHObjectHRegionHObjectHobject

Characters to be recognized.

Imageimageimage (input_object) singlechannelimage β†’ object (byte / uint2)object (byte / uint2)HObject (byte / uint2)HImage (byte / uint2)HObject (byte / uint2)Hobject (byte / uint2)

Gray values of the characters.

OCRHandleOCRHandleocrhandle (input_control) ocr_mlp β†’ (handle)(handle)HTuple (HHandle)HOCRMlp, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the OCR classifier.

Expressionexpressionexpression (input_control) string β†’ (string)(string)HTuple (HString)HTuple (string)strHtuple (char*)

Expression describing the allowed word structure.

NumAlternativesnumAlternativesnum_alternatives (input_control) integer β†’ (integer)(integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Number of classes per character considered for the internal word correction.

Default: 33
Suggested values: 3, 4, 53, 4, 5
Value range: 1 ≀ NumAlternatives

NumCorrectionsnumCorrectionsnum_corrections (input_control) integer β†’ (integer)(integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Maximum number of corrected characters.

Default: 22
Suggested values: 1, 2, 3, 4, 51, 2, 3, 4, 5
Value range: 0 ≀ NumCorrections

ClassclassValclass (output_control) string(-array) β†’ (string)(string)HTuple (HString)HTuple (string)Sequence[str]Htuple (char*)

Result of classifying the characters with the MLP.

Number of elements: Class == Character

Confidenceconfidenceconfidence (output_control) real(-array) β†’ (real)(real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Confidence of the class of the characters.

Number of elements: Confidence == Character

Wordwordword (output_control) string β†’ (string)(string)HTuple (HString)HTuple (string)strHtuple (char*)

Word text after classification and correction.

Scorescorescore (output_control) real β†’ (real)(real)HTuple (double)HTuple (double)floatHtuple (double)

Measure of similarity between corrected word and uncorrected classification results.

ComplexityπŸ”—

The complexity of checking all possible corrections is of magnitude \(O((n*a)^{min(c,n)})\), where \(a\) is the number of alternatives, \(n\) is the number of character regions, and \(c\) is the number of allowed corrections. However, to guard against a near-infinite loop in case of large \(n\), \(c\) is internally clipped to \(5\), \(3\), or \(1\) if \(a*n >= 30\), \(60\), or \(90\), respectively.

ResultπŸ”—

If the parameters are valid, the operator do_ocr_word_mlpDoOcrWordMlp returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

trainf_ocr_class_mlpTrainfOcrClassMlp, read_ocr_class_mlpReadOcrClassMlp

Alternatives

do_ocr_multi_class_mlpDoOcrMultiClassMlp

See also

create_ocr_class_mlpCreateOcrClassMlp, classify_class_mlpClassifyClassMlp

ModuleπŸ”—

OCR/OCV