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

📄 adaptmatch.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    Class = Templates->Class[ClassIndex];    config =      NumIntConfigsIn (ClassForIndex (Templates->Templates, ClassIndex));    for (config--; config >= 0 && !ConfigIsPermanent (Class, config);      config--);    if (MatcherDebugLevel >= 2 || display_ratings > 1) {      cprintf ("%c(%d) %2.1f(%2.1f)  ", ClassId, config,        ClassPrunerResults[i].Rating * 200.0,        ClassPrunerResults[i].Rating2 * 100.0);      if (i % 4 == 3)        cprintf ("\n");    }    AddNewResult (Results, ClassId, ClassPrunerResults[i].Rating * 2,      config);    i++;  }  if (MatcherDebugLevel >= 2 || display_ratings > 1)    cprintf ("\n");  ClassId = Results->BestClass;  if (ClassId == NO_CLASS)    return (NULL);  /* this is a bug - maybe should return "" */  ClassIndex = IndexForClassId (Templates->Templates, ClassId);  return ((char *) (Templates->Class[ClassIndex]->    Config[Results->BestConfig].Perm));}                                /* BaselineClassifier *//*---------------------------------------------------------------------------*/void make_config_pruner(INT_TEMPLATES templates,                        CONFIG_PRUNER *config_pruner) {  int classid;  int x;                         //feature coord  int word_index;                //in faster version  int bit_index;  UINT32 XFeatureAddress;  UINT32 YFeatureAddress;  UINT32 ThetaFeatureAddress;  INT_CLASS ClassTemplate;  int ProtoSetIndex;  PROTO_SET ProtoSet;  UINT32 *ProtoPrunerPtr;  UINT32 ProtoNum;  INT32 proto_offset;  UINT32 ConfigWord;  UINT32 ProtoWord;  INT_PROTO Proto;  UINT32 x_config_mask;          //forming mask  UINT32 y_config_mask;          //forming mask  UINT32 th_config_mask;         //forming mask  for (classid = 0; classid < NumClassesIn (templates); classid++) {    ClassTemplate = ClassForIndex (templates, classid);    for (x = 0; x < NUM_PP_BUCKETS; x++) {      XFeatureAddress = (x << 1);      YFeatureAddress = (NUM_PP_BUCKETS << 1) + (x << 1);      ThetaFeatureAddress = (NUM_PP_BUCKETS << 2) + (x << 1);      x_config_mask = 0;      y_config_mask = 0;      th_config_mask = 0;      for (ProtoSetIndex = 0;        ProtoSetIndex < NumProtoSetsIn (ClassTemplate);      ProtoSetIndex++) {        ProtoSet = ProtoSetIn (ClassTemplate, ProtoSetIndex);        ProtoPrunerPtr = (UINT32 *) ((*ProtoSet).ProtoPruner);        for (ProtoNum = 0; ProtoNum < PROTOS_PER_PROTO_SET;        ProtoNum += (PROTOS_PER_PROTO_SET >> 1), ProtoPrunerPtr++) {          /* Prune Protos of current Proto Set */          ProtoWord = *(ProtoPrunerPtr + XFeatureAddress);          for (proto_offset = 0; ProtoWord != 0;          proto_offset++, ProtoWord >>= 1) {            if (ProtoWord & 1) {              Proto =                &(ProtoSet->Protos[ProtoNum + proto_offset]);              ConfigWord = Proto->Configs[0];              x_config_mask |= ConfigWord;            }          }          ProtoWord = *(ProtoPrunerPtr + YFeatureAddress);          for (proto_offset = 0; ProtoWord != 0;          proto_offset++, ProtoWord >>= 1) {            if (ProtoWord & 1) {              Proto =                &(ProtoSet->Protos[ProtoNum + proto_offset]);              ConfigWord = Proto->Configs[0];              y_config_mask |= ConfigWord;            }          }          ProtoWord = *(ProtoPrunerPtr + ThetaFeatureAddress);          for (proto_offset = 0; ProtoWord != 0;          proto_offset++, ProtoWord >>= 1) {            if (ProtoWord & 1) {              Proto =                &(ProtoSet->Protos[ProtoNum + proto_offset]);              ConfigWord = Proto->Configs[0];              th_config_mask |= ConfigWord;            }          }        }      }      for (word_index = 0; word_index < 4; word_index++) {        ConfigWord = 0;        for (bit_index = 0; bit_index < 8; bit_index++) {          if (x_config_mask & 1)            ConfigWord |= 1 << (bit_index * 4);          x_config_mask >>= 1;        }        config_pruner[classid][0][x][word_index] = ConfigWord;        ConfigWord = 0;        for (bit_index = 0; bit_index < 8; bit_index++) {          if (y_config_mask & 1)            ConfigWord |= 1 << (bit_index * 4);          y_config_mask >>= 1;        }        config_pruner[classid][1][x][word_index] = ConfigWord;        ConfigWord = 0;        for (bit_index = 0; bit_index < 8; bit_index++) {          if (th_config_mask & 1)            ConfigWord |= 1 << (bit_index * 4);          th_config_mask >>= 1;        }        config_pruner[classid][2][x][word_index] = ConfigWord;      }    }  }}/*---------------------------------------------------------------------------*/void CharNormClassifier(TBLOB *Blob,                        LINE_STATS *LineStats,                        INT_TEMPLATES Templates,                        ADAPT_RESULTS *Results) {/* **							Parameters: **							Blob              blob to be classified**							LineStats              statistics for text line Blob is in**							Templates              templates to classify unknown against**							Results              place to put match results**							Globals:**							CharNormCutoffs              expected num features for each class**							AllProtosOn              mask that enables all protos**							AllConfigsOn              mask that enables all configs**							Operation: This routine extracts character normalized features**							from the unknown character and matches them against the**							specified set of templates.  The classes which match**							are added to Results.**							Return: none**							Exceptions: none**							History: Tue Mar 12 16:02:52 1991, DSJ, Created.*/  int IntOutlineLength;  int NumFeatures;  int NumClasses;  int i;  INT32 min_misses;  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;  CharNormClassifierCalls++;  NumFeatures = GetCharNormFeatures (Blob, LineStats,    Templates,    IntFeatures, CharNormArray,    &(Results->BlobLength));  if (NumFeatures <= 0)    return;  IntOutlineLength = (int) (Results->BlobLength / GetPicoFeatureLength ());  NumClasses = ClassPruner (Templates, NumFeatures,    IntFeatures, CharNormArray,    CharNormCutoffs, ClassPrunerResults,    MatchDebugFlags);  if (feature_prune_percentile > 0) {    min_misses = feature_pruner (Templates, NumFeatures,      IntFeatures, NumClasses,      ClassPrunerResults);    NumClasses =      prune_configs(Templates,                    min_misses,                    NumFeatures,                    IntFeatures,                    CharNormArray,                    NumClasses,                    IntOutlineLength,                    ClassPrunerResults,                    MatchDebugFlags);  }  else    min_misses = 0;  if (tessedit_single_match && NumClasses > 1)    NumClasses = 1;  NumCharNormClassesTried += NumClasses;  if (MatcherDebugLevel >= 2 || display_ratings > 1)    cprintf ("CN Matches =  ");  best_rating = WORST_POSSIBLE_RATING;  for (i = 0; i < NumClasses    && ((newcp_ratings_on & 3) < 2    || (newcp_ratings_on & 3) == 2    && ClassPrunerResults[i].Rating < best_rating + BadMatchPad / 2    && ClassPrunerResults[i].Rating < newcp_duff_rating  && NumClasses > 1); i++) {    ClassId = ClassPrunerResults[i].Class;    ClassIndex = IndexForClassId (Templates, ClassId);    SetCharNormMatch();    if (feature_prune_percentile > 0)                                 //xiaofan      config_mask_to_proto_mask (ClassForClassId (Templates, ClassId), (BIT_VECTOR) & ClassPrunerResults[i].config_mask,        PrunedProtos);                                 //xiaofan    IntegerMatcher (ClassForClassId (Templates, ClassId), PrunedProtos, (BIT_VECTOR) & ClassPrunerResults[i].config_mask,      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);    if (IntResult.Rating < best_rating)      best_rating = IntResult.Rating;  }  while (i < NumClasses) {    ClassId = ClassPrunerResults[i].Class;    ClassIndex = IndexForClassId (Templates, ClassId);    if (MatcherDebugLevel >= 2 || display_ratings > 1) {      cprintf ("%c %2.1f(%2.1f)  ", ClassId,        ClassPrunerResults[i].Rating * 200.0,        ClassPrunerResults[i].Rating2 * 100.0);      if (i % 4 == 3)        cprintf ("\n");    }    AddNewResult (Results, ClassId, ClassPrunerResults[i].Rating * 2, 0);    i++;  }  if (MatcherDebugLevel >= 2 || display_ratings > 1)    cprintf ("\n");}                                /* CharNormClassifier *//*---------------------------------------------------------------------------*/void ClassifyAsNoise(TBLOB *Blob,                     LINE_STATS *LineStats,                     ADAPT_RESULTS *Results) {/* **							Parameters: **							Blob              blob to be classified**							LineStats              statistics for text line Blob is in**							Results              results to add noise classification to**							Globals:**							NoiseBlobLength              avg. length of a noise blob**							Operation: This routine computes a rating which reflects the**							likelihood that the blob being classified is a noise**							blob.  NOTE: assumes that the blob length has already been**							computed and placed into Results.**							Return: none**							Exceptions: none**							History: Tue Mar 12 18:36:52 1991, DSJ, Created.*/  register FLOAT32 Rating;  Rating = Results->BlobLength / NoiseBlobLength;  Rating *= Rating;  Rating /= 1.0 + Rating;  AddNewResult (Results, NO_CLASS, Rating, 0);}                                /* ClassifyAsNoise *//*---------------------------------------------------------------------------*/int CompareCurrentRatings(                     //CLASS_ID              *Class1,                          const void *arg1,                          const void *arg2) {  //CLASS_ID              *Class2)/* **							Parameters: **							Class1, Class2              classes whose ratings are to be compared**							Globals:**							CurrentRatings              contains actual ratings for each class**							Operation: This routine gets the ratings for the 2 specified classes**							from a global variable (CurrentRatings) and returns:**			-1 if Rating1 < Rating2**							0 if Rating1 = Rating2**							1 if Rating1 > Rating2**							Return: Order of classes based on their ratings (see above).**							Exceptions: none**							History: Tue Mar 12 14:18:31 1991, DSJ, Created.*/  FLOAT32 Rating1, Rating2;  CLASS_ID *Class1 = (CLASS_ID *) arg1;  CLASS_ID *Class2 = (CLASS_ID *) arg2;  Rating1 = CurrentRatings[*Class1];  Rating2 = CurrentRatings[*Class2];  if (Rating1 < Rating2)    return (-1);  else if (Rating1 > Rating2)    return (1);  else    return (0);}                                /* CompareCurrentRatings *//*---------------------------------------------------------------------------*/LIST ConvertMatchesToChoices(ADAPT_RESULTS *Results) {/* **							Parameters: **							Results              adaptive matcher results to convert to choices**							Globals: none**							Operation: This routine creates a choice for each matching class**							in Results (up to MAX_MATCHES) and returns a list of**							these choices.  The match**							ratings are converted to be the ratings and certainties**							as used by the context checkers.**							Return: List of choices.**							Exceptions: none**							History: Tue Mar 12 08:55:37 1991, DSJ, Created.*/  char ChoiceString[2];  int i;  LIST Choices;  CLASS_ID NextMatch;  FLOAT32 Rating;  FLOAT32 Certainty;  ChoiceString[1] = '\0';  if (Results->NumMatches > MAX_MATCHES)    Results->NumMatches = MAX_MATCHES;  for (Choices = NIL, i = 0; i < Results->NumMatches; i++) {    NextMatch = Results->Classes[i];    ChoiceString[0] = NextMatch;    Rating = Certainty = Results->Ratings[NextMatch];    Rating *= RatingScale * Results->BlobLength;    Certainty *= -CertaintyScale;    Choices = append_choice (Choices, ChoiceString, Rating, Certainty,      Results->Configs[NextMatch]);  }  return (Choices);}                                /* ConvertMatchesToChoices *//*---------------------------------------------------------------------------*/#ifndef GRAPHICS_DISABLEDvoid DebugAdaptiveClassifier(TBLOB *Blob,                             LINE_STATS *LineStats,                             ADAPT_RESULTS *Results) {/* **							Parameters: **							Blob              blob whose classification is being debugged**							LineStats              statistics for text line blob is in**							Results              results of match being debugged**							Globals: none**							Operation:**							Return: none**							Exceptions: none**							History: Wed Mar 13 16:44:41 1991, DSJ, Created.

⌨️ 快捷键说明

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