Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IntegerMatcher Class Reference

#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
 

Detailed Description

Definition at line 90 of file intmatcher.h.

Constructor & Destructor Documentation

IntegerMatcher::IntegerMatcher ( )
inline

Definition at line 103 of file intmatcher.h.

103 : classify_debug_level_(0) {}

Member Function Documentation

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

Definition at line 1285 of file intmatcher.cpp.

1286  {
1287  return (rating * blob_length +
1288  local_matcher_multiplier_ * normalization_factor / 256.0) /
1289  (blob_length + local_matcher_multiplier_);
1290 }
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 625 of file intmatcher.cpp.

634  {
635 /*
636  ** Parameters:
637  ** ClassTemplate Prototypes & tables for a class
638  ** ProtoMask AND Mask for proto word
639  ** ConfigMask AND Mask for config word
640  ** BlobLength Length of unormalized blob
641  ** NumFeatures Number of features in blob
642  ** Features Array of features
643  ** FeatureArray Array of bad features
644  ** AdaptFeatureThreshold Threshold for bad features
645  ** Debug Debugger flag: 1=debugger on
646  ** Operation:
647  ** FindBadFeatures finds all features with maximum feature-evidence <
648  ** AdaptFeatureThresh. The list is ordered by increasing feature number.
649  ** Return:
650  ** Number of bad features in FeatureArray.
651  ** History: Tue Mar 12 17:09:26 MST 1991, RWM, Created
652  */
653  ScratchEvidence *tables = new ScratchEvidence();
654  int NumBadFeatures = 0;
655 
656  /* DEBUG opening heading */
657  if (MatchDebuggingOn(Debug))
658  cprintf("Find Bad Features -------------------------------------------\n");
659 
660  tables->Clear(ClassTemplate);
661 
662  for (int Feature = 0; Feature < NumFeatures; Feature++) {
663  UpdateTablesForFeature(
664  ClassTemplate, ProtoMask, ConfigMask, Feature, &Features[Feature],
665  tables, Debug);
666 
667  /* Find Best Evidence for Current Feature */
668  int best = 0;
669  for (int i = 0; i < ClassTemplate->NumConfigs; i++)
670  if (tables->feature_evidence_[i] > best)
671  best = tables->feature_evidence_[i];
672 
673  /* Find Bad Features */
674  if (best < AdaptFeatureThreshold) {
675  *FeatureArray = Feature;
676  FeatureArray++;
677  NumBadFeatures++;
678  }
679  }
680 
681 #ifndef GRAPHICS_DISABLED
682  if (PrintProtoMatchesOn(Debug) || PrintMatchSummaryOn(Debug))
683  DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables,
684  NumFeatures, Debug);
685 #endif
686 
687  if (MatchDebuggingOn(Debug))
688  cprintf("Match Complete --------------------------------------------\n");
689 
690  delete tables;
691  return NumBadFeatures;
692 }
#define PrintMatchSummaryOn(D)
Definition: intproto.h:190
uinT8 feature_evidence_[MAX_NUM_CONFIGS]
Definition: intmatcher.h:77
uinT8 NumConfigs
Definition: intproto.h:108
#define MatchDebuggingOn(D)
Definition: intproto.h:189
void Clear(const INT_CLASS class_template)
Definition: intmatcher.cpp:742
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
#define PrintProtoMatchesOn(D)
Definition: intproto.h:194
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 546 of file intmatcher.cpp.

555  {
556 /*
557  ** Parameters:
558  ** ClassTemplate Prototypes & tables for a class
559  ** ProtoMask AND Mask for proto word
560  ** ConfigMask AND Mask for config word
561  ** BlobLength Length of unormalized blob
562  ** NumFeatures Number of features in blob
563  ** Features Array of features
564  ** ProtoArray Array of good protos
565  ** AdaptProtoThreshold Threshold for good protos
566  ** Debug Debugger flag: 1=debugger on
567  ** Globals:
568  ** local_matcher_multiplier_ Normalization factor multiplier
569  ** Operation:
570  ** FindGoodProtos finds all protos whose normalized proto-evidence
571  ** exceed classify_adapt_proto_thresh. The list is ordered by increasing
572  ** proto id number.
573  ** Return:
574  ** Number of good protos in ProtoArray.
575  ** Exceptions: none
576  ** History: Tue Mar 12 17:09:26 MST 1991, RWM, Created
577  */
578  ScratchEvidence *tables = new ScratchEvidence();
579  int NumGoodProtos = 0;
580 
581  /* DEBUG opening heading */
582  if (MatchDebuggingOn (Debug))
583  cprintf
584  ("Find Good Protos -------------------------------------------\n");
585 
586  tables->Clear(ClassTemplate);
587 
588  for (int Feature = 0; Feature < NumFeatures; Feature++)
589  UpdateTablesForFeature(
590  ClassTemplate, ProtoMask, ConfigMask, Feature, &(Features[Feature]),
591  tables, Debug);
592 
593 #ifndef GRAPHICS_DISABLED
594  if (PrintProtoMatchesOn (Debug) || PrintMatchSummaryOn (Debug))
595  DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables,
596  NumFeatures, Debug);
597 #endif
598 
599  /* Average Proto Evidences & Find Good Protos */
600  for (int proto = 0; proto < ClassTemplate->NumProtos; proto++) {
601  /* Compute Average for Actual Proto */
602  int Temp = 0;
603  for (int i = 0; i < ClassTemplate->ProtoLengths[proto]; i++)
604  Temp += tables->proto_evidence_[proto][i];
605 
606  Temp /= ClassTemplate->ProtoLengths[proto];
607 
608  /* Find Good Protos */
609  if (Temp >= AdaptProtoThreshold) {
610  *ProtoArray = proto;
611  ProtoArray++;
612  NumGoodProtos++;
613  }
614  }
615 
616  if (MatchDebuggingOn (Debug))
617  cprintf ("Match Complete --------------------------------------------\n");
618  delete tables;
619 
620  return NumGoodProtos;
621 }
#define PrintMatchSummaryOn(D)
Definition: intproto.h:190
uinT8 proto_evidence_[MAX_NUM_PROTOS][MAX_PROTO_INDEX]
Definition: intmatcher.h:79
uinT8 * ProtoLengths
Definition: intproto.h:110
#define MatchDebuggingOn(D)
Definition: intproto.h:189
uinT16 NumProtos
Definition: intproto.h:106
void Clear(const INT_CLASS class_template)
Definition: intmatcher.cpp:742
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
#define PrintProtoMatchesOn(D)
Definition: intproto.h:194
void IntegerMatcher::Init ( tesseract::IntParam classify_debug_level,
int  classify_integer_matcher_multiplier 
)

Definition at line 696 of file intmatcher.cpp.

697  {
698  classify_debug_level_ = classify_debug_level;
699 
700  /* Set default mode of operation of IntegerMatcher */
702 
703  /* Initialize table for evidence to similarity lookup */
704  for (int i = 0; i < SE_TABLE_SIZE; i++) {
705  uinT32 IntSimilarity = i << (27 - SE_TABLE_BITS);
706  double Similarity = ((double) IntSimilarity) / 65536.0 / 65536.0;
707  double evidence = Similarity / kSimilarityCenter;
708  evidence = 255.0 / (evidence * evidence + 1.0);
709 
710  if (kSEExponentialMultiplier > 0.0) {
711  double scale = 1.0 - exp(-kSEExponentialMultiplier) *
712  exp(kSEExponentialMultiplier * ((double) i / SE_TABLE_SIZE));
713  evidence *= ClipToRange(scale, 0.0, 1.0);
714  }
715 
716  similarity_evidence_table_[i] = (uinT8) (evidence + 0.5);
717  }
718 
719  /* Initialize evidence computation variables */
720  evidence_table_mask_ =
721  ((1 << kEvidenceTableBits) - 1) << (9 - kEvidenceTableBits);
722  mult_trunc_shift_bits_ = (14 - kIntEvidenceTruncBits);
723  table_trunc_shift_bits_ = (27 - SE_TABLE_BITS - (mult_trunc_shift_bits_ << 1));
724  evidence_mult_mask_ = ((1 << kIntEvidenceTruncBits) - 1);
725 }
#define SE_TABLE_BITS
Definition: intmatcher.h:73
void SetCharNormMatch(int integer_matcher_multiplier)
Definition: intmatcher.cpp:734
static const float kSEExponentialMultiplier
Definition: intmatcher.h:99
#define SE_TABLE_SIZE
Definition: intmatcher.h:74
int classify_integer_matcher_multiplier
static const int kEvidenceTableBits
Definition: intmatcher.h:95
static const int kIntEvidenceTruncBits
Definition: intmatcher.h:97
static const float kSimilarityCenter
Definition: intmatcher.h:101
unsigned char uinT8
Definition: host.h:99
unsigned int uinT32
Definition: host.h:103
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:64
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 460 of file intmatcher.cpp.

468  {
469 /*
470  ** Parameters:
471  ** ClassTemplate Prototypes & tables for a class
472  ** BlobLength Length of unormalized blob
473  ** NumFeatures Number of features in blob
474  ** Features Array of features
475  ** NormalizationFactor Fudge factor from blob
476  ** normalization process
477  ** Result Class rating & configuration:
478  ** (0.0 -> 1.0), 0=good, 1=bad
479  ** Debug Debugger flag: 1=debugger on
480  ** Globals:
481  ** local_matcher_multiplier_ Normalization factor multiplier
482  ** Operation:
483  ** IntegerMatcher returns the best configuration and rating
484  ** for a single class. The class matched against is determined
485  ** by the uniqueness of the ClassTemplate parameter. The
486  ** best rating and its associated configuration are returned.
487  ** Return:
488  ** Exceptions: none
489  ** History: Tue Feb 19 16:36:23 MST 1991, RWM, Created.
490  */
491  ScratchEvidence *tables = new ScratchEvidence();
492  int Feature;
493  int BestMatch;
494 
495  if (MatchDebuggingOn (Debug))
496  cprintf ("Integer Matcher -------------------------------------------\n");
497 
498  tables->Clear(ClassTemplate);
499  Result->FeatureMisses = 0;
500 
501  for (Feature = 0; Feature < NumFeatures; Feature++) {
502  int csum = UpdateTablesForFeature(ClassTemplate, ProtoMask, ConfigMask,
503  Feature, &Features[Feature],
504  tables, Debug);
505  // Count features that were missed over all configs.
506  if (csum == 0)
507  Result->FeatureMisses++;
508  }
509 
510 #ifndef GRAPHICS_DISABLED
511  if (PrintProtoMatchesOn(Debug) || PrintMatchSummaryOn(Debug)) {
512  DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables,
513  NumFeatures, Debug);
514  }
515 
516  if (DisplayProtoMatchesOn(Debug)) {
517  DisplayProtoDebugInfo(ClassTemplate, ProtoMask, ConfigMask,
518  *tables, SeparateDebugWindows);
519  }
520 
521  if (DisplayFeatureMatchesOn(Debug)) {
522  DisplayFeatureDebugInfo(ClassTemplate, ProtoMask, ConfigMask, NumFeatures,
523  Features, AdaptFeatureThreshold, Debug,
524  SeparateDebugWindows);
525  }
526 #endif
527 
528  tables->UpdateSumOfProtoEvidences(ClassTemplate, ConfigMask, NumFeatures);
529  tables->NormalizeSums(ClassTemplate, NumFeatures, NumFeatures);
530 
531  BestMatch = FindBestMatch(ClassTemplate, *tables, Result);
532 
533 #ifndef GRAPHICS_DISABLED
534  if (PrintMatchSummaryOn(Debug))
535  DebugBestMatch(BestMatch, Result);
536 
537  if (MatchDebuggingOn(Debug))
538  cprintf("Match Complete --------------------------------------------\n");
539 #endif
540 
541  delete tables;
542 }
uinT16 FeatureMisses
Definition: intmatcher.h:45
#define PrintMatchSummaryOn(D)
Definition: intproto.h:190
#define DisplayProtoMatchesOn(D)
Definition: intproto.h:192
void NormalizeSums(INT_CLASS ClassTemplate, inT16 NumFeatures, inT32 used_features)
#define DisplayFeatureMatchesOn(D)
Definition: intproto.h:191
void UpdateSumOfProtoEvidences(INT_CLASS ClassTemplate, BIT_VECTOR ConfigMask, inT16 NumFeatures)
#define MatchDebuggingOn(D)
Definition: intproto.h:189
void Clear(const INT_CLASS class_template)
Definition: intmatcher.cpp:742
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
#define PrintProtoMatchesOn(D)
Definition: intproto.h:194
void IntegerMatcher::SetBaseLineMatch ( )

Definition at line 728 of file intmatcher.cpp.

728  {
729  local_matcher_multiplier_ = 0;
730 }
void IntegerMatcher::SetCharNormMatch ( int  integer_matcher_multiplier)

Definition at line 734 of file intmatcher.cpp.

734  {
735  local_matcher_multiplier_ = integer_matcher_multiplier;
736 }

Member Data Documentation

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.


The documentation for this class was generated from the following files: