tesseract 3.04.01

IntegerMatcher Class Reference

#include <intmatcher.h>

List of all members.

Public Member Functions

 IntegerMatcher ()
void Init (tesseract::IntParam *classify_debug_level)
void Match (INT_CLASS ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, inT16 NumFeatures, const INT_FEATURE_STRUCT *Features, tesseract::UnicharRating *Result, int AdaptFeatureThreshold, int Debug, bool SeparateDebugWindows)
float ApplyCNCorrection (float rating, int blob_length, int normalization_factor, int matcher_multiplier)
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

Detailed Description

Definition at line 83 of file intmatcher.h.


Constructor & Destructor Documentation

IntegerMatcher::IntegerMatcher ( ) [inline]

Definition at line 96 of file intmatcher.h.

: classify_debug_level_(0) {}

Member Function Documentation

float IntegerMatcher::ApplyCNCorrection ( float  rating,
int  blob_length,
int  normalization_factor,
int  matcher_multiplier 
)

Applies the CN normalization factor to the given rating and returns the modified rating.

Definition at line 1222 of file intmatcher.cpp.

                                                                {
  return (rating * blob_length +
          matcher_multiplier * normalization_factor / 256.0) /
      (blob_length + 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 
)

FindBadFeatures finds all features with maximum feature-evidence < AdaptFeatureThresh. The list is ordered by increasing feature number.

Parameters:
ClassTemplatePrototypes & tables for a class
ProtoMaskAND Mask for proto word
ConfigMaskAND Mask for config word
BlobLengthLength of unormalized blob
NumFeaturesNumber of features in blob
FeaturesArray of features
FeatureArrayArray of bad features
AdaptFeatureThresholdThreshold for bad features
DebugDebugger flag: 1=debugger on
Returns:
Number of bad features in FeatureArray.
Note:
History: Tue Mar 12 17:09:26 MST 1991, RWM, Created

Definition at line 625 of file intmatcher.cpp.

               {
  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 
)

FindGoodProtos finds all protos whose normalized proto-evidence exceed classify_adapt_proto_thresh. The list is ordered by increasing proto id number.

Globals:

  • local_matcher_multiplier_ Normalization factor multiplier param ClassTemplate Prototypes & tables for a class param ProtoMask AND Mask for proto word param ConfigMask AND Mask for config word param BlobLength Length of unormalized blob param NumFeatures Number of features in blob param Features Array of features param ProtoArray Array of good protos param AdaptProtoThreshold Threshold for good protos param Debug Debugger flag: 1=debugger on
    Returns:
    Number of good protos in ProtoArray.
    Note:
    Exceptions: none
    History: Tue Mar 12 17:09:26 MST 1991, RWM, Created

Definition at line 554 of file intmatcher.cpp.

               {
  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)

Definition at line 677 of file intmatcher.cpp.

                                                                 {
  classify_debug_level_ = classify_debug_level;

  /* 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,
tesseract::UnicharRating Result,
int  AdaptFeatureThreshold,
int  Debug,
bool  SeparateDebugWindows 
)

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.

Globals:

  • local_matcher_multiplier_ Normalization factor multiplier param ClassTemplate Prototypes & tables for a class param BlobLength Length of unormalized blob param NumFeatures Number of features in blob param Features Array of features param NormalizationFactor Fudge factor from blob normalization process param Result Class rating & configuration: (0.0 -> 1.0), 0=bad, 1=good param Debug Debugger flag: 1=debugger on
    Returns:
    none
    Note:
    Exceptions: none
    History: Tue Feb 19 16:36:23 MST 1991, RWM, Created.

Definition at line 472 of file intmatcher.cpp.

                                                      {
  ScratchEvidence *tables = new ScratchEvidence();
  int Feature;
  int BestMatch;

  if (MatchDebuggingOn (Debug))
    cprintf ("Integer Matcher -------------------------------------------\n");

  tables->Clear(ClassTemplate);
  Result->feature_misses = 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->feature_misses;
  }

#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))
    Result->Print();

  if (MatchDebuggingOn(Debug))
    cprintf("Match Complete --------------------------------------------\n");
#endif

  delete tables;
}

Member Data Documentation

const int IntegerMatcher::kEvidenceTableBits = 9 [static]

Definition at line 88 of file intmatcher.h.

const int IntegerMatcher::kIntEvidenceTruncBits = 14 [static]

Definition at line 90 of file intmatcher.h.

const int IntegerMatcher::kIntThetaFudge = 128 [static]

Definition at line 86 of file intmatcher.h.

const float IntegerMatcher::kSEExponentialMultiplier = 0.0 [static]

Definition at line 92 of file intmatcher.h.

const float IntegerMatcher::kSimilarityCenter = 0.0075 [static]

Definition at line 94 of file intmatcher.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines