classify/adaptmatch.h File Reference

#include "oldlist.h"
#include "tessclas.h"
#include "fxdefs.h"
#include "matchdefs.h"
#include "adaptive.h"
#include "ocrfeatures.h"

Go to the source code of this file.

Functions

Variables


Function Documentation

int AdaptableWord ( TWERD Word,
const char *  BestChoice,
const char *  BestRawChoice 
)

Return TRUE if the specified word is acceptable for adaptation. Rules that apply in general, those simplest to compute come first.

Parameters:
Word current word
BestChoice best overall choice for word with context
BestRawChoice best choice for word without context
Note:
Globals: none
Returns:
TRUE or FALSE
Note:
Exceptions: none
Date:
Thu May 30 14:25:06 1991, DSJ, Created.

Definition at line 1224 of file adaptmatch.cpp.

References ADAPTABLE_WERD, AlternativeChoicesWorseThan(), case_ok(), CurrentBestChoiceAdjustFactor(), CurrentBestChoiceIs(), MAX_ADAPTABLE_WERD_SIZE, NULL, NumBlobsIn(), punctuation_ok(), pure_number(), valid_number(), and valid_word().

Referenced by tess_adaptable_word().

01226                                              {
01227   int BestChoiceLength;
01228 
01229   return
01230    (
01231       /* EnableLearning && */
01232       /* new rules */
01233       BestChoice != NULL
01234       && BestRawChoice != NULL
01235       && Word != NULL
01236       && ( BestChoiceLength = strlen (BestChoice)) > 0
01237       && BestChoiceLength == NumBlobsIn (Word)
01238       && BestChoiceLength <= MAX_ADAPTABLE_WERD_SIZE
01239       && (
01240          /* new rules */
01241          EnableNewAdaptRules
01242          && CurrentBestChoiceAdjustFactor() <= ADAPTABLE_WERD
01243           && AlternativeChoicesWorseThan(ADAPTABLE_WERD)
01244          && CurrentBestChoiceIs(BestChoice)
01245          ||
01246          /* old rules */
01247          !EnableNewAdaptRules
01248          && BestChoiceLength == strlen (BestRawChoice)
01249          && (
01250                (
01251                valid_word (BestChoice)
01252                && case_ok (BestChoice)
01253                )
01254              ||   (
01255                valid_number (BestChoice)
01256                && pure_number (BestChoice)
01257                )
01258             )
01259             && punctuation_ok (BestChoice) != -1
01260             && punctuation_ok (BestChoice) <= 1
01261          )
01262    );
01263 }// AdaptableWord

LIST AdaptiveClassifier ( TBLOB Blob,
TBLOB DotBlob,
TEXTROW Row 
)

Calls the adaptive matcher which returns (in an array) the class id of each class matched.

Parameters:
Blob blob to be classified
DotBlob (obsolete)
Row row of text that word appears in
Note:
Globals: CurrentRatings used by compare function for qsort
Returns:
List of choices found by adaptive matcher.
It also returns the number of classes matched. For each class matched it places the best rating found for that class into the Ratings array. Bad matches are then removed so that they don't need to be sorted. The remaining good matches are then sorted and converted to choices. This routine also performs some simple speckle filtering.

Note:
Exceptions: none
Date:
Mon Mar 11 10:00:58 1991, DSJ, Created.

Definition at line 616 of file adaptmatch.cpp.

References AdaptedTemplates, AddLargeSpeckleTo(), append_choice(), ADAPT_RESULTS::BestClass, ADAPT_RESULTS::BestConfig, ADAPT_RESULTS::BestRating, ADAPT_RESULTS::BlobLength, ADAPT_RESULTS::Classes, CompareCurrentRatings(), ConvertMatchesToChoices(), count(), cprintf(), CurrentRatings, DebugAdaptiveClassifier(), DoAdaptiveMatch(), EnterClassifyMode, f, GetLineStatsFromRow(), InitMatcherRatings(), LargeSpeckle(), MatcherDebugLevel, MAX_FLOAT32, NewAdaptedTemplates(), NIL, NO_CLASS, NULL, NumClassesOutput, ADAPT_RESULTS::NumMatches, PrintAdaptiveMatchResults(), ADAPT_RESULTS::Ratings, RemoveBadMatches(), RemoveExtraPuncs(), and WORST_POSSIBLE_RATING.

Referenced by tess_bn_matcher(), tess_cn_matcher(), and tess_default_matcher().

00616                                                                    { 
00617   LIST Choices;
00618   ADAPT_RESULTS Results;
00619   LINE_STATS LineStats;
00620 
00621   // next 2 lines new for v1.03
00622   if (AdaptedTemplates == NULL)
00623     AdaptedTemplates = NewAdaptedTemplates ();
00624   EnterClassifyMode;
00625 
00626   Results.BlobLength = MAX_FLOAT32;
00627   Results.NumMatches = 0;
00628   Results.BestRating = WORST_POSSIBLE_RATING;
00629   Results.BestClass = NO_CLASS;
00630   Results.BestConfig = 0;
00631   GetLineStatsFromRow(Row, &LineStats);
00632   InitMatcherRatings (Results.Ratings);
00633 
00634   DoAdaptiveMatch(Blob, &LineStats, &Results);
00635   RemoveBadMatches(&Results);
00636 
00637   /* save ratings in a global so that CompareCurrentRatings() can see them */
00638   CurrentRatings = Results.Ratings;
00639   qsort ((void *) (Results.Classes), Results.NumMatches,
00640     sizeof (CLASS_ID), CompareCurrentRatings);
00641   RemoveExtraPuncs(&Results);
00642   Choices = ConvertMatchesToChoices (&Results);
00643 
00644   if (MatcherDebugLevel >= 1) {
00645     cprintf ("AD Matches =  ");
00646     PrintAdaptiveMatchResults(stdout, &Results);
00647   }
00648 
00649   if (LargeSpeckle (Blob, Row))
00650     Choices = AddLargeSpeckleTo (Choices);
00651 
00652 #ifndef GRAPHICS_DISABLED
00653   if (EnableAdaptiveDebugger)
00654     DebugAdaptiveClassifier(Blob, &LineStats, &Results);
00655 #endif
00656 
00657   NumClassesOutput += count (Choices);
00658   if (Choices == NIL) {
00659     if (!bln_numericmode)
00660       printf ("Nil classification!\n");  // Should never normally happen.
00661     return (append_choice (NIL, "", 50.0f, -20.0f, -1));
00662   }
00663 
00664   return (Choices);
00665 
00666 }// AdaptiveClassifier

void AdaptToWord ( TWERD Word,
TEXTROW Row,
const char *  BestChoice,
const char *  BestRawChoice,
const char *  rejmap 
)

Implements a preliminary version of the rules which are used to decide which characters to adapt to.

Parameters:
Word Word to be adapted to
Row Row of text that word is found in
BestChoice Best choice for word found by system
BestRawChoice Best choice for word found by classifier only
rejmap Reject map
Note:
Globals: EnableLearning TRUE if learning is enabled
Returns:
none
A word is adapted to if it is in the dictionary or if it is a "good" number (no trailing units, etc.). It cannot contain broken or merged characters. Within that word, only letters and digits are adapted to (no punctuation).

SPECIAL RULE: Don't adapt to an 'i' which is the first char in a word because they are too ambiguous with 'I'.

The new adaptation rules should account for this automatically, since they exclude ambiguous words from adaptation, but for safety's sake we'll leave the rule in.

Also, don't adapt to i's that have only one blob in them because this creates too much ambiguity for broken characters.

Note:
Exceptions: none
Date:
Thu Mar 14 07:40:36 1991, DSJ, Created.

Definition at line 700 of file adaptmatch.cpp.

References AdaptToChar(), AdaptToPunc(), assert(), wordstruct::blobs, cprintf(), GetAdaptThresholds(), GetLineStatsFromRow(), InitIntFX, LearningDebugLevel, MAX_ADAPTABLE_WERD_SIZE, blobstruct::next, NULL, NumOutlinesInBlob(), and NumWordsAdaptedTo.

Referenced by tess_adapter().

00704                                      {
00705   TBLOB *Blob;
00706   LINE_STATS LineStats;
00707   FLOAT32 Thresholds[MAX_ADAPTABLE_WERD_SIZE];
00708   FLOAT32 *Threshold;
00709   const char *map = rejmap;
00710   char map_char = '1';
00711 
00712   if (EnableLearning) {
00713     NumWordsAdaptedTo++;
00714 
00715     #ifndef SECURE_NAMES
00716     if (LearningDebugLevel >= 1)
00717       cprintf ("\n\nAdapting to word = %s\n", BestChoice);
00718     #endif
00719     GetLineStatsFromRow(Row, &LineStats);
00720 
00721     GetAdaptThresholds(Word,
00722                        &LineStats,
00723                        BestChoice,
00724                        BestRawChoice,
00725                        Thresholds);
00726 
00727     for (Blob = Word->blobs, Threshold = Thresholds;
00728     Blob != NULL; Blob = Blob->next, BestChoice++, Threshold++) {
00729       InitIntFX();
00730 
00731       if (rejmap != NULL)
00732         map_char = *map++;
00733 
00734       assert (map_char == '1' || map_char == '0');
00735 
00736       if (map_char == '1') {
00737 
00738         if (isalnum (*BestChoice)) {
00739           /* Use SPECIAL RULE here */
00740           if ((*BestChoice == 'i'
00741             || il1_adaption_test && *BestChoice == 'I'
00742             && islower (BestChoice[1])) && (Blob == Word->blobs
00743             ||
00744             ispunct (*
00745             (BestChoice -
00746             1))
00747             || !il1_adaption_test
00748             &&
00749             NumOutlinesInBlob
00750           (Blob) != 2)) {
00751             if (LearningDebugLevel >= 1)
00752               cprintf ("Rejecting char = %c\n", *BestChoice);
00753           }
00754           else {
00755             #ifndef SECURE_NAMES
00756             if (LearningDebugLevel >= 1)
00757               cprintf ("Adapting to char = %c, thr= %g\n", *BestChoice, *Threshold);
00758             #endif
00759             AdaptToChar(Blob, &LineStats, *BestChoice, *Threshold);
00760           }
00761         }
00762         else
00763           AdaptToPunc(Blob, &LineStats, *BestChoice, *Threshold);
00764       }
00765     }
00766     if (LearningDebugLevel >= 1)
00767       cprintf ("\n");
00768   }
00769 }                                /* AdaptToWord */

void EndAdaptiveClassifier (  ) 

Performs cleanup operations on the adaptive classifier.

Parameters:
none 
Note:
Globals:
  • AdaptedTemplates current set of adapted templates
  • SaveAdaptedTemplates TRUE if templates should be saved
  • EnableAdaptiveMatcher TRUE if adaptive matcher is enabled
Returns:
none
It should be called before the program is terminated. Its main function is to save the adapted templates to a file.

Finally, free all allocated memory (new for v1.03)

Note:
Exceptions: none
Date:
Tue Mar 19 14:37:06 1991, DSJ, Created.

Definition at line 790 of file adaptmatch.cpp.

References ADAPT_TEMPLATE_SUFFIX, AdaptedTemplates, AllConfigsOff, AllConfigsOn, AllProtosOff, AllProtosOn, cprintf(), EndDangerousAmbigs(), free_int_templates(), FreeBitVector(), FreeNormProtos(), imagefile, NULL, PreTrainedTemplates, PrunedProtos, TempProtoMask, and WriteAdaptedTemplates().

Referenced by dj_cleanup().

00790                              {
00791   char Filename[256];
00792   FILE *File;
00793 
00794   #ifndef SECURE_NAMES
00795   if (EnableAdaptiveMatcher && SaveAdaptedTemplates) {
00796     strcpy(Filename, imagefile);
00797     strcat(Filename, ADAPT_TEMPLATE_SUFFIX);
00798     File = fopen (Filename, "wb");
00799     if (File == NULL)
00800       cprintf ("Unable to save adapted templates to %s!\n", Filename);
00801     else {
00802       cprintf ("\nSaving adapted templates to %s ...", Filename);
00803       fflush(stdout);
00804       WriteAdaptedTemplates(File, AdaptedTemplates);
00805       cprintf ("\n");
00806       fclose(File);
00807     }
00808   }
00809   #endif
00810 
00811   // the following are new for v1.03
00812   EndDangerousAmbigs();
00813   FreeNormProtos();
00814   free_int_templates(PreTrainedTemplates);
00815   PreTrainedTemplates = NULL;
00816   FreeBitVector(AllProtosOn);
00817   FreeBitVector(PrunedProtos);
00818   FreeBitVector(AllConfigsOn);
00819   FreeBitVector(AllProtosOff);
00820   FreeBitVector(AllConfigsOff);
00821   FreeBitVector(TempProtoMask);
00822   AllProtosOn = NULL;
00823   PrunedProtos = NULL;
00824   AllConfigsOn = NULL;
00825   AllProtosOff = NULL;
00826   AllConfigsOff = NULL;
00827   TempProtoMask = NULL;
00828 }// EndAdaptiveClassifier

int GetAdaptiveFeatures ( TBLOB Blob,
LINE_STATS LineStats,
INT_FEATURE_ARRAY  IntFeatures,
FEATURE_SET FloatFeatures 
)

Sets up the feature extractor to extract baseline normalized pico-features.

Parameters:
Blob blob to extract features from
LineStats statistics about text row blob is in
IntFeatures array to fill with integer features
FloatFeatures place to return actual floating-pt features
Note:
Globals: none
Returns:
Number of pico-features returned (0 if an error occurred)
The extracted pico-features are converted to integer form and placed in IntFeatures. The original floating point features are returned in FloatFeatures.
Note:
Exceptions: none
Date:
Tue Mar 12 17:55:18 1991, DSJ, Created.

Definition at line 1185 of file adaptmatch.cpp.

References baseline, ComputeIntFeatures(), ExtractPicoFeatures(), FreeFeatureSet(), NormMethod, NumFeaturesIn, and UNLIKELY_NUM_FEAT.

Referenced by AdaptToChar(), and compare_tess_blobs().

01188                                                     {
01189   FEATURE_SET Features;
01190   int NumFeatures;
01191 
01192   NormMethod = baseline;
01193   Features = ExtractPicoFeatures (Blob, LineStats);
01194 
01195   NumFeatures = NumFeaturesIn (Features);
01196   if (NumFeatures > UNLIKELY_NUM_FEAT) {
01197     FreeFeatureSet(Features);
01198     return (0);
01199   }
01200 
01201   ComputeIntFeatures(Features, IntFeatures);
01202   *FloatFeatures = Features;
01203 
01204   return (NumFeatures);
01205 
01206 }                                /* GetAdaptiveFeatures */

void InitAdaptiveClassifier (  ) 

Reads in the training information needed by the adaptive classifier and saves it into global variables.

Parameters:
none 
Note:
Globals:
  • BuiltInTemplatesFile file to get built-in temps from
  • BuiltInCutoffsFile file to get avg. feat per class from
  • PreTrainedTemplates pre-trained configs and protos
  • AdaptedTemplates templates adapted to current page
  • CharNormCutoffs avg # of features per class
  • AllProtosOn dummy proto mask with all bits 1
  • AllConfigsOn dummy config mask with all bits 1
  • UsePreAdaptedTemplates enables use of pre-adapted templates
Returns:
none
Note:
Exceptions: none
Date:
Mon Mar 11 12:49:34 1991, DSJ, Created.

Definition at line 850 of file adaptmatch.cpp.

References ADAPT_TEMPLATE_SUFFIX, AdaptedTemplates, AllConfigsOff, AllConfigsOn, AllProtosOff, AllProtosOn, BaselineCutoffs, BuiltInCutoffsFile, BuiltInTemplatesFile, CharNormCutoffs, ClassIdForIndex, cprintf(), demodir, Efopen(), GetNormProtos(), imagefile, IndexForClassId, InitIntegerFX(), InitIntegerMatcher(), MAX_NUM_CONFIGS, MAX_NUM_PROTOS, NewAdaptedTemplates(), NewBitVector(), NULL, NumClassesIn, old_enable_learning, PreTrainedTemplates, PrintAdaptedTemplates(), PrunedProtos, ReadAdaptedTemplates(), ReadIntTemplates(), ReadNewCutoffs(), set_all_bits, ADAPT_TEMPLATES_STRUCT::Templates, TempProtoMask, TRUE, WordsInVectorOfSize, and zero_all_bits.

Referenced by mfeature_init().

00850                               {
00851   int i;
00852   FILE *File;
00853   char Filename[1024];
00854 
00855   if (!EnableAdaptiveMatcher)
00856     return;
00857 
00858   strcpy(Filename, demodir);
00859   strcat(Filename, BuiltInTemplatesFile);
00860   #ifndef SECURE_NAMES
00861   //      cprintf( "\nReading built-in templates from %s ...",
00862   //              Filename);
00863   fflush(stdout);
00864   #endif
00865 
00866   #ifdef __UNIX__
00867   File = Efopen (Filename, "r");
00868   #else
00869   File = Efopen (Filename, "rb");
00870   #endif
00871   PreTrainedTemplates = ReadIntTemplates (File, TRUE);
00872   fclose(File);
00873 
00874   strcpy(Filename, demodir);
00875   strcat(Filename, BuiltInCutoffsFile);
00876   #ifndef SECURE_NAMES
00877   //      cprintf( "\nReading built-in pico-feature cutoffs from %s ...",
00878   //              Filename);
00879   fflush(stdout);
00880   #endif
00881   ReadNewCutoffs (Filename, PreTrainedTemplates->IndexFor, CharNormCutoffs);
00882 
00883   GetNormProtos();
00884 
00885   InitIntegerMatcher();
00886   InitIntegerFX();
00887 
00888   AllProtosOn = NewBitVector (MAX_NUM_PROTOS);
00889   PrunedProtos = NewBitVector (MAX_NUM_PROTOS);
00890   AllConfigsOn = NewBitVector (MAX_NUM_CONFIGS);
00891   AllProtosOff = NewBitVector (MAX_NUM_PROTOS);
00892   AllConfigsOff = NewBitVector (MAX_NUM_CONFIGS);
00893   TempProtoMask = NewBitVector (MAX_NUM_PROTOS);
00894   set_all_bits (AllProtosOn, WordsInVectorOfSize (MAX_NUM_PROTOS));
00895   set_all_bits (PrunedProtos, WordsInVectorOfSize (MAX_NUM_PROTOS));
00896   set_all_bits (AllConfigsOn, WordsInVectorOfSize (MAX_NUM_CONFIGS));
00897   zero_all_bits (AllProtosOff, WordsInVectorOfSize (MAX_NUM_PROTOS));
00898   zero_all_bits (AllConfigsOff, WordsInVectorOfSize (MAX_NUM_CONFIGS));
00899 
00900   if (UsePreAdaptedTemplates) {
00901     strcpy(Filename, imagefile);
00902     strcat(Filename, ADAPT_TEMPLATE_SUFFIX);
00903     File = fopen (Filename, "rb");
00904     if (File == NULL)
00905       AdaptedTemplates = NewAdaptedTemplates ();
00906     else {
00907       #ifndef SECURE_NAMES
00908       cprintf ("\nReading pre-adapted templates from %s ...", Filename);
00909       fflush(stdout);
00910       #endif
00911       AdaptedTemplates = ReadAdaptedTemplates (File);
00912       cprintf ("\n");
00913       fclose(File);
00914       PrintAdaptedTemplates(stdout, AdaptedTemplates);
00915 
00916       for (i = 0; i < NumClassesIn (AdaptedTemplates->Templates); i++) {
00917         BaselineCutoffs[i] =
00918           CharNormCutoffs[IndexForClassId (PreTrainedTemplates,
00919           ClassIdForIndex
00920           (AdaptedTemplates->Templates,
00921           i))];
00922       }
00923     }
00924   }
00925   else
00926     AdaptedTemplates = NewAdaptedTemplates ();
00927   old_enable_learning = EnableLearning;
00928 
00929 }                                /* InitAdaptiveClassifier */

void InitAdaptiveClassifierVars (  ) 

Installs the control knobs used by the adaptive matcher.

Parameters:
none 
Note:
Globals: none
Returns:
none
Note:
Exceptions: none
Date:
Mon Mar 11 12:49:34 1991, DSJ, Created.

Definition at line 950 of file adaptmatch.cpp.

References BUILT_IN_CUTOFFS_FILE, BUILT_IN_TEMPLATES_FILE, BuiltInCutoffsFile, BuiltInTemplatesFile, dummy, InitOutlineFXVars(), InitPicoFXVars(), and string_variable.

Referenced by init_dj_debug().

00950                                   {
00951   VALUE dummy;
00952 
00953   string_variable (BuiltInTemplatesFile, "BuiltInTemplatesFile",
00954     BUILT_IN_TEMPLATES_FILE);
00955   string_variable (BuiltInCutoffsFile, "BuiltInCutoffsFile",
00956     BUILT_IN_CUTOFFS_FILE);
00957 
00958   MakeEnableAdaptiveMatcher();
00959   MakeUsePreAdaptedTemplates();
00960   MakeSaveAdaptedTemplates();
00961 
00962   MakeEnableLearning();
00963   MakeEnableAdaptiveDebugger();
00964   MakeBadMatchPad();
00965   MakeGoodAdaptiveMatch();
00966   MakeGreatAdaptiveMatch();
00967   MakeNoiseBlobLength();
00968   MakeMinNumPermClasses();
00969   MakeReliableConfigThreshold();
00970   MakeMaxAngleDelta();
00971   MakeLearningDebugLevel();
00972   MakeMatcherDebugLevel();
00973   MakeMatchDebugFlags();
00974   MakeRatingMargin();
00975   MakePerfectRating();
00976   MakeEnableIntFX();
00977   MakeEnableNewAdaptRules();
00978   MakeRatingScale();
00979   MakeCertaintyScale();
00980 
00981   InitPicoFXVars();
00982   InitOutlineFXVars();  //?
00983 
00984 }                                /* InitAdaptiveClassifierVars */

void MakeNewAdaptedClass ( TBLOB Blob,
LINE_STATS LineStats,
CLASS_ID  ClassId,
ADAPT_TEMPLATES  Templates 
)

Creates a new adapted class and uses Blob as the model for the first config in that class.

Parameters:
Blob blob to model new class after
LineStats statistics for text row blob is in
ClassId id of new class to be created
Templates adapted templates to add new class to
Note:
Globals:
  • AllProtosOn dummy mask with all 1's
  • BaselineCutoffs kludge needed to get cutoffs
  • PreTrainedTemplates kludge needed to get cutoffs
Returns:
none
Note:
Exceptions: none
Date:
Thu Mar 14 12:49:39 1991, DSJ, Created.

Definition at line 1096 of file adaptmatch.cpp.

References AddAdaptedClass(), AddIntConfig(), AddIntProto(), AddProtoToProtoPruner(), AllProtosOn, assert(), baseline, BaselineCutoffs, CharNormCutoffs, ClassForClassId, Config, ConvertConfig(), ConvertProto(), cprintf(), ExtractOutlineFeatures(), FeatureIn, FillABC(), FreeFeatureSet(), IndexForClassId, LearningDebugLevel, NewAdaptedClass(), NewTempConfig(), NewTempProto(), NO_PROTO, NormMethod, NumFeaturesIn, OutlineFeatDir, OutlineFeatLength, OutlineFeatX, OutlineFeatY, ParamOf, PreTrainedTemplates, TEMP_PROTO_STRUCT::Proto, ProtoAngle, TEMP_PROTO_STRUCT::ProtoId, ProtoLength, ProtoX, ProtoY, push(), SET_BIT, TempConfigFor, ADAPT_TEMPLATES_STRUCT::Templates, ADAPT_CLASS_STRUCT::TempProtos, UNLIKELY_NUM_FEAT, and Y_DIM_OFFSET.

Referenced by AdaptToChar(), and compare_tess_blobs().

01099                                                     {
01100   FEATURE_SET Features;
01101   int Fid, Pid;
01102   FEATURE Feature;
01103   int NumFeatures;
01104   TEMP_PROTO TempProto;
01105   PROTO Proto;
01106   ADAPT_CLASS Class;
01107   INT_CLASS IClass;
01108   CLASS_INDEX ClassIndex;
01109   TEMP_CONFIG Config;
01110 
01111   NormMethod = baseline;
01112   Features = ExtractOutlineFeatures (Blob, LineStats);
01113   NumFeatures = NumFeaturesIn (Features);
01114   if (NumFeatures > UNLIKELY_NUM_FEAT) {
01115     FreeFeatureSet(Features);
01116     return;
01117   }
01118 
01119   Class = NewAdaptedClass ();
01120   ClassIndex = AddAdaptedClass (Templates, Class, ClassId);
01121   Config = NewTempConfig (NumFeatures - 1);
01122   TempConfigFor (Class, 0) = Config;
01123 
01124   /* This is a kludge to construct cutoffs for adapted templates */
01125   BaselineCutoffs[ClassIndex] =
01126     CharNormCutoffs[IndexForClassId (PreTrainedTemplates, ClassId)];
01127 
01128   IClass = ClassForClassId (Templates->Templates, ClassId);
01129 
01130   for (Fid = 0; Fid < NumFeaturesIn (Features); Fid++) {
01131     Pid = AddIntProto (IClass);
01132     assert (Pid != NO_PROTO);
01133 
01134     Feature = FeatureIn (Features, Fid);
01135     TempProto = NewTempProto ();
01136     Proto = &(TempProto->Proto);
01137 
01138     /* compute proto params - NOTE that Y_DIM_OFFSET must be used because
01139        ConvertProto assumes that the Y dimension varies from -0.5 to 0.5
01140        instead of the -0.25 to 0.75 used in baseline normalization */
01141     ProtoAngle (Proto) = ParamOf (Feature, OutlineFeatDir);
01142     ProtoX (Proto) = ParamOf (Feature, OutlineFeatX);
01143     ProtoY (Proto) = ParamOf (Feature, OutlineFeatY) - Y_DIM_OFFSET;
01144     ProtoLength (Proto) = ParamOf (Feature, OutlineFeatLength);
01145     FillABC(Proto);
01146 
01147     TempProto->ProtoId = Pid;
01148     SET_BIT (Config->Protos, Pid);
01149 
01150     ConvertProto(Proto, Pid, IClass);
01151     AddProtoToProtoPruner(Proto, Pid, IClass);
01152 
01153     Class->TempProtos = push (Class->TempProtos, TempProto);
01154   }
01155   FreeFeatureSet(Features);
01156 
01157   AddIntConfig(IClass);
01158   ConvertConfig (AllProtosOn, 0, IClass);
01159 
01160   if (LearningDebugLevel >= 1) {
01161     cprintf ("Added new class '%c' with index %d and %d protos.\n",
01162       ClassId, ClassIndex, NumFeatures);
01163   }
01164 
01165 }                                /* MakeNewAdaptedClass */

void PrintAdaptiveStatistics ( FILE *  File  ) 

Print to File the statistics which have been gathered for the adaptive matcher.

Parameters:
File open text file to print adaptive statistics to
Note:
Globals: none
Returns:
none
Note:
Exceptions: none
Date:
Thu Apr 18 14:37:37 1991, DSJ, Created.

Definition at line 998 of file adaptmatch.cpp.

References AdaptedTemplates, AdaptiveMatcherCalls, AmbigClassifierCalls, BaselineClassifierCalls, CharNormClassifierCalls, NumAmbigClassesTried, NumBaselineClassesTried, NumCharNormClassesTried, NumCharsAdaptedTo, NumClassesOutput, NumWordsAdaptedTo, and PrintAdaptedTemplates().

Referenced by dj_statistics().

00998                                          {
00999   #ifndef SECURE_NAMES
01000 
01001   fprintf (File, "\nADAPTIVE MATCHER STATISTICS:\n");
01002   fprintf (File, "\tNum blobs classified = %d\n", AdaptiveMatcherCalls);
01003   fprintf (File, "\tNum classes output   = %d (Avg = %4.2f)\n",
01004     NumClassesOutput,
01005     ((AdaptiveMatcherCalls == 0) ? (0.0) :
01006   ((float) NumClassesOutput / AdaptiveMatcherCalls)));
01007   fprintf (File, "\t\tBaseline Classifier: %4d calls (%4.2f classes/call)\n",
01008     BaselineClassifierCalls,
01009     ((BaselineClassifierCalls == 0) ? (0.0) :
01010   ((float) NumBaselineClassesTried / BaselineClassifierCalls)));
01011   fprintf (File, "\t\tCharNorm Classifier: %4d calls (%4.2f classes/call)\n",
01012     CharNormClassifierCalls,
01013     ((CharNormClassifierCalls == 0) ? (0.0) :
01014   ((float) NumCharNormClassesTried / CharNormClassifierCalls)));
01015   fprintf (File, "\t\tAmbig    Classifier: %4d calls (%4.2f classes/call)\n",
01016     AmbigClassifierCalls,
01017     ((AmbigClassifierCalls == 0) ? (0.0) :
01018   ((float) NumAmbigClassesTried / AmbigClassifierCalls)));
01019 
01020   fprintf (File, "\nADAPTIVE LEARNER STATISTICS:\n");
01021   fprintf (File, "\tNumber of words adapted to: %d\n", NumWordsAdaptedTo);
01022   fprintf (File, "\tNumber of chars adapted to: %d\n", NumCharsAdaptedTo);
01023 
01024   PrintAdaptedTemplates(File, AdaptedTemplates);
01025   #endif
01026 }                                /* PrintAdaptiveStatistics */

void ResetAdaptiveClassifier (  ) 

Free allocated memory and reset templates.

Definition at line 934 of file adaptmatch.cpp.

References AdaptedTemplates, free_adapted_templates(), and NULL.

Referenced by TessBaseAPI::ClearAdaptiveClassifier(), and TessBaseAPI::End().

void SettupPass1 (  ) 

This routine prepares the adaptive matcher for the start of the first pass.

Parameters:
none 
Note:
Globals:
  • EnableLearning set to TRUE by this routine
Returns:
none
Learning is enabled (unless it is disabled for the whole program).
Note:
Exceptions: none
Date:
Mon Apr 15 16:39:29 1991, DSJ, Created.
Note:
This is somewhat redundant, it simply says that if learning is enabled then it will remain enabled on the first pass.
If it is disabled, then it will remain disabled. This is only put here to make it very clear that learning is controlled directly by the global setting of EnableLearning.

Definition at line 1050 of file adaptmatch.cpp.

References old_enable_learning, and SettupStopperPass1().

Referenced by set_pass1().

01050                    {
01051   EnableLearning = old_enable_learning;
01052 
01053   SettupStopperPass1();
01054 
01055 }                                /* SettupPass1 */

void SettupPass2 (  ) 

Prepares the adaptive matcher for the start of the second pass.

Parameters:
none 
Note:
Globals:
  • EnableLearning set to FALSE by this routine
Returns:
none
Further learning is disabled.
Note:
Exceptions: none
Date:
Mon Apr 15 16:39:29 1991, DSJ, Created.

Definition at line 1072 of file adaptmatch.cpp.

References FALSE, and SettupStopperPass2().

Referenced by set_pass2().

01072                    {
01073   EnableLearning = FALSE;
01074   SettupStopperPass2();
01075 
01076 }                                /* SettupPass2 */


Variable Documentation

float GoodAdaptiveMatch

Note:
File: adaptmatch.h
Interface to high-level adaptive matcher
Author:
Dan Johnson
Date:
Mon Mar 11 11:48:48 1991, DSJ, Created.
 **	(c) Copyright Hewlett-Packard Company, 1988.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.

Referenced by GetAdaptThresholds(), set_tess_tweak_vars(), and SetAdaptiveThreshold().

float GreatAdaptiveMatch

Referenced by set_tess_tweak_vars().

int LearningDebugLevel

Referenced by AdaptToChar(), AdaptToPunc(), AdaptToWord(), ConvertProto(), FillPPCircularBits(), FillPPLinearBits(), MakeNewAdaptedClass(), MakeNewTemporaryConfig(), and MakePermanent().

int ReliableConfigThreshold

Referenced by init_tesseract().

int tess_bn_matching

Definition at line 591 of file adaptmatch.cpp.

Referenced by DoAdaptiveMatch(), tess_bn_matcher(), tess_cn_matcher(), tess_default_matcher(), and tess_training_tester().

int tess_cn_matching

Definition at line 590 of file adaptmatch.cpp.

Referenced by DoAdaptiveMatch(), tess_bn_matcher(), tess_cn_matcher(), tess_default_matcher(), and tess_training_tester().


Generated on Wed Feb 28 19:49:18 2007 for Tesseract by  doxygen 1.5.1