intmatcher.cpp
来自「一个google的OCR源码」· C++ 代码 · 共 1,532 行 · 第 1/4 页
CPP
1,532 行
/*--------------------------------------------------------------------------*/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. */ int NumProtos = NumIntProtosIn (ClassTemplate); int NumConfigs = NumIntConfigsIn (ClassTemplate); memset(SumOfFeatureEvidence, 0, NumConfigs * sizeof(SumOfFeatureEvidence[0])); memset(ProtoEvidence, 0, NumProtos * sizeof(ProtoEvidence[0]));}/*---------------------------------------------------------------------------*/voidIMClearFeatureEvidenceTable (uinT8 FeatureEvidence[MAX_NUM_CONFIGS],int NumConfigs) {/* ** Parameters: ** FeatureEvidence Feature Evidence Table ** NumConfigs Number of Configurations ** Globals: ** Operation: ** Clear FeatureEvidence table. ** Return: ** Exceptions: none ** History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */ memset(FeatureEvidence, 0, NumConfigs * sizeof(*FeatureEvidence));}/*---------------------------------------------------------------------------*/void IMDebugConfiguration(int FeatureNum, uinT16 ActualProtoNum, uinT8 Evidence, BIT_VECTOR ConfigMask, uinT32 ConfigWord) {/* ** Parameters: ** Globals: ** Operation: ** Print debugging information for Configuations ** Return: ** Exceptions: none ** History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */ cprintf ("F = %3d, P = %3d, E = %3d, Configs = ", FeatureNum, (int) ActualProtoNum, (int) Evidence); while (ConfigWord) { if (ConfigWord & 1) cprintf ("1"); else cprintf ("0"); ConfigWord >>= 1; } cprintf ("\n");}/*---------------------------------------------------------------------------*/void IMDebugConfigurationSum(int FeatureNum, uinT8 *FeatureEvidence, inT32 ConfigCount) {/* ** Parameters: ** Globals: ** Operation: ** Print debugging information for Configuations ** Return: ** Exceptions: none ** History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */ int ConfigNum; cprintf ("F=%3d, C=", (int) FeatureNum); for (ConfigNum = 0; ConfigNum < ConfigCount; ConfigNum++) { cprintf ("%4d", FeatureEvidence[ConfigNum]); } cprintf ("\n");}/*---------------------------------------------------------------------------*/intIMUpdateTablesForFeature (INT_CLASS ClassTemplate,BIT_VECTOR ProtoMask,BIT_VECTOR ConfigMask,int FeatureNum,INT_FEATURE Feature,uinT8 FeatureEvidence[MAX_NUM_CONFIGS],int SumOfFeatureEvidence[MAX_NUM_CONFIGS],uinT8ProtoEvidence[MAX_NUM_PROTOS][MAX_PROTO_INDEX],int Debug) {/* ** Parameters: ** ClassTemplate Prototypes & tables for a class ** FeatureNum Current feature number (for DEBUG only) ** Feature Pointer to a feature struct ** FeatureEvidence Feature Evidence Table ** SumOfFeatureEvidence Sum of Feature Evidence Table ** ProtoEvidence Prototype Evidence Table ** Debug Debugger flag: 1=debugger on ** Globals: ** Operation: ** For the given feature: prune protos, compute evidence, update Feature Evidence, ** Proto Evidence, and Sum of Feature Evidence tables. ** Return: ** Exceptions: none ** History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */ register uinT32 ConfigWord; register uinT32 ProtoWord; register uinT32 ProtoNum; register uinT32 ActualProtoNum; uinT8 proto_byte; inT32 proto_word_offset; inT32 proto_offset; uinT8 config_byte; inT32 config_offset; PROTO_SET ProtoSet; uinT32 *ProtoPrunerPtr; INT_PROTO Proto; int ProtoSetIndex; uinT8 Evidence; uinT32 XFeatureAddress; uinT32 YFeatureAddress; uinT32 ThetaFeatureAddress; register uinT8 *UINT8Pointer; register int ProtoIndex; uinT8 Temp; register int *IntPointer; int ConfigNum; register inT32 M3; register inT32 A3; register uinT32 A4; IMClearFeatureEvidenceTable (FeatureEvidence, NumIntConfigsIn (ClassTemplate)); /* Precompute Feature Address offset for Proto Pruning */ XFeatureAddress = ((Feature->X >> 2) << 1); YFeatureAddress = (NUM_PP_BUCKETS << 1) + ((Feature->Y >> 2) << 1); ThetaFeatureAddress = (NUM_PP_BUCKETS << 2) + ((Feature->Theta >> 2) << 1); for (ProtoSetIndex = 0, ActualProtoNum = 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), ActualProtoNum += (PROTOS_PER_PROTO_SET >> 1), ProtoMask++, ProtoPrunerPtr++) { /* Prune Protos of current Proto Set */ ProtoWord = *(ProtoPrunerPtr + XFeatureAddress); ProtoWord &= *(ProtoPrunerPtr + YFeatureAddress); ProtoWord &= *(ProtoPrunerPtr + ThetaFeatureAddress); ProtoWord &= *ProtoMask; if (ProtoWord != 0) { proto_byte = ProtoWord & 0xff; ProtoWord >>= 8; proto_word_offset = 0; while (ProtoWord != 0 || proto_byte != 0) { while (proto_byte == 0) { proto_byte = ProtoWord & 0xff; ProtoWord >>= 8; proto_word_offset += 8; } proto_offset = offset_table[proto_byte] + proto_word_offset; proto_byte = next_table[proto_byte]; Proto = &(ProtoSet->Protos[ProtoNum + proto_offset]); ConfigWord = Proto->Configs[0]; A3 = (((Proto->A * (Feature->X - 128)) << 1) - (Proto->B * (Feature->Y - 128)) + (Proto->C << 9)); M3 = (((inT8) (Feature->Theta - Proto->Angle)) * IntThetaFudge) << 1; if (A3 < 0) A3 = ~A3; if (M3 < 0) M3 = ~M3; A3 >>= MultTruncShiftBits; M3 >>= MultTruncShiftBits; if (A3 > EvidenceMultMask) A3 = EvidenceMultMask; if (M3 > EvidenceMultMask) M3 = EvidenceMultMask; A4 = (A3 * A3) + (M3 * M3); A4 >>= TableTruncShiftBits; if (A4 > EvidenceTableMask) Evidence = 0; else Evidence = SimilarityEvidenceTable[A4]; if (PrintFeatureMatchesOn (Debug)) IMDebugConfiguration (FeatureNum, ActualProtoNum + proto_offset, Evidence, ConfigMask, ConfigWord); ConfigWord &= *ConfigMask; UINT8Pointer = FeatureEvidence - 8; config_byte = 0; while (ConfigWord != 0 || config_byte != 0) { while (config_byte == 0) { config_byte = ConfigWord & 0xff; ConfigWord >>= 8; UINT8Pointer += 8; // config_shifts++; } config_offset = offset_table[config_byte]; config_byte = next_table[config_byte]; if (Evidence > UINT8Pointer[config_offset]) UINT8Pointer[config_offset] = Evidence; } UINT8Pointer = &(ProtoEvidence[ActualProtoNum + proto_offset][0]); for (ProtoIndex = LengthForProtoId (ClassTemplate, ActualProtoNum + proto_offset); ProtoIndex > 0; ProtoIndex--, UINT8Pointer++) { if (Evidence > *UINT8Pointer) { Temp = *UINT8Pointer; *UINT8Pointer = Evidence; Evidence = Temp; } else if (Evidence == 0) break; } } } } } if (PrintFeatureMatchesOn (Debug)) IMDebugConfigurationSum (FeatureNum, FeatureEvidence, NumIntConfigsIn (ClassTemplate)); IntPointer = SumOfFeatureEvidence; UINT8Pointer = FeatureEvidence; int SumOverConfigs = 0; for (ConfigNum = NumIntConfigsIn (ClassTemplate); ConfigNum > 0; ConfigNum--) { int evidence = *UINT8Pointer++; SumOverConfigs += evidence; *IntPointer++ += evidence; } return SumOverConfigs;}/*---------------------------------------------------------------------------*/#ifndef GRAPHICS_DISABLEDvoidIMDebugFeatureProtoError (INT_CLASS ClassTemplate,BIT_VECTOR ProtoMask,BIT_VECTOR ConfigMask,int SumOfFeatureEvidence[MAX_NUM_CONFIGS],uinT8ProtoEvidence[MAX_NUM_PROTOS][MAX_PROTO_INDEX],inT16 NumFeatures, int Debug) {/* ** Parameters: ** Globals: ** Operation: ** Print debugging information for Configuations ** Return: ** Exceptions: none ** History: Wed Feb 27 14:12:28 MST 1991, RWM, Created. */ uinT8 *UINT8Pointer; int *IntPointer; FLOAT32 ProtoConfigs[MAX_NUM_CONFIGS]; int ConfigNum; uinT32 ConfigWord; int ProtoSetIndex; uinT16 ProtoNum; uinT8 ProtoWordNum; PROTO_SET ProtoSet; int ProtoIndex; int NumProtos; uinT16 ActualProtoNum; int Temp; int NumConfigs; NumProtos = NumIntProtosIn (ClassTemplate); NumConfigs = NumIntConfigsIn (ClassTemplate); if (PrintMatchSummaryOn (Debug)) { cprintf ("Configuration Mask:\n"); for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++) cprintf ("%1d", (((*ConfigMask) >> ConfigNum) & 1)); cprintf ("\n"); cprintf ("Feature Error for Configurations:\n"); for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++) cprintf (" %5.1f", 100.0 * (1.0 - (FLOAT32) SumOfFeatureEvidence[ConfigNum] / NumFeatures / 256.0)); cprintf ("\n\n\n"); } if (PrintMatchSummaryOn (Debug)) { cprintf ("Proto Mask:\n"); for (ProtoSetIndex = 0; ProtoSetIndex < NumProtoSetsIn (ClassTemplate); ProtoSetIndex++) { ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET); for (ProtoWordNum = 0; ProtoWordNum < 2; ProtoWordNum++, ProtoMask++) { ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET); for (ProtoNum = 0; ((ProtoNum < (PROTOS_PER_PROTO_SET >> 1)) && (ActualProtoNum < NumProtos)); ProtoNum++, ActualProtoNum++) cprintf ("%1d", (((*ProtoMask) >> ProtoNum) & 1)); cprintf ("\n"); } } cprintf ("\n"); } for (ConfigNum = 0; ConfigNum < NumConfigs; ConfigNum++) ProtoConfigs[ConfigNum] = 0; if (PrintProtoMatchesOn (Debug)) { cprintf ("Proto Evidence:\n"); 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++) { cprintf ("P %3d =", ActualProtoNum); Temp = 0; UINT8Pointer = &(ProtoEvidence[ActualProtoNum][0]); for (ProtoIndex = 0; ProtoIndex < LengthForProtoId (ClassTemplate, ActualProtoNum); ProtoIndex++, UINT8Pointer++) { cprintf (" %d", *UINT8Pointer); Temp += *UINT8Pointer; } cprintf (" = %6.4f%%\n", Temp /
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?