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

📄 intmatcher.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                              ConfigMask,                              NumFeatures,                              Features,                              Debug);#endif  IMUpdateSumOfProtoEvidences(ClassTemplate,                              ConfigMask,                              SumOfFeatureEvidence,                              ProtoEvidence,                              NumFeatures);  IMNormalizeSumOfEvidences(ClassTemplate,                            SumOfFeatureEvidence,                            NumFeatures,                            used_features);  BestMatch =    IMFindBestMatch(ClassTemplate,                    SumOfFeatureEvidence,                    BlobLength,                    NormalizationFactor,                    Result);#ifndef GRAPHICS_DISABLED  if (PrintMatchSummaryOn (Debug))    IMDebugBestMatch(BestMatch, Result, BlobLength, NormalizationFactor);  if (MatchDebuggingOn (Debug))    cprintf ("Match Complete --------------------------------------------\n");#endif}/*---------------------------------------------------------------------------*/int FindGoodProtos(INT_CLASS ClassTemplate,                   BIT_VECTOR ProtoMask,                   BIT_VECTOR ConfigMask,                   UINT16 BlobLength,                   INT16 NumFeatures,                   INT_FEATURE_ARRAY Features,                   PROTO_ID *ProtoArray,                   int Debug) {/* **      Parameters: **              ClassTemplate             Prototypes & tables for a class **              ProtoMask                 AND Mask for proto word **              ConfigMask                AND Mask for config word **              BlobLength                Length of unormalized blob **              NumFeatures               Number of features in blob **              Features                  Array of features **              ProtoArray                Array of good protos **              Debug                     Debugger flag: 1=debugger on **      Globals: **              LocalMatcherMultiplier    Normalization factor multiplier **              IntThetaFudge             Theta fudge factor used for **                                        evidence calculation **              AdaptProtoThresh          Threshold for good protos **      Operation: **              FindGoodProtos finds all protos whose normalized proto-evidence **              exceed AdaptProtoThresh.  The list is ordered by increasing **              proto id number. **      Return: **              Number of good protos in ProtoArray. **      Exceptions: none **      History: Tue Mar 12 17:09:26 MST 1991, RWM, Created */  static UINT8 FeatureEvidence[MAX_NUM_CONFIGS];  static int SumOfFeatureEvidence[MAX_NUM_CONFIGS];  static UINT8 ProtoEvidence[MAX_NUM_PROTOS][MAX_PROTO_INDEX];  int Feature;  register UINT8 *UINT8Pointer;  register int ProtoIndex;  int NumProtos;  int NumGoodProtos;  UINT16 ActualProtoNum;  register int Temp;  /* DEBUG opening heading */  if (MatchDebuggingOn (Debug))    cprintf      ("Find Good Protos -------------------------------------------\n");  IMClearTables(ClassTemplate, SumOfFeatureEvidence, ProtoEvidence);  for (Feature = 0; Feature < NumFeatures; Feature++)    IMUpdateTablesForFeature (ClassTemplate, ProtoMask, ConfigMask, Feature,      &(Features[Feature]), FeatureEvidence,      SumOfFeatureEvidence, ProtoEvidence, Debug);#ifndef GRAPHICS_DISABLED  if (PrintProtoMatchesOn (Debug) || PrintMatchSummaryOn (Debug))    IMDebugFeatureProtoError(ClassTemplate,                             ProtoMask,                             ConfigMask,                             SumOfFeatureEvidence,                             ProtoEvidence,                             NumFeatures,                             Debug);#endif  /* Average Proto Evidences & Find Good Protos */  NumProtos = NumIntProtosIn (ClassTemplate);  NumGoodProtos = 0;  for (ActualProtoNum = 0; ActualProtoNum < NumProtos; ActualProtoNum++) {    /* Compute Average for Actual Proto */    Temp = 0;    UINT8Pointer = &(ProtoEvidence[ActualProtoNum][0]);    for (ProtoIndex = LengthForProtoId (ClassTemplate, ActualProtoNum);      ProtoIndex > 0; ProtoIndex--, UINT8Pointer++)    Temp += *UINT8Pointer;    Temp /= LengthForProtoId (ClassTemplate, ActualProtoNum);    /* Find Good Protos */    if (Temp >= AdaptProtoThresh) {      *ProtoArray = ActualProtoNum;      ProtoArray++;      NumGoodProtos++;    }  }  if (MatchDebuggingOn (Debug))    cprintf ("Match Complete --------------------------------------------\n");  return NumGoodProtos;}/*---------------------------------------------------------------------------*/int FindBadFeatures(INT_CLASS ClassTemplate,                    BIT_VECTOR ProtoMask,                    BIT_VECTOR ConfigMask,                    UINT16 BlobLength,                    INT16 NumFeatures,                    INT_FEATURE_ARRAY Features,                    FEATURE_ID *FeatureArray,                    int Debug) {/* **      Parameters: **              ClassTemplate             Prototypes & tables for a class **              ProtoMask                 AND Mask for proto word **              ConfigMask                AND Mask for config word **              BlobLength                Length of unormalized blob **              NumFeatures               Number of features in blob **              Features                  Array of features **              FeatureArray              Array of bad features **              Debug                     Debugger flag: 1=debugger on **      Globals: **              LocalMatcherMultiplier    Normalization factor multiplier **              IntThetaFudge             Theta fudge factor used for **                                        evidence calculation **              AdaptFeatureThresh        Threshold for bad features **      Operation: **              FindBadFeatures finds all features whose maximum feature-evidence **              was less than AdaptFeatureThresh.  The list is ordered by increasing **              feature number. **      Return: **              Number of bad features in FeatureArray. **      Exceptions: none **      History: Tue Mar 12 17:09:26 MST 1991, RWM, Created */  static UINT8 FeatureEvidence[MAX_NUM_CONFIGS];  static int SumOfFeatureEvidence[MAX_NUM_CONFIGS];  static UINT8 ProtoEvidence[MAX_NUM_PROTOS][MAX_PROTO_INDEX];  int Feature;  register UINT8 *UINT8Pointer;  register int ConfigNum;  int NumConfigs;  int NumBadFeatures;  register int Temp;  /* DEBUG opening heading */  if (MatchDebuggingOn (Debug))    cprintf      ("Find Bad Features -------------------------------------------\n");  IMClearTables(ClassTemplate, SumOfFeatureEvidence, ProtoEvidence);  NumBadFeatures = 0;  NumConfigs = NumIntConfigsIn (ClassTemplate);  for (Feature = 0; Feature < NumFeatures; Feature++) {    IMUpdateTablesForFeature (ClassTemplate, ProtoMask, ConfigMask, Feature,      &(Features[Feature]), FeatureEvidence,      SumOfFeatureEvidence, ProtoEvidence, Debug);    /* Find Best Evidence for Current Feature */    Temp = 0;    UINT8Pointer = FeatureEvidence;    for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++, UINT8Pointer++)      if (*UINT8Pointer > Temp)        Temp = *UINT8Pointer;    /* Find Bad Features */    if (Temp < AdaptFeatureThresh) {      *FeatureArray = Feature;      FeatureArray++;      NumBadFeatures++;    }  }#ifndef GRAPHICS_DISABLED  if (PrintProtoMatchesOn (Debug) || PrintMatchSummaryOn (Debug))    IMDebugFeatureProtoError(ClassTemplate,                             ProtoMask,                             ConfigMask,                             SumOfFeatureEvidence,                             ProtoEvidence,                             NumFeatures,                             Debug);#endif  if (MatchDebuggingOn (Debug))    cprintf ("Match Complete --------------------------------------------\n");  return NumBadFeatures;}/*---------------------------------------------------------------------------*/void InitIntegerMatcher() {  int i;  UINT32 IntSimilarity;  double Similarity;  double Evidence;  double ScaleFactor;  /* Set default mode of operation of IntegerMatcher */  SetCharNormMatch();  /* Initialize table for evidence to similarity lookup */  for (i = 0; i < SE_TABLE_SIZE; i++) {    IntSimilarity = i << (27 - SE_TABLE_BITS);    Similarity = ((double) IntSimilarity) / 65536.0 / 65536.0;    Evidence = Similarity / SimilarityCenter;    Evidence *= Evidence;    Evidence += 1.0;    Evidence = 1.0 / Evidence;    Evidence *= 255.0;    if (SEExponentialMultiplier > 0.0) {      ScaleFactor = 1.0 - exp (-SEExponentialMultiplier) *        exp (SEExponentialMultiplier * ((double) i / SE_TABLE_SIZE));      if (ScaleFactor > 1.0)        ScaleFactor = 1.0;      if (ScaleFactor < 0.0)        ScaleFactor = 0.0;      Evidence *= ScaleFactor;    }    SimilarityEvidenceTable[i] = (UINT8) (Evidence + 0.5);  }  /* Initialize evidence computation variables */  EvidenceTableMask =    ((1 << EvidenceTableBits) - 1) << (9 - EvidenceTableBits);  MultTruncShiftBits = (14 - IntEvidenceTruncBits);  TableTruncShiftBits = (27 - SE_TABLE_BITS - (MultTruncShiftBits << 1));  EvidenceMultMask = ((1 << IntEvidenceTruncBits) - 1);}/*---------------------------------------------------------------------------*/void InitIntegerMatcherVars() {  MakeClassPrunerThreshold();  MakeClassPrunerMultiplier();  MakeIntegerMatcherMultiplier();  MakeIntThetaFudge();  MakeCPCutoffStrength();  MakeEvidenceTableBits();  MakeIntEvidenceTruncBits();  MakeSEExponentialMultiplier();  MakeSimilarityCenter();}/*-------------------------------------------------------------------------*/void PrintIntMatcherStats(FILE *f) {  fprintf (f, "protoword_lookups=%d, zero_protowords=%d, proto_shifts=%d\n",    protoword_lookups, zero_protowords, proto_shifts);  fprintf (f, "set_proto_bits=%d, config_shifts=%d, set_config_bits=%d\n",    set_proto_bits, config_shifts, set_config_bits);}/*-------------------------------------------------------------------------*/void SetProtoThresh(FLOAT32 Threshold) {  AdaptProtoThresh = (int) (255 * Threshold);  if (AdaptProtoThresh < 0)    AdaptProtoThresh = 0;  if (AdaptProtoThresh > 255)    AdaptProtoThresh = 255;}/*---------------------------------------------------------------------------*/void SetFeatureThresh(FLOAT32 Threshold) {  AdaptFeatureThresh = (int) (255 * Threshold);  if (AdaptFeatureThresh < 0)    AdaptFeatureThresh = 0;  if (AdaptFeatureThresh > 255)    AdaptFeatureThresh = 255;}/*--------------------------------------------------------------------------*/void SetBaseLineMatch() {  LocalMatcherMultiplier = 0;}/*--------------------------------------------------------------------------*/void SetCharNormMatch() {  LocalMatcherMultiplier = IntegerMatcherMultiplier;}/**----------------------------------------------------------------------------              Private Code----------------------------------------------------------------------------**//*---------------------------------------------------------------------------*/voidIMClearTables (INT_CLASS ClassTemplate,int SumOfFeatureEvidence[MAX_NUM_CONFIGS],UINT8 ProtoEvidence[MAX_NUM_PROTOS][MAX_PROTO_INDEX]) {/* **      Parameters: **              SumOfFeatureEvidence  Sum of Feature Evidence Table **              NumConfigs            Number of Configurations **              ProtoEvidence         Prototype Evidence Table **              NumProtos             Number of Prototypes **      Globals: **      Operation: **              Clear SumOfFeatureEvidence and ProtoEvidence tables. **      Return: **      Exceptions: none **      History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */  register UINT8 *UINT8Pointer;  register int *IntPointer;  register int ConfigNum;  int NumConfigs;  register UINT16 ProtoNum;  int NumProtos;  register int ProtoIndex;  NumProtos = NumIntProtosIn (ClassTemplate);  NumConfigs = NumIntConfigsIn (ClassTemplate);  IntPointer = SumOfFeatureEvidence;  for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++, IntPointer++)    *IntPointer = 0;

⌨️ 快捷键说明

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