tesseract  3.04.00
 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)
 
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 
)

Definition at line 1263 of file intmatcher.cpp.

1265  {
1266  return (rating * blob_length +
1267  matcher_multiplier * normalization_factor / 256.0) /
1268  (blob_length + matcher_multiplier);
1269 }
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 626 of file intmatcher.cpp.

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

Definition at line 547 of file intmatcher.cpp.

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

697  {
698  classify_debug_level_ = classify_debug_level;
699 
700  /* Initialize table for evidence to similarity lookup */
701  for (int i = 0; i < SE_TABLE_SIZE; i++) {
702  uinT32 IntSimilarity = i << (27 - SE_TABLE_BITS);
703  double Similarity = ((double) IntSimilarity) / 65536.0 / 65536.0;
704  double evidence = Similarity / kSimilarityCenter;
705  evidence = 255.0 / (evidence * evidence + 1.0);
706 
707  if (kSEExponentialMultiplier > 0.0) {
708  double scale = 1.0 - exp(-kSEExponentialMultiplier) *
709  exp(kSEExponentialMultiplier * ((double) i / SE_TABLE_SIZE));
710  evidence *= ClipToRange(scale, 0.0, 1.0);
711  }
712 
713  similarity_evidence_table_[i] = (uinT8) (evidence + 0.5);
714  }
715 
716  /* Initialize evidence computation variables */
717  evidence_table_mask_ =
718  ((1 << kEvidenceTableBits) - 1) << (9 - kEvidenceTableBits);
719  mult_trunc_shift_bits_ = (14 - kIntEvidenceTruncBits);
720  table_trunc_shift_bits_ = (27 - SE_TABLE_BITS - (mult_trunc_shift_bits_ << 1));
721  evidence_mult_mask_ = ((1 << kIntEvidenceTruncBits) - 1);
722 }
#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 
)

Definition at line 461 of file intmatcher.cpp.

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