tesseract  4.00.00dev
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::IntegerMatcher ( )
inline

Definition at line 96 of file intmatcher.h.

96 : classify_debug_level_(0) {}

Member Function Documentation

◆ ApplyCNCorrection()

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 1216 of file intmatcher.cpp.

1218  {
1219  return (rating * blob_length +
1220  matcher_multiplier * normalization_factor / 256.0) /
1221  (blob_length + matcher_multiplier);
1222 }

◆ FindBadFeatures()

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 627 of file intmatcher.cpp.

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

◆ FindGoodProtos()

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 557 of file intmatcher.cpp.

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

◆ Init()

void IntegerMatcher::Init ( tesseract::IntParam classify_debug_level)

Definition at line 679 of file intmatcher.cpp.

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

◆ Match()

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 475 of file intmatcher.cpp.

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

Member Data Documentation

◆ kEvidenceTableBits

const int IntegerMatcher::kEvidenceTableBits = 9
static

Definition at line 88 of file intmatcher.h.

◆ kIntEvidenceTruncBits

const int IntegerMatcher::kIntEvidenceTruncBits = 14
static

Definition at line 90 of file intmatcher.h.

◆ kIntThetaFudge

const int IntegerMatcher::kIntThetaFudge = 128
static

Definition at line 86 of file intmatcher.h.

◆ kSEExponentialMultiplier

const float IntegerMatcher::kSEExponentialMultiplier = 0.0
static

Definition at line 92 of file intmatcher.h.

◆ kSimilarityCenter

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: