19# include "config_auto.h"
47static const uint8_t offset_table[] = {
48 255, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2,
49 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0,
50 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1,
51 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0,
52 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4,
53 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0,
54 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1,
55 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0,
56 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0};
58static const uint8_t next_table[] = {
59 0, 0, 0, 0x2, 0, 0x4, 0x4, 0x6, 0, 0x8, 0x8, 0x0a, 0x08, 0x0c, 0x0c, 0x0e,
60 0, 0x10, 0x10, 0x12, 0x10, 0x14, 0x14, 0x16, 0x10, 0x18, 0x18, 0x1a, 0x18, 0x1c, 0x1c, 0x1e,
61 0, 0x20, 0x20, 0x22, 0x20, 0x24, 0x24, 0x26, 0x20, 0x28, 0x28, 0x2a, 0x28, 0x2c, 0x2c, 0x2e,
62 0x20, 0x30, 0x30, 0x32, 0x30, 0x34, 0x34, 0x36, 0x30, 0x38, 0x38, 0x3a, 0x38, 0x3c, 0x3c, 0x3e,
63 0, 0x40, 0x40, 0x42, 0x40, 0x44, 0x44, 0x46, 0x40, 0x48, 0x48, 0x4a, 0x48, 0x4c, 0x4c, 0x4e,
64 0x40, 0x50, 0x50, 0x52, 0x50, 0x54, 0x54, 0x56, 0x50, 0x58, 0x58, 0x5a, 0x58, 0x5c, 0x5c, 0x5e,
65 0x40, 0x60, 0x60, 0x62, 0x60, 0x64, 0x64, 0x66, 0x60, 0x68, 0x68, 0x6a, 0x68, 0x6c, 0x6c, 0x6e,
66 0x60, 0x70, 0x70, 0x72, 0x70, 0x74, 0x74, 0x76, 0x70, 0x78, 0x78, 0x7a, 0x78, 0x7c, 0x7c, 0x7e,
67 0, 0x80, 0x80, 0x82, 0x80, 0x84, 0x84, 0x86, 0x80, 0x88, 0x88, 0x8a, 0x88, 0x8c, 0x8c, 0x8e,
68 0x80, 0x90, 0x90, 0x92, 0x90, 0x94, 0x94, 0x96, 0x90, 0x98, 0x98, 0x9a, 0x98, 0x9c, 0x9c, 0x9e,
69 0x80, 0xa0, 0xa0, 0xa2, 0xa0, 0xa4, 0xa4, 0xa6, 0xa0, 0xa8, 0xa8, 0xaa, 0xa8, 0xac, 0xac, 0xae,
70 0xa0, 0xb0, 0xb0, 0xb2, 0xb0, 0xb4, 0xb4, 0xb6, 0xb0, 0xb8, 0xb8, 0xba, 0xb8, 0xbc, 0xbc, 0xbe,
71 0x80, 0xc0, 0xc0, 0xc2, 0xc0, 0xc4, 0xc4, 0xc6, 0xc0, 0xc8, 0xc8, 0xca, 0xc8, 0xcc, 0xcc, 0xce,
72 0xc0, 0xd0, 0xd0, 0xd2, 0xd0, 0xd4, 0xd4, 0xd6, 0xd0, 0xd8, 0xd8, 0xda, 0xd8, 0xdc, 0xdc, 0xde,
73 0xc0, 0xe0, 0xe0, 0xe2, 0xe0, 0xe4, 0xe4, 0xe6, 0xe0, 0xe8, 0xe8, 0xea, 0xe8, 0xec, 0xec, 0xee,
74 0xe0, 0xf0, 0xf0, 0xf2, 0xf0, 0xf4, 0xf4, 0xf6, 0xf0, 0xf8, 0xf8, 0xfa, 0xf8, 0xfc, 0xfc, 0xfe};
86static void HeapSort(
int n,
int ra[],
int rb[]) {
110 if (j < ir && ra[j] < ra[j + 1]) {
141 max_classes_ = max_classes;
144 class_count_ =
new int[rounded_classes_];
145 norm_count_ =
new int[rounded_classes_];
146 sort_key_ =
new int[rounded_classes_ + 1];
147 sort_index_ =
new int[rounded_classes_ + 1];
148 for (
int i = 0;
i < rounded_classes_;
i++) {
151 pruning_threshold_ = 0;
157 delete[] class_count_;
158 delete[] norm_count_;
160 delete[] sort_index_;
167 num_features_ = num_features;
169 for (
int f = 0; f < num_features; ++f) {
178 for (
unsigned pruner_set = 0; pruner_set < num_pruners; ++pruner_set) {
181 const uint32_t *pruner_word_ptr = int_templates->
ClassPruners[pruner_set]->
p[
x][
y][theta];
183 uint32_t pruner_word = *pruner_word_ptr++;
236 for (
int class_id = 0; class_id < max_classes_; ++class_id) {
237 if (num_features_ < expected_num_features[class_id]) {
238 int deficit = expected_num_features[class_id] - num_features_;
239 class_count_[class_id] -=
240 class_count_[class_id] * deficit / (num_features_ * cutoff_strength + deficit);
248 for (
int class_id = 0; class_id < max_classes_; ++class_id) {
250 class_count_[class_id] = 0;
257 for (
int class_id = 0; class_id < max_classes_; ++class_id) {
261 class_count_[class_id] = 0;
271 for (
int class_id = 0; class_id < max_classes_; class_id++) {
272 norm_count_[class_id] =
273 class_count_[class_id] - ((norm_multiplier * normalization_factors[class_id]) >> 8);
279 for (
int class_id = 0; class_id < max_classes_; class_id++) {
280 norm_count_[class_id] = class_count_[class_id];
287 void PruneAndSort(
int pruning_factor,
int keep_this,
bool max_of_non_fragments,
290 for (
int c = 0; c < max_classes_; ++c) {
291 if (norm_count_[c] > max_count &&
297 (!max_of_non_fragments || !unicharset.
get_fragment(c))) {
298 max_count = norm_count_[c];
302 pruning_threshold_ = (max_count * pruning_factor) >> 8;
304 if (pruning_threshold_ < 1) {
305 pruning_threshold_ = 1;
308 for (
int class_id = 0; class_id < max_classes_; class_id++) {
309 if (norm_count_[class_id] >= pruning_threshold_ || class_id == keep_this) {
311 sort_index_[num_classes_] = class_id;
312 sort_key_[num_classes_] = norm_count_[class_id];
317 if (num_classes_ > 1) {
318 HeapSort(num_classes_, sort_key_, sort_index_);
327 int max_num_classes = int_templates->
NumClasses;
328 for (
int f = 0; f < num_features_; ++f) {
330 tprintf(
"F=%3d(%d,%d,%d),", f, feature->
X, feature->
Y, feature->
Theta);
336 for (
int pruner_set = 0; pruner_set < num_pruners; ++pruner_set) {
339 const uint32_t *pruner_word_ptr = int_templates->
ClassPruners[pruner_set]->
p[
x][
y][theta];
341 uint32_t pruner_word = *pruner_word_ptr++;
342 for (
int word_class = 0; word_class < 16 && class_id < max_num_classes;
343 ++word_class, ++class_id) {
344 if (norm_count_[class_id] >= pruning_threshold_) {
358 const uint16_t *expected_num_features,
int norm_multiplier,
359 const uint8_t *normalization_factors)
const {
360 tprintf(
"CP:%d classes, %d features:\n", num_classes_, num_features_);
361 for (
int i = 0;
i < num_classes_; ++
i) {
362 int class_id = sort_index_[num_classes_ -
i];
363 std::string class_string = classify.
ClassIDToDebugStr(int_templates, class_id, 0);
365 "%s:Initial=%d, E=%d, Xht-adj=%d, N=%d, Rat=%.2f\n", class_string.c_str(),
366 class_count_[class_id], expected_num_features[class_id],
367 (norm_multiplier * normalization_factors[class_id]) >> 8, sort_key_[num_classes_ -
i],
376 results->resize(num_classes_);
377 for (
int c = 0; c < num_classes_; ++c) {
378 (*results)[c].Class = sort_index_[num_classes_ - c];
379 (*results)[c].Rating =
380 1.0f - sort_key_[num_classes_ - c] /
400 int rounded_classes_;
402 int pruning_threshold_;
429 const uint8_t *normalization_factors,
430 const uint16_t *expected_num_features,
431 std::vector<CP_RESULT_STRUCT> *results) {
442 if (disable_character_fragments &&
shape_table_ ==
nullptr) {
447 if (normalization_factors !=
nullptr) {
456 if (classify_debug_level > 2) {
457 pruner.
DebugMatch(*
this, int_templates, features);
459 if (classify_debug_level > 1) {
461 classify_class_pruner_multiplier, normalization_factors);
485 bool SeparateDebugWindows) {
490 tprintf(
"Integer Matcher -------------------------------------------\n");
493 tables->Clear(ClassTemplate);
496 for (Feature = 0; Feature < NumFeatures; Feature++) {
497 int csum = UpdateTablesForFeature(ClassTemplate, ProtoMask, ConfigMask, Feature,
498 &Features[Feature], tables, Debug);
505#ifndef GRAPHICS_DISABLED
507 DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables, NumFeatures, Debug);
511 DisplayProtoDebugInfo(ClassTemplate, ConfigMask, *tables, SeparateDebugWindows);
515 DisplayFeatureDebugInfo(ClassTemplate, ProtoMask, ConfigMask, NumFeatures, Features,
516 AdaptFeatureThreshold, Debug, SeparateDebugWindows);
520 tables->UpdateSumOfProtoEvidences(ClassTemplate, ConfigMask);
521 tables->NormalizeSums(ClassTemplate, NumFeatures);
523 FindBestMatch(ClassTemplate, *tables, Result);
525#ifndef GRAPHICS_DISABLED
531 tprintf(
"Match Complete --------------------------------------------\n");
558 int AdaptProtoThreshold,
int Debug) {
560 int NumGoodProtos = 0;
564 tprintf(
"Find Good Protos -------------------------------------------\n");
567 tables->Clear(ClassTemplate);
569 for (
int Feature = 0; Feature < NumFeatures; Feature++) {
570 UpdateTablesForFeature(ClassTemplate, ProtoMask, ConfigMask, Feature, &(Features[Feature]),
574#ifndef GRAPHICS_DISABLED
576 DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables, NumFeatures, Debug);
581 for (
int proto = 0; proto < ClassTemplate->
NumProtos; proto++) {
585 Temp += tables->proto_evidence_[proto][
i];
591 if (Temp >= AdaptProtoThreshold) {
599 tprintf(
"Match Complete --------------------------------------------\n");
603 return NumGoodProtos;
622 int AdaptFeatureThreshold,
int Debug) {
624 int NumBadFeatures = 0;
628 tprintf(
"Find Bad Features -------------------------------------------\n");
631 tables->Clear(ClassTemplate);
633 for (
int Feature = 0; Feature < NumFeatures; Feature++) {
634 UpdateTablesForFeature(ClassTemplate, ProtoMask, ConfigMask, Feature, &Features[Feature],
641 if (tables->feature_evidence_[
i] > best) {
642 best = tables->feature_evidence_[
i];
647 if (best < AdaptFeatureThreshold) {
648 *FeatureArray = Feature;
654#ifndef GRAPHICS_DISABLED
656 DebugFeatureProtoError(ClassTemplate, ProtoMask, ConfigMask, *tables, NumFeatures, Debug);
661 tprintf(
"Match Complete --------------------------------------------\n");
665 return NumBadFeatures;
669 : classify_debug_level_(classify_debug_level) {
673 double Similarity = (
static_cast<double>(IntSimilarity)) / 65536.0 / 65536.0;
675 evidence = 255.0 / (evidence * evidence + 1.0);
684 similarity_evidence_table_[
i] =
static_cast<uint8_t
>(evidence + 0.5);
690 table_trunc_shift_bits_ = (27 -
SE_TABLE_BITS - (mult_trunc_shift_bits_ << 1));
709static void IMDebugConfiguration(
int FeatureNum, uint16_t ActualProtoNum, uint8_t Evidence,
710 uint32_t ConfigWord) {
711 tprintf(
"F = %3d, P = %3d, E = %3d, Configs = ", FeatureNum,
static_cast<int>(ActualProtoNum),
712 static_cast<int>(Evidence));
714 if (ConfigWord & 1) {
727static void IMDebugConfigurationSum(
int FeatureNum, uint8_t *FeatureEvidence, int32_t ConfigCount) {
728 tprintf(
"F=%3d, C=", FeatureNum);
729 for (
int ConfigNum = 0; ConfigNum < ConfigCount; ConfigNum++) {
730 tprintf(
"%4d", FeatureEvidence[ConfigNum]);
746int IntegerMatcher::UpdateTablesForFeature(INT_CLASS_STRUCT *ClassTemplate,
BIT_VECTOR ProtoMask,
748 const INT_FEATURE_STRUCT *Feature,
749 ScratchEvidence *tables,
int Debug) {
753 uint32_t ActualProtoNum;
755 int32_t proto_word_offset;
756 int32_t proto_offset;
757 PROTO_SET_STRUCT *ProtoSet;
758 uint32_t *ProtoPrunerPtr;
759 INT_PROTO_STRUCT *Proto;
762 uint32_t XFeatureAddress;
763 uint32_t YFeatureAddress;
764 uint32_t ThetaFeatureAddress;
766 tables->ClearFeatureEvidence(ClassTemplate);
769 XFeatureAddress = ((Feature->X >> 2) << 1);
770 YFeatureAddress = (
NUM_PP_BUCKETS << 1) + ((Feature->Y >> 2) << 1);
771 ThetaFeatureAddress = (
NUM_PP_BUCKETS << 2) + ((Feature->Theta >> 2) << 1);
773 for (ProtoSetIndex = 0, ActualProtoNum = 0; ProtoSetIndex < ClassTemplate->NumProtoSets;
775 ProtoSet = ClassTemplate->ProtoSets[ProtoSetIndex];
776 ProtoPrunerPtr =
reinterpret_cast<uint32_t *
>((*ProtoSet).ProtoPruner);
780 ProtoWord = *(ProtoPrunerPtr + XFeatureAddress);
781 ProtoWord &= *(ProtoPrunerPtr + YFeatureAddress);
782 ProtoWord &= *(ProtoPrunerPtr + ThetaFeatureAddress);
783 ProtoWord &= *ProtoMask;
785 if (ProtoWord != 0) {
786 proto_byte = ProtoWord & 0xff;
788 proto_word_offset = 0;
789 while (ProtoWord != 0 || proto_byte != 0) {
790 while (proto_byte == 0) {
791 proto_byte = ProtoWord & 0xff;
793 proto_word_offset += 8;
795 proto_offset = offset_table[proto_byte] + proto_word_offset;
796 proto_byte = next_table[proto_byte];
797 Proto = &(ProtoSet->Protos[ProtoNum + proto_offset]);
798 ConfigWord = Proto->Configs[0];
799 int32_t A3 = (((Proto->A * (Feature->X - 128)) * 2) - (Proto->B * (Feature->Y - 128)) +
801 int32_t M3 = ((
static_cast<int8_t
>(Feature->Theta - Proto->Angle)) *
kIntThetaFudge) * 2;
809 A3 >>= mult_trunc_shift_bits_;
810 M3 >>= mult_trunc_shift_bits_;
811 if (
static_cast<uint32_t
>(A3) > evidence_mult_mask_) {
812 A3 = evidence_mult_mask_;
814 if (
static_cast<uint32_t
>(M3) > evidence_mult_mask_) {
815 M3 = evidence_mult_mask_;
818 uint32_t A4 = (A3 * A3) + (M3 * M3);
819 A4 >>= table_trunc_shift_bits_;
820 if (A4 > evidence_table_mask_) {
823 Evidence = similarity_evidence_table_[A4];
827 IMDebugConfiguration(FeatureNum, ActualProtoNum + proto_offset, Evidence, ConfigWord);
830 ConfigWord &= *ConfigMask;
832 uint8_t feature_evidence_index = 0;
833 uint8_t config_byte = 0;
834 while (ConfigWord != 0 || config_byte != 0) {
835 while (config_byte == 0) {
836 config_byte = ConfigWord & 0xff;
838 feature_evidence_index += 8;
840 const uint8_t config_offset = offset_table[config_byte] + feature_evidence_index - 8;
841 config_byte = next_table[config_byte];
842 if (Evidence > tables->feature_evidence_[config_offset]) {
843 tables->feature_evidence_[config_offset] = Evidence;
847 uint8_t ProtoIndex = ClassTemplate->ProtoLengths[ActualProtoNum + proto_offset];
853 uint8_t *UINT8Pointer = &(tables->proto_evidence_[ActualProtoNum + proto_offset][0]);
854 for (; Evidence > 0 && ProtoIndex > 0; ProtoIndex--, UINT8Pointer++) {
855 if (Evidence > *UINT8Pointer) {
856 uint8_t Temp = *UINT8Pointer;
857 *UINT8Pointer = Evidence;
867 IMDebugConfigurationSum(FeatureNum, tables->feature_evidence_, ClassTemplate->NumConfigs);
870 int *IntPointer = tables->sum_feature_evidence_;
871 uint8_t *UINT8Pointer = tables->feature_evidence_;
872 int SumOverConfigs = 0;
873 for (
int ConfigNum = ClassTemplate->NumConfigs; ConfigNum > 0; ConfigNum--) {
874 int evidence = *UINT8Pointer++;
875 SumOverConfigs += evidence;
876 *IntPointer++ += evidence;
878 return SumOverConfigs;
884#ifndef GRAPHICS_DISABLED
885void IntegerMatcher::DebugFeatureProtoError(INT_CLASS_STRUCT *ClassTemplate,
BIT_VECTOR ProtoMask,
886 BIT_VECTOR ConfigMask,
const ScratchEvidence &tables,
887 int16_t NumFeatures,
int Debug) {
893 uint8_t ProtoWordNum;
894 PROTO_SET_STRUCT *ProtoSet;
895 uint16_t ActualProtoNum;
898 tprintf(
"Configuration Mask:\n");
899 for (ConfigNum = 0; ConfigNum < ClassTemplate->NumConfigs; ConfigNum++) {
900 tprintf(
"%1d", (((*ConfigMask) >> ConfigNum) & 1));
904 tprintf(
"Feature Error for Configurations:\n");
905 for (ConfigNum = 0; ConfigNum < ClassTemplate->NumConfigs; ConfigNum++) {
906 tprintf(
" %5.1f", 100.0 * (1.0 -
static_cast<float>(tables.sum_feature_evidence_[ConfigNum]) /
907 NumFeatures / 256.0));
914 for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->NumProtoSets; ProtoSetIndex++) {
916 for (ProtoWordNum = 0; ProtoWordNum < 2; ProtoWordNum++, ProtoMask++) {
919 (ActualProtoNum < ClassTemplate->NumProtos));
920 ProtoNum++, ActualProtoNum++) {
921 tprintf(
"%1d", (((*ProtoMask) >> ProtoNum) & 1));
929 for (
int i = 0;
i < ClassTemplate->NumConfigs;
i++) {
935 for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->NumProtoSets; ProtoSetIndex++) {
936 ProtoSet = ClassTemplate->ProtoSets[ProtoSetIndex];
940 ProtoNum++, ActualProtoNum++) {
941 tprintf(
"P %3d =", ActualProtoNum);
943 for (uint8_t j = 0; j < ClassTemplate->ProtoLengths[ActualProtoNum]; j++) {
944 uint8_t data = tables.proto_evidence_[ActualProtoNum][j];
949 tprintf(
" = %6.4f%%\n", temp / 256.0 / ClassTemplate->ProtoLengths[ActualProtoNum]);
951 ConfigWord = ProtoSet->Protos[ProtoNum].Configs[0];
954 tprintf(
"%5d", ConfigWord & 1 ? temp : 0);
955 if (ConfigWord & 1) {
956 ProtoConfigs[ConfigNum] += temp;
967 tprintf(
"Proto Error for Configurations:\n");
968 for (ConfigNum = 0; ConfigNum < ClassTemplate->NumConfigs; ConfigNum++) {
969 tprintf(
" %5.1f", 100.0 * (1.0 - ProtoConfigs[ConfigNum] /
970 ClassTemplate->ConfigLengths[ConfigNum] / 256.0));
976 tprintf(
"Proto Sum for Configurations:\n");
977 for (ConfigNum = 0; ConfigNum < ClassTemplate->NumConfigs; ConfigNum++) {
978 tprintf(
" %4.1f", ProtoConfigs[ConfigNum] / 256.0);
982 tprintf(
"Proto Length for Configurations:\n");
983 for (ConfigNum = 0; ConfigNum < ClassTemplate->NumConfigs; ConfigNum++) {
984 tprintf(
" %4.1f",
static_cast<float>(ClassTemplate->ConfigLengths[ConfigNum]));
990void IntegerMatcher::DisplayProtoDebugInfo(INT_CLASS_STRUCT *ClassTemplate,
BIT_VECTOR ConfigMask,
991 const ScratchEvidence &tables,
992 bool SeparateDebugWindows) {
994 uint16_t ActualProtoNum;
995 PROTO_SET_STRUCT *ProtoSet;
999 if (SeparateDebugWindows) {
1004 for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->NumProtoSets; ProtoSetIndex++) {
1005 ProtoSet = ClassTemplate->ProtoSets[ProtoSetIndex];
1009 ProtoNum++, ActualProtoNum++) {
1012 for (uint8_t
i = 0;
i < ClassTemplate->ProtoLengths[ActualProtoNum];
i++) {
1013 temp += tables.proto_evidence_[ActualProtoNum][
i];
1016 temp /= ClassTemplate->ProtoLengths[ActualProtoNum];
1018 if ((ProtoSet->Protos[ProtoNum]).Configs[0] & (*ConfigMask)) {
1025void IntegerMatcher::DisplayFeatureDebugInfo(INT_CLASS_STRUCT *ClassTemplate,
BIT_VECTOR ProtoMask,
1027 const INT_FEATURE_STRUCT *Features,
1028 int AdaptFeatureThreshold,
int Debug,
1029 bool SeparateDebugWindows) {
1030 auto *tables =
new ScratchEvidence();
1032 tables->Clear(ClassTemplate);
1035 if (SeparateDebugWindows) {
1040 for (
int Feature = 0; Feature < NumFeatures; Feature++) {
1041 UpdateTablesForFeature(ClassTemplate, ProtoMask, ConfigMask, Feature, &Features[Feature],
1048 if (tables->feature_evidence_[
i] > best) {
1049 best = tables->feature_evidence_[
i];
1055 if (best < AdaptFeatureThreshold) {
1074 uint32_t ConfigWord;
1079 uint16_t ActualProtoNum;
1083 for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->
NumProtoSets; ProtoSetIndex++) {
1084 ProtoSet = ClassTemplate->
ProtoSets[ProtoSetIndex];
1087 ProtoNum++, ActualProtoNum++) {
1095 ConfigWord &= *ConfigMask;
1097 while (ConfigWord) {
1098 if (ConfigWord & 1) {
1099 *IntPointer += temp;
1129 result->
fonts.clear();
1136 if (*classify_debug_level_ > 2) {
1137 tprintf(
"Config %d, rating=%d\n", c, rating);
1139 if (rating > best_match) {
1141 best_match = rating;
1143 result->
fonts.emplace_back(c, rating);
1147 result->
rating = best_match / 65536.0f;
1157 int matcher_multiplier) {
1158 int divisor = blob_length + matcher_multiplier;
1161 : (rating * blob_length + matcher_multiplier * normalization_factor / 256.0f) /
#define MatchDebuggingOn(D)
#define PrintFeatureMatchesOn(D)
#define PrintMatchSummaryOn(D)
#define CLASS_PRUNER_CLASS_MASK
#define DisplayFeatureMatchesOn(D)
#define DisplayProtoMatchesOn(D)
#define WERDS_PER_CP_VECTOR
#define PROTOS_PER_PROTO_SET
#define ClipMatchEvidenceOn(D)
#define NUM_BITS_PER_CLASS
#define PrintProtoMatchesOn(D)
void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, float Evidence)
void tprintf(const char *format,...)
void InitIntMatchWindowIfReqd()
void InitFeatureDisplayWindowIfReqd()
int RoundUp(int n, int block_size)
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
void DisplayIntProto(INT_CLASS_STRUCT *Class, PROTO_ID ProtoId, float Evidence)
void InitProtoDisplayWindowIfReqd()
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
bool get_enabled(UNICHAR_ID unichar_id) const
int PruneClasses(const INT_TEMPLATES_STRUCT *int_templates, int num_features, int keep_this, const INT_FEATURE_STRUCT *features, const uint8_t *normalization_factors, const uint16_t *expected_num_features, std::vector< CP_RESULT_STRUCT > *results)
ShapeTable * shape_table_
std::string ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, int class_id, int config_id) const
void SummarizeResult(const Classify &classify, const INT_TEMPLATES_STRUCT *int_templates, const uint16_t *expected_num_features, int norm_multiplier, const uint8_t *normalization_factors) const
void AdjustForExpectedNumFeatures(const uint16_t *expected_num_features, int cutoff_strength)
void NormalizeForXheight(int norm_multiplier, const uint8_t *normalization_factors)
void DisableFragments(const UNICHARSET &unicharset)
void ComputeScores(const INT_TEMPLATES_STRUCT *int_templates, int num_features, const INT_FEATURE_STRUCT *features)
ClassPruner(int max_classes)
void PruneAndSort(int pruning_factor, int keep_this, bool max_of_non_fragments, const UNICHARSET &unicharset)
int SetupResults(std::vector< CP_RESULT_STRUCT > *results) const
void DebugMatch(const Classify &classify, const INT_TEMPLATES_STRUCT *int_templates, const INT_FEATURE_STRUCT *features) const
void DisableDisabledClasses(const UNICHARSET &unicharset)
void NormalizeSums(INT_CLASS_STRUCT *ClassTemplate, int16_t NumFeatures)
void UpdateSumOfProtoEvidences(INT_CLASS_STRUCT *ClassTemplate, BIT_VECTOR ConfigMask)
void ClearFeatureEvidence(const INT_CLASS_STRUCT *class_template)
uint8_t feature_evidence_[MAX_NUM_CONFIGS]
uint8_t proto_evidence_[MAX_NUM_PROTOS][MAX_PROTO_INDEX]
void Clear(const INT_CLASS_STRUCT *class_template)
int sum_feature_evidence_[MAX_NUM_CONFIGS]
static const int kIntThetaFudge
void Match(INT_CLASS_STRUCT *ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, int16_t NumFeatures, const INT_FEATURE_STRUCT *Features, tesseract::UnicharRating *Result, int AdaptFeatureThreshold, int Debug, bool SeparateDebugWindows)
static const int kEvidenceTableBits
int FindBadFeatures(INT_CLASS_STRUCT *ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, int16_t NumFeatures, INT_FEATURE_ARRAY Features, FEATURE_ID *FeatureArray, int AdaptFeatureThreshold, int Debug)
static const float kSEExponentialMultiplier
float ApplyCNCorrection(float rating, int blob_length, int normalization_factor, int matcher_multiplier)
int FindGoodProtos(INT_CLASS_STRUCT *ClassTemplate, BIT_VECTOR ProtoMask, BIT_VECTOR ConfigMask, int16_t NumFeatures, INT_FEATURE_ARRAY Features, PROTO_ID *ProtoArray, int AdaptProtoThreshold, int Debug)
static const float kSimilarityCenter
static const int kIntEvidenceTruncBits
IntegerMatcher(tesseract::IntParam *classify_debug_level)
uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
uint32_t Configs[WERDS_PER_CONFIG_VEC]
INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET]
PROTO_SET_STRUCT * ProtoSets[MAX_NUM_PROTO_SETS]
uint16_t ConfigLengths[MAX_NUM_CONFIGS]
std::vector< uint8_t > ProtoLengths
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
std::vector< ScoredFont > fonts