All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
IntegerMatcher Class Reference

#include <intmatcher.h>

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.

96 : 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.

1224  {
1225  return (rating * blob_length +
1226  matcher_multiplier * normalization_factor / 256.0) /
1227  (blob_length + matcher_multiplier);
1228 }
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.

634  {
635  ScratchEvidence *tables = new ScratchEvidence();
636  int NumBadFeatures = 0;
637 
638  /* DEBUG opening heading */
639  if (MatchDebuggingOn(Debug))
640  cprintf("Find Bad Features -------------------------------------------\n");
641 
642  tables->Clear(ClassTemplate);
643 
644  for (int Feature = 0; Feature < NumFeatures; Feature++) {
645  UpdateTablesForFeature(
646  ClassTemplate, ProtoMask, ConfigMask, Feature, &Features[Feature],
647  tables, Debug);
648 
649  /* Find Best Evidence for Current Feature */
650  int best = 0;
651  for (int i = 0; i < ClassTemplate->NumConfigs; i++)
652  if (tables->feature_evidence_[i] > best)
653  best = tables->feature_evidence_[i];
654 
655  /* Find Bad Features */
656  if (best < AdaptFeatureThreshold) {
657  *FeatureArray = Feature;
658  FeatureArray++;
659  NumBadFeatures++;
660  }
661  }
662 
663 #ifndef GRAPHICS_DISABLED
664  if (PrintProtoMatchesOn(Debug) || PrintMatchSummaryOn(Debug))
665  DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables,
666  NumFeatures, Debug);
667 #endif
668 
669  if (MatchDebuggingOn(Debug))
670  cprintf("Match Complete --------------------------------------------\n");
671 
672  delete tables;
673  return NumBadFeatures;
674 }
#define PrintMatchSummaryOn(D)
Definition: intproto.h:198
#define PrintProtoMatchesOn(D)
Definition: intproto.h:202
void Clear(const INT_CLASS class_template)
Definition: intmatcher.cpp:708
#define MatchDebuggingOn(D)
Definition: intproto.h:197
uinT8 feature_evidence_[MAX_NUM_CONFIGS]
Definition: intmatcher.h:70
uinT8 NumConfigs
Definition: intproto.h:110
void cprintf(const char *format,...)
Definition: callcpp.cpp:40
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.

563  {
564  ScratchEvidence *tables = new ScratchEvidence();
565  int NumGoodProtos = 0;
566 
567  /* DEBUG opening heading */
568  if (MatchDebuggingOn (Debug))
569  cprintf
570  ("Find Good Protos -------------------------------------------\n");
571 
572  tables->Clear(ClassTemplate);
573 
574  for (int Feature = 0; Feature < NumFeatures; Feature++)
575  UpdateTablesForFeature(
576  ClassTemplate, ProtoMask, ConfigMask, Feature, &(Features[Feature]),
577  tables, Debug);
578 
579 #ifndef GRAPHICS_DISABLED
580  if (PrintProtoMatchesOn (Debug) || PrintMatchSummaryOn (Debug))
581  DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables,
582  NumFeatures, Debug);
583 #endif
584 
585  /* Average Proto Evidences & Find Good Protos */
586  for (int proto = 0; proto < ClassTemplate->NumProtos; proto++) {
587  /* Compute Average for Actual Proto */
588  int Temp = 0;
589  for (int i = 0; i < ClassTemplate->ProtoLengths[proto]; i++)
590  Temp += tables->proto_evidence_[proto][i];
591 
592  Temp /= ClassTemplate->ProtoLengths[proto];
593 
594  /* Find Good Protos */
595  if (Temp >= AdaptProtoThreshold) {
596  *ProtoArray = proto;
597  ProtoArray++;
598  NumGoodProtos++;
599  }
600  }
601 
602  if (MatchDebuggingOn (Debug))
603  cprintf ("Match Complete --------------------------------------------\n");
604  delete tables;
605 
606  return NumGoodProtos;
607 }
#define PrintMatchSummaryOn(D)
Definition: intproto.h:198
uinT8 proto_evidence_[MAX_NUM_PROTOS][MAX_PROTO_INDEX]
Definition: intmatcher.h:72
#define PrintProtoMatchesOn(D)
Definition: intproto.h:202
void Clear(const INT_CLASS class_template)
Definition: intmatcher.cpp:708
#define MatchDebuggingOn(D)
Definition: intproto.h:197
void cprintf(const char *format,...)
Definition: callcpp.cpp:40
uinT8 * ProtoLengths
Definition: intproto.h:112
uinT16 NumProtos
Definition: intproto.h:108
void IntegerMatcher::Init ( tesseract::IntParam classify_debug_level)

Definition at line 677 of file intmatcher.cpp.

677  {
678  classify_debug_level_ = classify_debug_level;
679 
680  /* Initialize table for evidence to similarity lookup */
681  for (int i = 0; i < SE_TABLE_SIZE; i++) {
682  uinT32 IntSimilarity = i << (27 - SE_TABLE_BITS);
683  double Similarity = ((double) IntSimilarity) / 65536.0 / 65536.0;
684  double evidence = Similarity / kSimilarityCenter;
685  evidence = 255.0 / (evidence * evidence + 1.0);
686 
687  if (kSEExponentialMultiplier > 0.0) {
688  double scale = 1.0 - exp(-kSEExponentialMultiplier) *
689  exp(kSEExponentialMultiplier * ((double) i / SE_TABLE_SIZE));
690  evidence *= ClipToRange(scale, 0.0, 1.0);
691  }
692 
693  similarity_evidence_table_[i] = (uinT8) (evidence + 0.5);
694  }
695 
696  /* Initialize evidence computation variables */
697  evidence_table_mask_ =
698  ((1 << kEvidenceTableBits) - 1) << (9 - kEvidenceTableBits);
699  mult_trunc_shift_bits_ = (14 - kIntEvidenceTruncBits);
700  table_trunc_shift_bits_ = (27 - SE_TABLE_BITS - (mult_trunc_shift_bits_ << 1));
701  evidence_mult_mask_ = ((1 << kIntEvidenceTruncBits) - 1);
702 }
#define SE_TABLE_SIZE
Definition: intmatcher.h:67
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:115
unsigned int uinT32
Definition: host.h:103
static const float kSEExponentialMultiplier
Definition: intmatcher.h:92
static const int kEvidenceTableBits
Definition: intmatcher.h:88
static const float kSimilarityCenter
Definition: intmatcher.h:94
#define SE_TABLE_BITS
Definition: intmatcher.h:66
static const int kIntEvidenceTruncBits
Definition: intmatcher.h:90
unsigned char uinT8
Definition: host.h:99
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.

480  {
481  ScratchEvidence *tables = new ScratchEvidence();
482  int Feature;
483  int BestMatch;
484 
485  if (MatchDebuggingOn (Debug))
486  cprintf ("Integer Matcher -------------------------------------------\n");
487 
488  tables->Clear(ClassTemplate);
489  Result->feature_misses = 0;
490 
491  for (Feature = 0; Feature < NumFeatures; Feature++) {
492  int csum = UpdateTablesForFeature(ClassTemplate, ProtoMask, ConfigMask,
493  Feature, &Features[Feature],
494  tables, Debug);
495  // Count features that were missed over all configs.
496  if (csum == 0)
497  ++Result->feature_misses;
498  }
499 
500 #ifndef GRAPHICS_DISABLED
501  if (PrintProtoMatchesOn(Debug) || PrintMatchSummaryOn(Debug)) {
502  DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables,
503  NumFeatures, Debug);
504  }
505 
506  if (DisplayProtoMatchesOn(Debug)) {
507  DisplayProtoDebugInfo(ClassTemplate, ProtoMask, ConfigMask,
508  *tables, SeparateDebugWindows);
509  }
510 
511  if (DisplayFeatureMatchesOn(Debug)) {
512  DisplayFeatureDebugInfo(ClassTemplate, ProtoMask, ConfigMask, NumFeatures,
513  Features, AdaptFeatureThreshold, Debug,
514  SeparateDebugWindows);
515  }
516 #endif
517 
518  tables->UpdateSumOfProtoEvidences(ClassTemplate, ConfigMask, NumFeatures);
519  tables->NormalizeSums(ClassTemplate, NumFeatures, NumFeatures);
520 
521  BestMatch = FindBestMatch(ClassTemplate, *tables, Result);
522 
523 #ifndef GRAPHICS_DISABLED
524  if (PrintMatchSummaryOn(Debug))
525  Result->Print();
526 
527  if (MatchDebuggingOn(Debug))
528  cprintf("Match Complete --------------------------------------------\n");
529 #endif
530 
531  delete tables;
532 }
void NormalizeSums(INT_CLASS ClassTemplate, inT16 NumFeatures, inT32 used_features)
#define PrintMatchSummaryOn(D)
Definition: intproto.h:198
#define PrintProtoMatchesOn(D)
Definition: intproto.h:202
void UpdateSumOfProtoEvidences(INT_CLASS ClassTemplate, BIT_VECTOR ConfigMask, inT16 NumFeatures)
void Clear(const INT_CLASS class_template)
Definition: intmatcher.cpp:708
#define MatchDebuggingOn(D)
Definition: intproto.h:197
#define DisplayFeatureMatchesOn(D)
Definition: intproto.h:199
void Print() const
Definition: shapetable.h:49
#define DisplayProtoMatchesOn(D)
Definition: intproto.h:200
void cprintf(const char *format,...)
Definition: callcpp.cpp:40

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: