ClassesClasses | | Operators

do_ocr_word_mlpdo_ocr_word_mlpDoOcrWordMlpDoOcrWordMlp (Operator)

Name

do_ocr_word_mlpdo_ocr_word_mlpDoOcrWordMlpDoOcrWordMlp — Classify a related group of characters with an OCR classifier.

Signature

do_ocr_word_mlp(Character, Image : : OCRHandle, Expression, NumAlternatives, NumCorrections : Class, Confidence, Word, Score)

Herror do_ocr_word_mlp(const Hobject Character, const Hobject Image, const Hlong OCRHandle, const char* Expression, const Hlong NumAlternatives, const Hlong NumCorrections, char* Class, double* Confidence, char* Word, double* Score)

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)

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)

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

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

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)

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_mlpdo_ocr_word_mlpDoOcrWordMlpDoOcrWordMlpDoOcrWordMlp works like do_ocr_multi_class_mlpdo_ocr_multi_class_mlpDoOcrMultiClassMlpDoOcrMultiClassMlpDoOcrMultiClassMlp insofar as it computes the best class for each of the characters given by the regions CharacterCharacterCharacterCharactercharacter and the gray values ImageImageImageImageimage with the OCR classifier OCRHandleOCRHandleOCRHandleOCRHandleOCRHandle, and returns the classes in ClassClassClassClassclassVal and the corresponding confidences (probabilities) of the classes in ConfidenceConfidenceConfidenceConfidenceconfidence.

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

The ExpressionExpressionExpressionExpressionexpression may restrict the word to belong to a predefined lexicon created using create_lexiconcreate_lexiconCreateLexiconCreateLexiconCreateLexicon or import_lexiconimport_lexiconImportLexiconImportLexiconImportLexicon, by specifying the name of the lexicon in angular brackets as in '<mylexicon>'"<mylexicon>""<mylexicon>""<mylexicon>""<mylexicon>". If the ExpressionExpressionExpressionExpressionexpression is of any other form, it is interpreted as a regular expression with the same syntax as specified for tuple_regexp_matchtuple_regexp_matchTupleRegexpMatchTupleRegexpMatchTupleRegexpMatch. 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_matchtuple_regexp_matchTupleRegexpMatchTupleRegexpMatchTupleRegexpMatch, do_ocr_word_mlpdo_ocr_word_mlpDoOcrWordMlpDoOcrWordMlpDoOcrWordMlp 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 ExpressionExpressionExpressionExpressionexpression, do_ocr_word_mlpdo_ocr_word_mlpDoOcrWordMlpDoOcrWordMlpDoOcrWordMlp attempts to correct it by considering the NumAlternativesNumAlternativesNumAlternativesNumAlternativesnumAlternatives best classes for each character. The alternatives used are identical to those returned by do_ocr_single_class_mlpdo_ocr_single_class_mlpDoOcrSingleClassMlpDoOcrSingleClassMlpDoOcrSingleClassMlp for a single character. It does so by testing all possible corrections for which the classification result is changed for at most NumCorrectionsNumCorrectionsNumCorrectionsNumCorrectionsnumCorrections character regions.

In case the ExpressionExpressionExpressionExpressionexpression 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 NumCorrectionsNumCorrectionsNumCorrectionsNumCorrectionsnumCorrections edit operations for the correction (see suggest_lexiconsuggest_lexiconSuggestLexiconSuggestLexiconSuggestLexicon).

The resulting word is graded by a ScoreScoreScoreScorescore between 0.0 (no correction found) and 1.0 (original word correct), which is dominated by the number of corrected characters but also adds a minor penalty for ignoring the second best class or even all best classes (in case of lexica). Note that this is a combinatorial score which does not reflect the original ConfidenceConfidenceConfidenceConfidenceconfidence of the best ClassClassClassClassclassVal.

The result '\x1A'"\x1A""\x1A""\x1A""\x1A" in ClassClassClassClassclassVal signifies that the respective region has been classified as rejection class.

Execution Information

Parameters

CharacterCharacterCharacterCharactercharacter (input_object)  region(-array) objectHRegionHRegionHobject

Characters to be recognized.

ImageImageImageImageimage (input_object)  singlechannelimage objectHImageHImageHobject (byte / uint2)

Gray values of the characters.

OCRHandleOCRHandleOCRHandleOCRHandleOCRHandle (input_control)  ocr_mlp HOCRMlp, HTupleHTupleHtuple (integer) (IntPtr) (Hlong) (Hlong)

Handle of the OCR classifier.

ExpressionExpressionExpressionExpressionexpression (input_control)  string HTupleHTupleHtuple (string) (string) (HString) (char*)

Expression describing the allowed word structure.

NumAlternativesNumAlternativesNumAlternativesNumAlternativesnumAlternatives (input_control)  integer HTupleHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

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

Default value: 3

Suggested values: 3, 4, 5

Typical range of values: 1 ≤ NumAlternatives NumAlternatives NumAlternatives NumAlternatives numAlternatives

NumCorrectionsNumCorrectionsNumCorrectionsNumCorrectionsnumCorrections (input_control)  integer HTupleHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Maximum number of corrected characters.

Default value: 2

Suggested values: 1, 2, 3, 4, 5

Typical range of values: 0 ≤ NumCorrections NumCorrections NumCorrections NumCorrections numCorrections

ClassClassClassClassclassVal (output_control)  string(-array) HTupleHTupleHtuple (string) (string) (HString) (char*)

Result of classifying the characters with the MLP.

Number of elements: Class == Character

ConfidenceConfidenceConfidenceConfidenceconfidence (output_control)  real(-array) HTupleHTupleHtuple (real) (double) (double) (double)

Confidence of the class of the characters.

Number of elements: Confidence == Character

WordWordWordWordword (output_control)  string HTupleHTupleHtuple (string) (string) (HString) (char*)

Word text after classification and correction.

ScoreScoreScoreScorescore (output_control)  real HTupleHTupleHtuple (real) (double) (double) (double)

Measure of similarity between corrected word and uncorrected classification results.

Complexity

The complexity of checking all possible corrections is of magnitude , 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_mlpdo_ocr_word_mlpDoOcrWordMlpDoOcrWordMlpDoOcrWordMlp returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Possible Predecessors

trainf_ocr_class_mlptrainf_ocr_class_mlpTrainfOcrClassMlpTrainfOcrClassMlpTrainfOcrClassMlp, read_ocr_class_mlpread_ocr_class_mlpReadOcrClassMlpReadOcrClassMlpReadOcrClassMlp

Alternatives

do_ocr_multi_class_mlpdo_ocr_multi_class_mlpDoOcrMultiClassMlpDoOcrMultiClassMlpDoOcrMultiClassMlp

See also

create_ocr_class_mlpcreate_ocr_class_mlpCreateOcrClassMlpCreateOcrClassMlpCreateOcrClassMlp, classify_class_mlpclassify_class_mlpClassifyClassMlpClassifyClassMlpClassifyClassMlp

Module

OCR/OCV


ClassesClasses | | Operators