do_ocr_word_knn T_do_ocr_word_knn DoOcrWordKnn DoOcrWordKnn do_ocr_word_knn (Operator)
Name
do_ocr_word_knn T_do_ocr_word_knn DoOcrWordKnn DoOcrWordKnn do_ocr_word_knn
— Classify a related group of characters with an OCR classifier.
Signature
void DoOcrWordKnn (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 ::DoOcrWordKnn (const HImage& Image , const HOCRKnn& OCRHandle , const HString& Expression , Hlong NumAlternatives , Hlong NumCorrections , HTuple* Confidence , HString* Word , double* Score ) const
HString HRegion ::DoOcrWordKnn (const HImage& Image , const HOCRKnn& OCRHandle , const HString& Expression , Hlong NumAlternatives , Hlong NumCorrections , double* Confidence , HString* Word , double* Score ) const
HString HRegion ::DoOcrWordKnn (const HImage& Image , const HOCRKnn& OCRHandle , const char* Expression , Hlong NumAlternatives , Hlong NumCorrections , double* Confidence , HString* Word , double* Score ) const
HString HRegion ::DoOcrWordKnn (const HImage& Image , const HOCRKnn& OCRHandle , const wchar_t* Expression , Hlong NumAlternatives , Hlong NumCorrections , double* Confidence , HString* Word , double* Score ) const
(
Windows only)
HTuple HOCRKnn ::DoOcrWordKnn (const HRegion& Character , const HImage& Image , const HString& Expression , Hlong NumAlternatives , Hlong NumCorrections , HTuple* Confidence , HString* Word , double* Score ) const
HString HOCRKnn ::DoOcrWordKnn (const HRegion& Character , const HImage& Image , const HString& Expression , Hlong NumAlternatives , Hlong NumCorrections , double* Confidence , HString* Word , double* Score ) const
HString HOCRKnn ::DoOcrWordKnn (const HRegion& Character , const HImage& Image , const char* Expression , Hlong NumAlternatives , Hlong NumCorrections , double* Confidence , HString* Word , double* Score ) const
HString HOCRKnn ::DoOcrWordKnn (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 .DoOcrWordKnn (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 .DoOcrWordKnn (HImage image , HOCRKnn OCRHandle , string expression , int numAlternatives , int numCorrections , out HTuple confidence , out string word , out double score )
string HRegion .DoOcrWordKnn (HImage image , HOCRKnn OCRHandle , string expression , int numAlternatives , int numCorrections , out double confidence , out string word , out double score )
HTuple HOCRKnn .DoOcrWordKnn (HRegion character , HImage image , string expression , int numAlternatives , int numCorrections , out HTuple confidence , out string word , out double score )
string HOCRKnn .DoOcrWordKnn (HRegion character , HImage image , string expression , int numAlternatives , int numCorrections , out double confidence , out string word , out double score )
def do_ocr_word_knn (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_knn_s (character : HObject, image : HObject, ocrhandle : HHandle, expression : str, num_alternatives : int, num_corrections : int) -> Tuple[str, float, str, float]
Description
do_ocr_word_knn do_ocr_word_knn DoOcrWordKnn DoOcrWordKnn do_ocr_word_knn
works like do_ocr_multi_class_knn do_ocr_multi_class_knn DoOcrMultiClassKnn DoOcrMultiClassKnn do_ocr_multi_class_knn
insofar
as it computes the best class for each of the characters given by the
regions Character Character Character character character
and the gray values Image Image Image image image
with the
OCR classifier OCRHandle OCRHandle OCRHandle OCRHandle ocrhandle
, and returns the classes in Class Class Class classVal class
and the corresponding confidences of the classes
in Confidence Confidence Confidence confidence confidence
. The confidences lie between 0.0 and 1.0.
The larger the value, the more reliable is the classification of the single
characters.
In contrast to do_ocr_multi_class_knn do_ocr_multi_class_knn DoOcrMultiClassKnn DoOcrMultiClassKnn do_ocr_multi_class_knn
, do_ocr_word_knn do_ocr_word_knn DoOcrWordKnn DoOcrWordKnn do_ocr_word_knn
treats the group of characters as an entity which yields a Word Word Word word word
by concatenating the class names for each character region. This allows
to restrict the allowed classification results on a textual level by
specifying an Expression Expression Expression expression expression
describing the expected word.
The Expression Expression Expression expression expression
may restrict the word to belong to a predefined
lexicon created using create_lexicon create_lexicon CreateLexicon CreateLexicon create_lexicon
or import_lexicon import_lexicon ImportLexicon ImportLexicon import_lexicon
,
by specifying the name of the lexicon in angular
brackets as in '<mylexicon>' "<mylexicon>" "<mylexicon>" "<mylexicon>" "<mylexicon>" . If the Expression Expression Expression expression expression
is of
any other form, it is interpreted as a regular expression with the same
syntax as specified for tuple_regexp_match tuple_regexp_match TupleRegexpMatch TupleRegexpMatch tuple_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_match tuple_regexp_match TupleRegexpMatch TupleRegexpMatch tuple_regexp_match
, do_ocr_word_knn do_ocr_word_knn DoOcrWordKnn DoOcrWordKnn do_ocr_word_knn
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 Expression Expression Expression expression expression
, do_ocr_word_knn do_ocr_word_knn DoOcrWordKnn DoOcrWordKnn do_ocr_word_knn
attempts to correct it by
considering the NumAlternatives NumAlternatives NumAlternatives numAlternatives num_alternatives
best classes for each character.
The alternatives used are identical to those returned by
do_ocr_single_class_knn do_ocr_single_class_knn DoOcrSingleClassKnn DoOcrSingleClassKnn do_ocr_single_class_knn
for a single character. It does so by
testing all possible corrections for which the classification result
is changed for at most NumCorrections NumCorrections NumCorrections numCorrections num_corrections
character regions.
Note that NumAlternatives NumAlternatives NumAlternatives numAlternatives num_alternatives
and NumCorrections NumCorrections NumCorrections numCorrections num_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 Expression Expression Expression expression expression
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 NumCorrections NumCorrections NumCorrections numCorrections num_corrections
edit operations for the
correction (see suggest_lexicon suggest_lexicon SuggestLexicon SuggestLexicon suggest_lexicon
).
The resulting word is graded by a Score Score Score score score
between 0.0 (no correction
found) and 1.0 (original word correct). The Score Score Score score score
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 Expression Expression Expression expression expression
:
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 Confidence Confidence Confidence confidence confidence
of the best Class Class Class classVal class
.
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
Character Character Character character character
(input_object) region(-array) →
object HRegion HObject HObject Hobject
Characters to be recognized.
Image Image Image image image
(input_object) singlechannelimage →
object HImage HObject HObject Hobject (byte / uint2)
Gray values of the characters.
OCRHandle OCRHandle OCRHandle OCRHandle ocrhandle
(input_control) ocr_knn →
HOCRKnn , HTuple HHandle HTuple Htuple (handle) (IntPtr ) (HHandle ) (handle )
Handle of the OCR classifier.
Expression Expression Expression expression expression
(input_control) string →
HTuple str HTuple Htuple (string) (string ) (HString ) (char* )
Expression describing the allowed word structure.
NumAlternatives NumAlternatives NumAlternatives numAlternatives num_alternatives
(input_control) integer →
HTuple int HTuple Htuple (integer) (int / long) (Hlong ) (Hlong )
Number of classes per character considered for the
internal word correction.
Default:
3
Suggested values:
3, 4, 5
Value range:
1
≤
NumAlternatives
NumAlternatives
NumAlternatives
numAlternatives
num_alternatives
≤
5
NumCorrections NumCorrections NumCorrections numCorrections num_corrections
(input_control) integer →
HTuple int HTuple Htuple (integer) (int / long) (Hlong ) (Hlong )
Maximum number of corrected characters.
Default:
2
Suggested values:
1, 2, 3, 4, 5
Value range:
0
≤
NumCorrections
NumCorrections
NumCorrections
numCorrections
num_corrections
≤
5
Class Class Class classVal class
(output_control) string(-array) →
HTuple Sequence[str] HTuple Htuple (string) (string ) (HString ) (char* )
Result of classifying the characters with the
k-NN.
Number of elements:
Class == Character
Confidence Confidence Confidence confidence confidence
(output_control) real(-array) →
HTuple Sequence[float] HTuple Htuple (real) (double ) (double ) (double )
Confidence of the class of the characters.
Number of elements:
Confidence == Character
Word Word Word word word
(output_control) string →
HTuple str HTuple Htuple (string) (string ) (HString ) (char* )
Word text after classification and correction.
Score Score Score score score
(output_control) real →
HTuple float HTuple Htuple (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_knn do_ocr_word_knn DoOcrWordKnn DoOcrWordKnn do_ocr_word_knn
returns the value 2 (
H_MSG_TRUE )
. If
necessary, an exception is raised.
Possible Predecessors
trainf_ocr_class_knn trainf_ocr_class_knn TrainfOcrClassKnn TrainfOcrClassKnn trainf_ocr_class_knn
,
read_ocr_class_knn read_ocr_class_knn ReadOcrClassKnn ReadOcrClassKnn read_ocr_class_knn
Alternatives
do_ocr_multi_class_knn do_ocr_multi_class_knn DoOcrMultiClassKnn DoOcrMultiClassKnn do_ocr_multi_class_knn
See also
create_ocr_class_knn create_ocr_class_knn CreateOcrClassKnn CreateOcrClassKnn create_ocr_class_knn
,
classify_class_knn classify_class_knn ClassifyClassKnn ClassifyClassKnn classify_class_knn
Module
OCR/OCV