do_ocr_word_cnnT_do_ocr_word_cnnDoOcrWordCnnDoOcrWordCnndo_ocr_word_cnn (Operator)

Name

do_ocr_word_cnnT_do_ocr_word_cnnDoOcrWordCnnDoOcrWordCnndo_ocr_word_cnn — Classify a related group of characters with an CNN-based OCR classifier.

Signature

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

Herror T_do_ocr_word_cnn(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 DoOcrWordCnn(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::DoOcrWordCnn(const HImage& Image, const HOCRCnn& OCRHandle, const HString& Expression, Hlong NumAlternatives, Hlong NumCorrections, HTuple* Confidence, HString* Word, double* Score) const

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

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

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

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

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

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

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

static void HOperatorSet.DoOcrWordCnn(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.DoOcrWordCnn(HImage image, HOCRCnn OCRHandle, string expression, int numAlternatives, int numCorrections, out HTuple confidence, out string word, out double score)

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

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

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

def do_ocr_word_cnn(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_cnn_s(character: HObject, image: HObject, ocrhandle: HHandle, expression: str, num_alternatives: int, num_corrections: int) -> Tuple[str, float, str, float]

Description

do_ocr_word_cnndo_ocr_word_cnnDoOcrWordCnnDoOcrWordCnnDoOcrWordCnndo_ocr_word_cnn works like do_ocr_multi_class_cnndo_ocr_multi_class_cnnDoOcrMultiClassCnnDoOcrMultiClassCnnDoOcrMultiClassCnndo_ocr_multi_class_cnn insofar as it computes the best class for each of the characters given by the regions CharacterCharacterCharacterCharactercharactercharacter and the gray values ImageImageImageImageimageimage with the OCR classifier OCRHandleOCRHandleOCRHandleOCRHandleOCRHandleocrhandle, and returns the classes in ClassClassClassClassclassValclass and the corresponding confidences (probabilities) of the classes in ConfidenceConfidenceConfidenceConfidenceconfidenceconfidence.

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

The ExpressionExpressionExpressionExpressionexpressionexpression may restrict the word to belong to a predefined lexicon created using create_lexiconcreate_lexiconCreateLexiconCreateLexiconCreateLexiconcreate_lexicon or import_lexiconimport_lexiconImportLexiconImportLexiconImportLexiconimport_lexicon, or by specifying the name of the lexicon in angular brackets as in '<mylexicon>'"<mylexicon>""<mylexicon>""<mylexicon>""<mylexicon>""<mylexicon>". If the ExpressionExpressionExpressionExpressionexpressionexpression is of any other form, it is interpreted as a regular expression with the same syntax as specified for tuple_regexp_matchtuple_regexp_matchTupleRegexpMatchTupleRegexpMatchTupleRegexpMatchtuple_regexp_match. 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_matchTupleRegexpMatchTupleRegexpMatchTupleRegexpMatchtuple_regexp_match, do_ocr_word_cnndo_ocr_word_cnnDoOcrWordCnnDoOcrWordCnnDoOcrWordCnndo_ocr_word_cnn 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 ExpressionExpressionExpressionExpressionexpressionexpression, do_ocr_word_cnndo_ocr_word_cnnDoOcrWordCnnDoOcrWordCnnDoOcrWordCnndo_ocr_word_cnn attempts to correct it by considering the NumAlternativesNumAlternativesNumAlternativesNumAlternativesnumAlternativesnum_alternatives best classes for each character. The alternatives used are identical to those returned by do_ocr_single_class_cnndo_ocr_single_class_cnnDoOcrSingleClassCnnDoOcrSingleClassCnnDoOcrSingleClassCnndo_ocr_single_class_cnn for a single character. It does so by testing all possible corrections for which the classification result is changed for at most NumCorrectionsNumCorrectionsNumCorrectionsNumCorrectionsnumCorrectionsnum_corrections character regions. Note that NumAlternativesNumAlternativesNumAlternativesNumAlternativesnumAlternativesnum_alternatives and NumCorrectionsNumCorrectionsNumCorrectionsNumCorrectionsnumCorrectionsnum_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 ExpressionExpressionExpressionExpressionexpressionexpression 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 NumCorrectionsNumCorrectionsNumCorrectionsNumCorrectionsnumCorrectionsnum_corrections edit operations for the correction (see suggest_lexiconsuggest_lexiconSuggestLexiconSuggestLexiconSuggestLexiconsuggest_lexicon).

The resulting word is graded by a ScoreScoreScoreScorescorescore between 0.0 (no correction found) and 1.0 (original word correct). The ScoreScoreScoreScorescorescore 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 ExpressionExpressionExpressionExpressionexpressionexpression:

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

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

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

Execution Information

Parameters

CharacterCharacterCharacterCharactercharactercharacter (input_object)  region(-array) objectHRegionHObjectHRegionHobject

Characters to be recognized.

ImageImageImageImageimageimage (input_object)  singlechannelimage objectHImageHObjectHImageHobject (byte / uint2)

Gray values of the characters.

OCRHandleOCRHandleOCRHandleOCRHandleOCRHandleocrhandle (input_control)  ocr_cnn HOCRCnn, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Handle of the OCR classifier.

ExpressionExpressionExpressionExpressionexpressionexpression (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Expression describing the allowed word structure.

NumAlternativesNumAlternativesNumAlternativesNumAlternativesnumAlternativesnum_alternatives (input_control)  integer HTupleintHTupleHtuple (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 num_alternatives

NumCorrectionsNumCorrectionsNumCorrectionsNumCorrectionsnumCorrectionsnum_corrections (input_control)  integer HTupleintHTupleHtuple (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 num_corrections

ClassClassClassClassclassValclass (output_control)  string(-array) HTupleSequence[str]HTupleHtuple (string) (string) (HString) (char*)

Result of classifying the characters with the CNN.

Number of elements: Class == Character

ConfidenceConfidenceConfidenceConfidenceconfidenceconfidence (output_control)  real(-array) HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

Confidence of the class of the characters.

Number of elements: Confidence == Character

WordWordWordWordwordword (output_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Word text after classification and correction.

ScoreScoreScoreScorescorescore (output_control)  real HTuplefloatHTupleHtuple (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_cnndo_ocr_word_cnnDoOcrWordCnnDoOcrWordCnnDoOcrWordCnndo_ocr_word_cnn returns the value TRUE. If necessary, an exception is raised.

Possible Predecessors

read_ocr_class_cnnread_ocr_class_cnnReadOcrClassCnnReadOcrClassCnnReadOcrClassCnnread_ocr_class_cnn

Alternatives

do_ocr_multi_class_cnndo_ocr_multi_class_cnnDoOcrMultiClassCnnDoOcrMultiClassCnnDoOcrMultiClassCnndo_ocr_multi_class_cnn

Module

OCR/OCV