Tesseract
3.02
|
#include <intmatcher.h>
Public Member Functions | |
IntegerMatcher () | |
void | Init (tesseract::IntParam *classify_debug_level, int classify_integer_matcher_multiplier) |
void | SetBaseLineMatch () |
void | SetCharNormMatch (int integer_matcher_multiplier) |
void | Match (INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, inT16 NumFeatures, const INT_FEATURE_STRUCT *Features, INT_RESULT Result, int AdaptFeatureThreshold, int Debug, bool SeparateDebugWindows) |
float | ApplyCNCorrection (float rating, int blob_length, int normalization_factor) |
int | FindGoodProtos (INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, uinT16 BlobLength, inT16 NumFeatures, INT_FEATURE_ARRAY Features, PROTO_ID *ProtoArray, int AdaptProtoThreshold, int Debug) |
int | FindBadFeatures (INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, uinT16 BlobLength, inT16 NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_ID *FeatureArray, int AdaptFeatureThreshold, int Debug) |
Static Public Attributes | |
static const int | kIntThetaFudge = 128 |
static const int | kEvidenceTableBits = 9 |
static const int | kIntEvidenceTruncBits = 14 |
static const float | kSEExponentialMultiplier = 0.0 |
static const float | kSimilarityCenter = 0.0075 |
Definition at line 90 of file intmatcher.h.
IntegerMatcher::IntegerMatcher | ( | ) | [inline] |
Definition at line 103 of file intmatcher.h.
: classify_debug_level_(0) {}
float IntegerMatcher::ApplyCNCorrection | ( | float | rating, |
int | blob_length, | ||
int | normalization_factor | ||
) |
Definition at line 1284 of file intmatcher.cpp.
{
return (rating * blob_length +
local_matcher_multiplier_ * normalization_factor / 256.0) /
(blob_length + local_matcher_multiplier_);
}
int IntegerMatcher::FindBadFeatures | ( | INT_CLASS | ClassTemplate, |
BIT_VECTOR | ProtoMask, | ||
BIT_VECTOR | ConfigMask, | ||
uinT16 | BlobLength, | ||
inT16 | NumFeatures, | ||
INT_FEATURE_ARRAY | Features, | ||
FEATURE_ID * | FeatureArray, | ||
int | AdaptFeatureThreshold, | ||
int | Debug | ||
) |
Definition at line 624 of file intmatcher.cpp.
{ /* ** Parameters: ** ClassTemplate Prototypes & tables for a class ** ProtoMask AND Mask for proto word ** ConfigMask AND Mask for config word ** BlobLength Length of unormalized blob ** NumFeatures Number of features in blob ** Features Array of features ** FeatureArray Array of bad features ** AdaptFeatureThreshold Threshold for bad features ** Debug Debugger flag: 1=debugger on ** Operation: ** FindBadFeatures finds all features with maximum feature-evidence < ** AdaptFeatureThresh. The list is ordered by increasing feature number. ** Return: ** Number of bad features in FeatureArray. ** History: Tue Mar 12 17:09:26 MST 1991, RWM, Created */ ScratchEvidence *tables = new ScratchEvidence(); int NumBadFeatures = 0; /* DEBUG opening heading */ if (MatchDebuggingOn(Debug)) cprintf("Find Bad Features -------------------------------------------\n"); tables->Clear(ClassTemplate); for (int Feature = 0; Feature < NumFeatures; Feature++) { UpdateTablesForFeature( ClassTemplate, ProtoMask, ConfigMask, Feature, &Features[Feature], tables, Debug); /* Find Best Evidence for Current Feature */ int best = 0; for (int i = 0; i < ClassTemplate->NumConfigs; i++) if (tables->feature_evidence_[i] > best) best = tables->feature_evidence_[i]; /* Find Bad Features */ if (best < AdaptFeatureThreshold) { *FeatureArray = Feature; FeatureArray++; NumBadFeatures++; } } #ifndef GRAPHICS_DISABLED if (PrintProtoMatchesOn(Debug) || PrintMatchSummaryOn(Debug)) DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables, NumFeatures, Debug); #endif if (MatchDebuggingOn(Debug)) cprintf("Match Complete --------------------------------------------\n"); delete tables; return NumBadFeatures; }
int IntegerMatcher::FindGoodProtos | ( | INT_CLASS | ClassTemplate, |
BIT_VECTOR | ProtoMask, | ||
BIT_VECTOR | ConfigMask, | ||
uinT16 | BlobLength, | ||
inT16 | NumFeatures, | ||
INT_FEATURE_ARRAY | Features, | ||
PROTO_ID * | ProtoArray, | ||
int | AdaptProtoThreshold, | ||
int | Debug | ||
) |
Definition at line 545 of file intmatcher.cpp.
{ /* ** Parameters: ** ClassTemplate Prototypes & tables for a class ** ProtoMask AND Mask for proto word ** ConfigMask AND Mask for config word ** BlobLength Length of unormalized blob ** NumFeatures Number of features in blob ** Features Array of features ** ProtoArray Array of good protos ** AdaptProtoThreshold Threshold for good protos ** Debug Debugger flag: 1=debugger on ** Globals: ** local_matcher_multiplier_ Normalization factor multiplier ** Operation: ** FindGoodProtos finds all protos whose normalized proto-evidence ** exceed classify_adapt_proto_thresh. The list is ordered by increasing ** proto id number. ** Return: ** Number of good protos in ProtoArray. ** Exceptions: none ** History: Tue Mar 12 17:09:26 MST 1991, RWM, Created */ ScratchEvidence *tables = new ScratchEvidence(); int NumGoodProtos = 0; /* DEBUG opening heading */ if (MatchDebuggingOn (Debug)) cprintf ("Find Good Protos -------------------------------------------\n"); tables->Clear(ClassTemplate); for (int Feature = 0; Feature < NumFeatures; Feature++) UpdateTablesForFeature( ClassTemplate, ProtoMask, ConfigMask, Feature, &(Features[Feature]), tables, Debug); #ifndef GRAPHICS_DISABLED if (PrintProtoMatchesOn (Debug) || PrintMatchSummaryOn (Debug)) DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables, NumFeatures, Debug); #endif /* Average Proto Evidences & Find Good Protos */ for (int proto = 0; proto < ClassTemplate->NumProtos; proto++) { /* Compute Average for Actual Proto */ int Temp = 0; for (int i = 0; i < ClassTemplate->ProtoLengths[proto]; i++) Temp += tables->proto_evidence_[proto][i]; Temp /= ClassTemplate->ProtoLengths[proto]; /* Find Good Protos */ if (Temp >= AdaptProtoThreshold) { *ProtoArray = proto; ProtoArray++; NumGoodProtos++; } } if (MatchDebuggingOn (Debug)) cprintf ("Match Complete --------------------------------------------\n"); delete tables; return NumGoodProtos; }
void IntegerMatcher::Init | ( | tesseract::IntParam * | classify_debug_level, |
int | classify_integer_matcher_multiplier | ||
) |
Definition at line 695 of file intmatcher.cpp.
{ classify_debug_level_ = classify_debug_level; /* Set default mode of operation of IntegerMatcher */ SetCharNormMatch(classify_integer_matcher_multiplier); /* Initialize table for evidence to similarity lookup */ for (int i = 0; i < SE_TABLE_SIZE; i++) { uinT32 IntSimilarity = i << (27 - SE_TABLE_BITS); double Similarity = ((double) IntSimilarity) / 65536.0 / 65536.0; double evidence = Similarity / kSimilarityCenter; evidence = 255.0 / (evidence * evidence + 1.0); if (kSEExponentialMultiplier > 0.0) { double scale = 1.0 - exp(-kSEExponentialMultiplier) * exp(kSEExponentialMultiplier * ((double) i / SE_TABLE_SIZE)); evidence *= ClipToRange(scale, 0.0, 1.0); } similarity_evidence_table_[i] = (uinT8) (evidence + 0.5); } /* Initialize evidence computation variables */ evidence_table_mask_ = ((1 << kEvidenceTableBits) - 1) << (9 - kEvidenceTableBits); mult_trunc_shift_bits_ = (14 - kIntEvidenceTruncBits); table_trunc_shift_bits_ = (27 - SE_TABLE_BITS - (mult_trunc_shift_bits_ << 1)); evidence_mult_mask_ = ((1 << kIntEvidenceTruncBits) - 1); }
void IntegerMatcher::Match | ( | INT_CLASS | ClassTemplate, |
BIT_VECTOR | ProtoMask, | ||
BIT_VECTOR | ConfigMask, | ||
inT16 | NumFeatures, | ||
const INT_FEATURE_STRUCT * | Features, | ||
INT_RESULT | Result, | ||
int | AdaptFeatureThreshold, | ||
int | Debug, | ||
bool | SeparateDebugWindows | ||
) |
Definition at line 459 of file intmatcher.cpp.
{ /* ** Parameters: ** ClassTemplate Prototypes & tables for a class ** BlobLength Length of unormalized blob ** NumFeatures Number of features in blob ** Features Array of features ** NormalizationFactor Fudge factor from blob ** normalization process ** Result Class rating & configuration: ** (0.0 -> 1.0), 0=good, 1=bad ** Debug Debugger flag: 1=debugger on ** Globals: ** local_matcher_multiplier_ Normalization factor multiplier ** Operation: ** IntegerMatcher returns the best configuration and rating ** for a single class. The class matched against is determined ** by the uniqueness of the ClassTemplate parameter. The ** best rating and its associated configuration are returned. ** Return: ** Exceptions: none ** History: Tue Feb 19 16:36:23 MST 1991, RWM, Created. */ ScratchEvidence *tables = new ScratchEvidence(); int Feature; int BestMatch; if (MatchDebuggingOn (Debug)) cprintf ("Integer Matcher -------------------------------------------\n"); tables->Clear(ClassTemplate); Result->FeatureMisses = 0; for (Feature = 0; Feature < NumFeatures; Feature++) { int csum = UpdateTablesForFeature(ClassTemplate, ProtoMask, ConfigMask, Feature, &Features[Feature], tables, Debug); // Count features that were missed over all configs. if (csum == 0) Result->FeatureMisses++; } #ifndef GRAPHICS_DISABLED if (PrintProtoMatchesOn(Debug) || PrintMatchSummaryOn(Debug)) { DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables, NumFeatures, Debug); } if (DisplayProtoMatchesOn(Debug)) { DisplayProtoDebugInfo(ClassTemplate, ProtoMask, ConfigMask, *tables, SeparateDebugWindows); } if (DisplayFeatureMatchesOn(Debug)) { DisplayFeatureDebugInfo(ClassTemplate, ProtoMask, ConfigMask, NumFeatures, Features, AdaptFeatureThreshold, Debug, SeparateDebugWindows); } #endif tables->UpdateSumOfProtoEvidences(ClassTemplate, ConfigMask, NumFeatures); tables->NormalizeSums(ClassTemplate, NumFeatures, NumFeatures); BestMatch = FindBestMatch(ClassTemplate, *tables, Result); #ifndef GRAPHICS_DISABLED if (PrintMatchSummaryOn(Debug)) DebugBestMatch(BestMatch, Result); if (MatchDebuggingOn(Debug)) cprintf("Match Complete --------------------------------------------\n"); #endif delete tables; }
void IntegerMatcher::SetBaseLineMatch | ( | ) |
Definition at line 727 of file intmatcher.cpp.
{ local_matcher_multiplier_ = 0; }
void IntegerMatcher::SetCharNormMatch | ( | int | integer_matcher_multiplier | ) |
Definition at line 733 of file intmatcher.cpp.
{ local_matcher_multiplier_ = integer_matcher_multiplier; }
const int IntegerMatcher::kEvidenceTableBits = 9 [static] |
Definition at line 95 of file intmatcher.h.
const int IntegerMatcher::kIntEvidenceTruncBits = 14 [static] |
Definition at line 97 of file intmatcher.h.
const int IntegerMatcher::kIntThetaFudge = 128 [static] |
Definition at line 93 of file intmatcher.h.
const float IntegerMatcher::kSEExponentialMultiplier = 0.0 [static] |
Definition at line 99 of file intmatcher.h.
const float IntegerMatcher::kSimilarityCenter = 0.0075 [static] |
Definition at line 101 of file intmatcher.h.