intmatcher.cpp

来自「一个google的OCR源码」· C++ 代码 · 共 1,532 行 · 第 1/4 页

CPP
1,532
字号
          256.0 / LengthForProtoId (ClassTemplate,          ActualProtoNum));        ConfigWord = (ProtoSet->Protos[ProtoNum]).Configs[0];        IntPointer = SumOfFeatureEvidence;        ConfigNum = 0;        while (ConfigWord) {          cprintf ("%5d", ConfigWord & 1 ? Temp : 0);          if (ConfigWord & 1)            ProtoConfigs[ConfigNum] += Temp;          IntPointer++;          ConfigNum++;          ConfigWord >>= 1;        }        cprintf ("\n");      }    }  }  if (PrintMatchSummaryOn (Debug)) {    cprintf ("Proto Error for Configurations:\n");    for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++)      cprintf (" %5.1f",        100.0 * (1.0 -        ProtoConfigs[ConfigNum] /        LengthForConfigId (ClassTemplate,        ConfigNum) / 256.0));    cprintf ("\n\n");  }  if (PrintProtoMatchesOn (Debug)) {    cprintf ("Proto Sum for Configurations:\n");    for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++)      cprintf (" %4.1f", ProtoConfigs[ConfigNum] / 256.0);    cprintf ("\n\n");    cprintf ("Proto Length for Configurations:\n");    for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++)      cprintf (" %4.1f",        (float) LengthForConfigId (ClassTemplate, ConfigNum));    cprintf ("\n\n");  }}/*---------------------------------------------------------------------------*/voidIMDisplayProtoDebugInfo (INT_CLASS ClassTemplate,BIT_VECTOR ProtoMask,BIT_VECTOR ConfigMask,uinT8 ProtoEvidence[MAX_NUM_PROTOS][MAX_PROTO_INDEX],int Debug) {  register uinT8 *UINT8Pointer;  register uinT32 ConfigWord;  register uinT16 ProtoNum;  register uinT16 ActualProtoNum;  PROTO_SET ProtoSet;  int ProtoSetIndex;  int ProtoIndex;  int NumProtos;  register int Temp;  extern ScrollView *IntMatchWindow;  if (IntMatchWindow == NULL) {    IntMatchWindow = c_create_window ("IntMatchWindow", 50, 200,      520, 520,      -130.0, 130.0, -130.0, 130.0);  }  NumProtos = NumIntProtosIn (ClassTemplate);  for (ProtoSetIndex = 0; ProtoSetIndex < NumProtoSetsIn (ClassTemplate);  ProtoSetIndex++) {    ProtoSet = ProtoSetIn (ClassTemplate, ProtoSetIndex);    ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);    for (ProtoNum = 0;      ((ProtoNum < PROTOS_PER_PROTO_SET)    && (ActualProtoNum < NumProtos)); ProtoNum++, 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);      ConfigWord = (ProtoSet->Protos[ProtoNum]).Configs[0];      ConfigWord &= *ConfigMask;      if (ConfigWord) {        /* Update display for current proto */        if (ClipMatchEvidenceOn (Debug)) {          if (Temp < AdaptProtoThresh)            DisplayIntProto (ClassTemplate, ActualProtoNum,              (Temp / 255.0));          else            DisplayIntProto (ClassTemplate, ActualProtoNum,              (Temp / 255.0));        }        else {          DisplayIntProto (ClassTemplate, ActualProtoNum,            (Temp / 255.0));        }      }    }  }}/*---------------------------------------------------------------------------*/void IMDisplayFeatureDebugInfo(INT_CLASS ClassTemplate,                               BIT_VECTOR ProtoMask,                               BIT_VECTOR ConfigMask,                               inT16 NumFeatures,                               INT_FEATURE_ARRAY Features,                               int Debug) {  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;  register int Temp;  IMClearTables(ClassTemplate, SumOfFeatureEvidence, ProtoEvidence);  NumConfigs = NumIntConfigsIn (ClassTemplate);  for (Feature = 0; Feature < NumFeatures; Feature++) {    IMUpdateTablesForFeature (ClassTemplate, ProtoMask, ConfigMask, Feature,      &(Features[Feature]), FeatureEvidence,      SumOfFeatureEvidence, ProtoEvidence, 0);    /* Find Best Evidence for Current Feature */    Temp = 0;    UINT8Pointer = FeatureEvidence;    for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++, UINT8Pointer++)      if (*UINT8Pointer > Temp)        Temp = *UINT8Pointer;    /* Update display for current feature */    if (ClipMatchEvidenceOn (Debug)) {      if (Temp < AdaptFeatureThresh)        DisplayIntFeature (&(Features[Feature]), 0.0);      else        DisplayIntFeature (&(Features[Feature]), 1.0);    }    else {      DisplayIntFeature (&(Features[Feature]), (Temp / 255.0));    }  }}#endif/*---------------------------------------------------------------------------*/voidIMUpdateSumOfProtoEvidences (INT_CLASS ClassTemplate,BIT_VECTOR ConfigMask,int SumOfFeatureEvidence[MAX_NUM_CONFIGS],uinT8ProtoEvidence[MAX_NUM_PROTOS][MAX_PROTO_INDEX],inT16 NumFeatures) {/* **      Parameters: **      Globals: **      Operation: **              Add sum of Proto Evidences into Sum Of Feature Evidence Array **      Return: **      Exceptions: none **      History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */  register uinT8 *UINT8Pointer;  register int *IntPointer;  register uinT32 ConfigWord;  int ProtoSetIndex;  register uinT16 ProtoNum;  PROTO_SET ProtoSet;  register int ProtoIndex;  int NumProtos;  uinT16 ActualProtoNum;  int Temp;  NumProtos = NumIntProtosIn (ClassTemplate);  for (ProtoSetIndex = 0; ProtoSetIndex < NumProtoSetsIn (ClassTemplate);  ProtoSetIndex++) {    ProtoSet = ProtoSetIn (ClassTemplate, ProtoSetIndex);    ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);    for (ProtoNum = 0;      ((ProtoNum < PROTOS_PER_PROTO_SET)    && (ActualProtoNum < NumProtos)); ProtoNum++, ActualProtoNum++) {      Temp = 0;      UINT8Pointer = &(ProtoEvidence[ActualProtoNum][0]);      for (ProtoIndex = LengthForProtoId (ClassTemplate, ActualProtoNum);        ProtoIndex > 0; ProtoIndex--, UINT8Pointer++)      Temp += *UINT8Pointer;      ConfigWord = (ProtoSet->Protos[ProtoNum]).Configs[0];      ConfigWord &= *ConfigMask;      IntPointer = SumOfFeatureEvidence;      while (ConfigWord) {        if (ConfigWord & 1)          *IntPointer += Temp;        IntPointer++;        ConfigWord >>= 1;      }    }  }}/*---------------------------------------------------------------------------*/voidIMNormalizeSumOfEvidences (INT_CLASS ClassTemplate,int SumOfFeatureEvidence[MAX_NUM_CONFIGS],inT16 NumFeatures, inT32 used_features) {/* **      Parameters: **      Globals: **      Operation: **              Normalize Sum of Proto and Feature Evidence by dividing by **              the sum of the Feature Lengths and the Proto Lengths for each **              configuration. **      Return: **      Exceptions: none **      History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */  register int *IntPointer;  register int ConfigNum;  int NumConfigs;  NumConfigs = NumIntConfigsIn (ClassTemplate);  IntPointer = SumOfFeatureEvidence;  for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++, IntPointer++)    *IntPointer = (*IntPointer << 8) /      (NumFeatures + LengthForConfigId (ClassTemplate, ConfigNum));}/*---------------------------------------------------------------------------*/intIMFindBestMatch (INT_CLASS ClassTemplate,int SumOfFeatureEvidence[MAX_NUM_CONFIGS],uinT16 BlobLength,uinT8 NormalizationFactor, INT_RESULT Result) {/* **      Parameters: **      Globals: **      Operation: **              Find the best match for the current class and update the Result **              with the configuration and match rating. **      Return: **              The best normalized sum of evidences **      Exceptions: none **      History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */  register int *IntPointer;  register int ConfigNum;  register int NumConfigs;  register int BestMatch;  register int Best2Match;  NumConfigs = NumIntConfigsIn (ClassTemplate);  /* Find best match */  BestMatch = 0;  Best2Match = 0;  IntPointer = SumOfFeatureEvidence;  for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++, IntPointer++) {    if (display_ratings > 1)      cprintf ("Config %d, rating=%d\n", ConfigNum, *IntPointer);    if (*IntPointer > BestMatch) {      if (BestMatch > 0) {        Result->Config2 = Result->Config;        Best2Match = BestMatch;      }      else        Result->Config2 = ConfigNum;      Result->Config = ConfigNum;      BestMatch = *IntPointer;    }    else if (*IntPointer > Best2Match) {      Result->Config2 = ConfigNum;      Best2Match = *IntPointer;    }  }  /* Compute Certainty Rating */  (*Result).Rating = ((65536.0 - BestMatch) / 65536.0 * BlobLength +    LocalMatcherMultiplier * NormalizationFactor / 256.0) /    (BlobLength + LocalMatcherMultiplier);  return BestMatch;}/*---------------------------------------------------------------------------*/#ifndef GRAPHICS_DISABLEDvoid IMDebugBestMatch(int BestMatch,                      INT_RESULT Result,                      uinT16 BlobLength,                      uinT8 NormalizationFactor) {/* **      Parameters: **      Globals: **      Operation: **              Find the best match for the current class and update the Result **      Return: **      Exceptions: none **      History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */  cprintf ("Rating          = %5.1f%%     Best Config   = %3d\n",    100.0 * ((*Result).Rating), (int) ((*Result).Config));  cprintf    ("Matcher Error   = %5.1f%%     Blob Length   = %3d     Weight = %4.1f%%\n",    100.0 * (65536.0 - BestMatch) / 65536.0, (int) BlobLength,    100.0 * BlobLength / (BlobLength + LocalMatcherMultiplier));  cprintf    ("Char Norm Error = %5.1f%%     Norm Strength = %3d     Weight = %4.1f%%\n",    100.0 * NormalizationFactor / 256.0, LocalMatcherMultiplier,    100.0 * LocalMatcherMultiplier / (BlobLength + LocalMatcherMultiplier));}#endif/*---------------------------------------------------------------------------*/voidHeapSort (int n, register int ra[], register int rb[]) {/* **      Parameters: **              n      Number of elements to sort **              ra     Key array [1..n] **              rb     Index array [1..n] **      Globals: **      Operation: **              Sort Key array in ascending order using heap sort **              algorithm.  Also sort Index array that is tied to **              the key array. **      Return: **      Exceptions: none **      History: Tue Feb 19 10:24:24 MST 1991, RWM, Created. */  register int i, rra, rrb;  int l, j, ir;  l = (n >> 1) + 1;  ir = n;  for (;;) {    if (l > 1) {      rra = ra[--l];      rrb = rb[l];    }    else {      rra = ra[ir];      rrb = rb[ir];      ra[ir] = ra[1];      rb[ir] = rb[1];      if (--ir == 1) {        ra[1] = rra;        rb[1] = rrb;        return;      }    }    i = l;    j = l << 1;    while (j <= ir) {      if (j < ir && ra[j] < ra[j + 1])        ++j;      if (rra < ra[j]) {        ra[i] = ra[j];        rb[i] = rb[j];        j += (i = j);      }      else        j = ir + 1;    }    ra[i] = rra;    rb[i] = rrb;  }}

⌨️ 快捷键说明

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