⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adaptmatch.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    (BestChoice)    ||                                 /* old rules */    !EnableNewAdaptRules    &&    BestChoiceLength    ==    strlen    (BestRawChoice)    &&    ((valid_word (BestChoice) && case_ok (BestChoice)) || (valid_number (BestChoice) && pure_number (BestChoice))) && punctuation_ok (BestChoice) != -1 && punctuation_ok (BestChoice) <= 1));}                                /* AdaptableWord *//*---------------------------------------------------------------------------*/void AdaptToChar(TBLOB *Blob,                 LINE_STATS *LineStats,                 CLASS_ID ClassId,                 FLOAT32 Threshold) {/* **							Parameters: **							Blob              blob to add to templates for ClassId**							LineStats              statistics about text line blob is in**							ClassId              class to add blob to**							Threshold              minimum match rating to existing template**							Globals:**							AdaptedTemplates              current set of adapted templates**							AllProtosOn              dummy mask to match against all protos**							AllConfigsOn              dummy mask to match against all configs**							Operation:**							Return: none**							Exceptions: none**							History: Thu Mar 14 09:36:03 1991, DSJ, Created.*/  int NumFeatures;  INT_FEATURE_ARRAY IntFeatures;  INT_RESULT_STRUCT IntResult;  CLASS_INDEX ClassIndex;  INT_CLASS IClass;  ADAPT_CLASS Class;  TEMP_CONFIG TempConfig;  FEATURE_SET FloatFeatures;  NumCharsAdaptedTo++;  if (!LegalClassId (ClassId))    return;  if (UnusedClassIdIn (AdaptedTemplates->Templates, ClassId)) {    MakeNewAdaptedClass(Blob, LineStats, ClassId, AdaptedTemplates);  }  else {    IClass = ClassForClassId (AdaptedTemplates->Templates, ClassId);    ClassIndex = IndexForClassId (AdaptedTemplates->Templates, ClassId);    Class = AdaptedTemplates->Class[ClassIndex];    NumFeatures = GetAdaptiveFeatures (Blob, LineStats,      IntFeatures, &FloatFeatures);    if (NumFeatures <= 0)      return;    SetBaseLineMatch();    IntegerMatcher (IClass, AllProtosOn, AllConfigsOn,      NumFeatures, NumFeatures, IntFeatures, 0, 0,      &IntResult, NO_DEBUG);    SetAdaptiveThreshold(Threshold);    if (IntResult.Rating <= Threshold) {      if (ConfigIsPermanent (Class, IntResult.Config)) {        if (LearningDebugLevel >= 1)          cprintf ("Found good match to perm config %d = %4.1f%%.\n",            IntResult.Config, (1.0 - IntResult.Rating) * 100.0);        FreeFeatureSet(FloatFeatures);        return;      }      TempConfig = TempConfigFor (Class, IntResult.Config);      IncreaseConfidence(TempConfig);      if (LearningDebugLevel >= 1)        cprintf ("Increasing reliability of temp config %d to %d.\n",          IntResult.Config, TempConfig->NumTimesSeen);      if (TempConfigReliable (TempConfig))        MakePermanent (AdaptedTemplates, ClassId, IntResult.Config,          Blob, LineStats);    }    else {      if (LearningDebugLevel >= 1)        cprintf ("Found poor match to temp config %d = %4.1f%%.\n",          IntResult.Config, (1.0 - IntResult.Rating) * 100.0);      MakeNewTemporaryConfig(AdaptedTemplates,                             ClassId,                             NumFeatures,                             IntFeatures,                             FloatFeatures);      if (LearningDebugLevel >= 1) {        IntegerMatcher (IClass, AllProtosOn, AllConfigsOn,          NumFeatures, NumFeatures, IntFeatures, 0, 0,          &IntResult, NO_DEBUG);        cprintf ("Best match to temp config %d = %4.1f%%.\n",          IntResult.Config, (1.0 - IntResult.Rating) * 100.0);        if (LearningDebugLevel >= 2) {          UINT32 ConfigMask;          ConfigMask = 1 << IntResult.Config;          ShowMatchDisplay();          IntegerMatcher (IClass, AllProtosOn, (BIT_VECTOR)&ConfigMask,            NumFeatures, NumFeatures, IntFeatures, 0, 0,            &IntResult, 6 | 0x19);          UpdateMatchDisplay();          GetClassToDebug ("Adapting");        }      }    }    FreeFeatureSet(FloatFeatures);  }}                                /* AdaptToChar *//*---------------------------------------------------------------------------*/void AdaptToPunc(TBLOB *Blob,                 LINE_STATS *LineStats,                 CLASS_ID ClassId,                 FLOAT32 Threshold) {/* **							Parameters: **							Blob              blob to add to templates for ClassId**							LineStats              statistics about text line blob is in**							ClassId              class to add blob to**							Threshold              minimum match rating to existing template**							Globals:**							PreTrainedTemplates              current set of built-in templates**							Operation:**							Return: none**							Exceptions: none**							History: Thu Mar 14 09:36:03 1991, DSJ, Created.*/  ADAPT_RESULTS Results;  int i;  Results.BlobLength = MAX_FLOAT32;  Results.NumMatches = 0;  Results.BestRating = WORST_POSSIBLE_RATING;  Results.BestClass = NO_CLASS;  Results.BestConfig = 0;  InitMatcherRatings (Results.Ratings);  CharNormClassifier(Blob, LineStats, PreTrainedTemplates, &Results);  RemoveBadMatches(&Results);  if (Results.NumMatches != 1) {    if (LearningDebugLevel >= 1) {      cprintf ("Rejecting punc = %c (Alternatives = ", ClassId);      for (i = 0; i < Results.NumMatches; i++)        cprintf ("%c", Results.Classes[i]);      cprintf (")\n");    }    return;  }  #ifndef SECURE_NAMES  if (LearningDebugLevel >= 1)    cprintf ("Adapting to punc = %c\n", ClassId);  #endif  AdaptToChar(Blob, LineStats, ClassId, Threshold);}                                /* AdaptToPunc *//*---------------------------------------------------------------------------*/void AddNewResult(ADAPT_RESULTS *Results,                  CLASS_ID ClassId,                  FLOAT32 Rating,                  int ConfigId) {/* **							Parameters: **							Results              results to add new result to**							ClassId              class of new result**							Rating              rating of new result**							ConfigId              config id of new result**							Globals:**							BadMatchPad              defines limits of an acceptable match**							Operation: This routine adds the result of a classification into**							Results.  If the new rating is much worse than the current**							best rating, it is not entered into results because it**							would end up being stripped later anyway.  If the new rating**							is better than the old rating for the class, it replaces the**							old rating.  If this is the first rating for the class, the**							class is added to the list of matched classes in Results.**							If the new rating is better than the best so far, it**							becomes the best so far.**							Return: none**							Exceptions: none**							History: Tue Mar 12 18:19:29 1991, DSJ, Created.*/  FLOAT32 OldRating;  INT_CLASS_STRUCT* CharClass = NULL;  OldRating = Results->Ratings[ClassId];  if (Rating <= Results->BestRating + BadMatchPad && Rating < OldRating) {    Results->Ratings[ClassId] = Rating;    if (ClassId != NO_CLASS)      CharClass = ClassForClassId(PreTrainedTemplates, ClassId);    if (CharClass != NULL && NumIntConfigsIn(CharClass) == 32)      Results->Configs[ClassId] = ConfigId;    else      Results->Configs[ClassId] = ~0;    if (Rating < Results->BestRating) {      Results->BestRating = Rating;      Results->BestClass = ClassId;      Results->BestConfig = ConfigId;    }    /* if this is first rating for class, add to list of classes matched */    if (OldRating == WORST_POSSIBLE_RATING)      Results->Classes[Results->NumMatches++] = ClassId;  }}                                /* AddNewResult *//*---------------------------------------------------------------------------*/void AmbigClassifier(TBLOB *Blob,                     LINE_STATS *LineStats,                     INT_TEMPLATES Templates,                     char *Ambiguities,                     ADAPT_RESULTS *Results) {/* **							Parameters: **							Blob              blob to be classified**							LineStats              statistics for text line Blob is in**							Templates              built-in templates to classify against**							Ambiguities              string of class id's to match against**							Results              place to put match results**							Globals:**							AllProtosOn              mask that enables all protos**							AllConfigsOn              mask that enables all configs**							Operation: This routine is identical to CharNormClassifier()**							except that it does no class pruning.  It simply matches**							the unknown blob against the classes listed in**							Ambiguities.**							Return: none**							Exceptions: none**							History: Tue Mar 12 19:40:36 1991, DSJ, Created.*/  int IntOutlineLength;  int NumFeatures;  INT_FEATURE_ARRAY IntFeatures;  CLASS_NORMALIZATION_ARRAY CharNormArray;  INT_RESULT_STRUCT IntResult;  CLASS_ID ClassId;  CLASS_INDEX ClassIndex;  AmbigClassifierCalls++;  NumFeatures = GetCharNormFeatures (Blob, LineStats,    Templates,    IntFeatures, CharNormArray,    &(Results->BlobLength));  if (NumFeatures <= 0)    return;  IntOutlineLength = (int) (Results->BlobLength / GetPicoFeatureLength ());  if (MatcherDebugLevel >= 2)    cprintf ("AM Matches =  ");  while (*Ambiguities) {    ClassId = *Ambiguities;    ClassIndex = IndexForClassId (Templates, ClassId);    SetCharNormMatch();    IntegerMatcher (ClassForClassId (Templates, ClassId),      AllProtosOn, AllConfigsOn,      IntOutlineLength, NumFeatures, IntFeatures, 0,      CharNormArray[ClassIndex], &IntResult, NO_DEBUG);    if (MatcherDebugLevel >= 2)      cprintf ("%c-%-2d %2.0f  ", ClassId, IntResult.Config,        IntResult.Rating * 100.0);    AddNewResult (Results, ClassId, IntResult.Rating, IntResult.Config);    Ambiguities++;    NumAmbigClassesTried++;  }  if (MatcherDebugLevel >= 2)    cprintf ("\n");}                                /* AmbigClassifier *//*---------------------------------------------------------------------------*/char *BaselineClassifier(TBLOB *Blob,                         LINE_STATS *LineStats,                         ADAPT_TEMPLATES Templates,                         ADAPT_RESULTS *Results) {/* **							Parameters: **							Blob              blob to be classified**							LineStats              statistics for text line Blob is in**							Templates              current set of adapted templates**							Results              place to put match results**							Globals:**							BaselineCutoffs              expected num features for each class**							Operation: This routine extracts baseline normalized features**							from the unknown character and matches them against the**							specified set of templates.  The classes which match**							are added to Results.**							Return: String of possible ambiguous chars that should be checked.**							Exceptions: none**							History: Tue Mar 12 19:38:03 1991, DSJ, Created.*/  int IntOutlineLength;  int NumFeatures;  int NumClasses;  int i;  int config;  float best_rating;  INT_FEATURE_ARRAY IntFeatures;  CLASS_NORMALIZATION_ARRAY CharNormArray;  CLASS_PRUNER_RESULTS ClassPrunerResults;  INT_RESULT_STRUCT IntResult;  CLASS_ID ClassId;  CLASS_INDEX ClassIndex;  ADAPT_CLASS Class;  BaselineClassifierCalls++;  NumFeatures = GetBaselineFeatures (Blob, LineStats,    Templates->Templates,    IntFeatures, CharNormArray,    &(Results->BlobLength));  if (NumFeatures <= 0)    return NULL;  IntOutlineLength = (int) (Results->BlobLength / GetPicoFeatureLength ());  NumClasses = ClassPruner (Templates->Templates, NumFeatures,    IntFeatures, CharNormArray,    BaselineCutoffs, ClassPrunerResults,    MatchDebugFlags);  NumBaselineClassesTried += NumClasses;  if (MatcherDebugLevel >= 2 || display_ratings > 1)    cprintf ("BL Matches =  ");  best_rating = WORST_POSSIBLE_RATING;  for (i = 0; i < NumClasses    && ((newcp_ratings_on & 12) < 8    || (newcp_ratings_on & 12) == 8    && ClassPrunerResults[i].Rating < best_rating + BadMatchPad / 2    && ClassPrunerResults[i].Rating < newcp_duff_rating  && NumClasses > 1); i++) {    ClassId = ClassPrunerResults[i].Class;    ClassIndex = IndexForClassId (Templates->Templates, ClassId);    SetBaseLineMatch();    IntegerMatcher (ClassForClassId (Templates->Templates, ClassId),      Templates->Class[ClassIndex]->PermProtos,      Templates->Class[ClassIndex]->PermConfigs,      IntOutlineLength, NumFeatures, IntFeatures, 0,      CharNormArray[ClassIndex], &IntResult, MatchDebugFlags);    if (MatcherDebugLevel >= 2 || display_ratings > 1) {      cprintf ("%c-%-2d %2.1f(%2.1f/%2.1f)  ", ClassId, IntResult.Config,        IntResult.Rating * 100.0,        ClassPrunerResults[i].Rating * 100.0,        ClassPrunerResults[i].Rating2 * 100.0);      if (i % 4 == 3)        cprintf ("\n");    }    AddNewResult (Results, ClassId, IntResult.Rating, IntResult.Config);  }  while (i < NumClasses) {    ClassId = ClassPrunerResults[i].Class;    ClassIndex = IndexForClassId (Templates->Templates, ClassId);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -