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

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

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

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

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

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

◆ Init()

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

Definition at line 678 of file intmatcher.cpp.

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

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

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: