21 #include "config_auto.h" 31 #ifndef DISABLED_LEGACY_ENGINE 40 #ifndef DISABLED_LEGACY_ENGINE 63 TBOX &selection_box) {
79 int16_t good_char_qual;
84 if (lstm_recognizer_ ==
nullptr) {
85 #ifndef DISABLED_LEGACY_ENGINE 87 #endif // ndef DISABLED_LEGACY_ENGINE 91 #ifndef DISABLED_LEGACY_ENGINE 95 tprintf(
"\n%d chars; word_blob_quality: %d; outline_errs: %d; " 96 "char_quality: %d; good_char_quality: %d\n",
101 #endif // ndef DISABLED_LEGACY_ENGINE 121 const TBOX& target_word_box,
122 const char* word_config,
124 if (word_config !=
nullptr) {
126 if (backup_config_file_ ==
nullptr) {
128 FILE* config_fp = fopen(backup_config_file_,
"wb");
129 if (config_fp ==
nullptr) {
130 tprintf(
"Error, failed to open file \"%s\"\n", backup_config_file_);
140 if (backup_config_file_ !=
nullptr) {
144 backup_config_file_ =
nullptr;
147 }
else if (pass > 1 && !word_box.
major_overlap(target_word_box)) {
155 const TBOX* target_word_box,
156 const char* word_config,
163 if (target_word_box ==
nullptr ||
165 *target_word_box, word_config, 1)) {
170 for (
int w = 0; w < words->
size(); ++w) {
172 if (w > 0) (*words)[w].prev_word = &(*words)[w - 1];
178 if (pass_n == 1 || !word->
word->
done) {
186 }
else if (pass_n == 2) {
193 for (
int s = 0; s <= sub_langs_.size(); ++s) {
195 Tesseract* lang_t = s < sub_langs_.size() ? sub_langs_[s] :
this;
201 word_res->SetupForRecognition(
222 for (
int w = 0; w < words->
size(); ++w) {
224 if (w > 0) word->
prev_word = &(*words)[w - 1];
225 if (monitor !=
nullptr) {
244 for (; w < words->
size(); ++w) {
258 while (pr_it->
word() !=
nullptr && pr_it->
word() != word->
word)
261 bool make_next_word_fuzzy =
false;
270 tprintf(
"Pass%d: %s [%s]\n", pass_n,
275 if (make_next_word_fuzzy && pr_it->
word() !=
nullptr) {
305 const TBOX* target_word_box,
306 const char* word_config,
315 if (dopasses==0 || dopasses==1) {
319 #ifndef DISABLED_LEGACY_ENGINE 330 for (
int i = 0; i < sub_langs_.size(); ++i) {
332 sub_langs_[i]->SwitchAdaptiveClassifier();
334 sub_langs_[i]->StartBackupAdaptiveClassifier();
338 #endif // ndef DISABLED_LEGACY_ENGINE 344 #ifndef DISABLED_LEGACY_ENGINE 348 #endif // ndef DISABLED_LEGACY_ENGINE 359 most_recently_used_ =
this;
384 if (dopasses == 1)
return true;
386 #ifndef DISABLED_LEGACY_ENGINE 397 most_recently_used_ =
this;
428 #endif // ndef DISABLED_LEGACY_ENGINE 435 #ifndef DISABLED_LEGACY_ENGINE 441 #endif //ndef DISABLED_LEGACY_ENGINE 443 const auto pageseg_mode =
static_cast<PageSegMode>(
460 if (monitor !=
nullptr) {
466 #ifndef DISABLED_LEGACY_ENGINE 475 while (word_it.
forward() !=
nullptr &&
479 if (!word_it.
word())
break;
486 tprintf(
"Skipping because one of the words is W_REP_CHAR\n");
511 tprintf(
"Top choice \"%s %s\" verified by bigram model.\n",
517 tprintf(
"Examining alt choices for \"%s %s\".\n",
528 float best_rating = 0.0;
531 for (prev_it.mark_cycle_pt(); !prev_it.cycled_list(); prev_it.forward()) {
540 for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
551 if (overrides_word1.
size() == 1 ||
554 best_idx = overrides_word1.
size() - 1;
559 if (!overrides_word1.
empty()) {
562 *overrides_word1[best_idx]) &&
564 *overrides_word2[best_idx])) {
566 tprintf(
"Top choice \"%s %s\" verified (sans case) by bigram " 567 "model.\n", orig_w1_str.
string(), orig_w2_str.
string());
571 const STRING new_w1_str = overrides_word1[best_idx]->unichar_string();
572 const STRING new_w2_str = overrides_word2[best_idx]->unichar_string();
573 if (new_w1_str != orig_w1_str) {
576 if (new_w2_str != orig_w2_str) {
580 STRING choices_description;
581 int num_bigram_choices
582 = overrides_word1.
size() * overrides_word2.
size();
583 if (num_bigram_choices == 1) {
584 choices_description =
"This was the unique bigram choice.";
588 const int kMaxChoicesToPrint = 20;
589 for (
int i = 0; i < overrides_word1.
size() &&
590 i < kMaxChoicesToPrint; i++) {
591 if (i > 0) { bigrams_list +=
", "; }
596 choices_description =
"There were many choices: {";
597 choices_description += bigrams_list;
598 choices_description +=
"}";
600 choices_description.
add_str_int(
"There were ", num_bigram_choices);
601 choices_description +=
" compatible bigrams.";
604 tprintf(
"Replaced \"%s %s\" with \"%s %s\" with bigram model. %s\n",
607 choices_description.
string());
615 const TBOX* target_word_box,
616 const char* word_config) {
625 if (monitor !=
nullptr) {
638 if (target_word_box &&
640 *target_word_box, word_config, 4)) {
654 int16_t all_char_quality;
655 int16_t accepted_all_char_quality;
657 &all_char_quality, &accepted_all_char_quality);
668 (blob_quality == 0) && (outline_errs >= chars_in_word))
676 (
"QUALITY: num_chs= %d num_rejs= %d %5.3f blob_qual= %d %5.3f" 677 " outline_errs= %d %5.3f char_qual= %d %5.3f good_ch_qual= %d %5.3f\n",
691 bool good_quality_doc =
709 #endif // ndef DISABLED_LEGACY_ENGINE 723 static_cast<IncorrectResultReason>(bl)),
745 float word_x_height = word->
x_height;
746 if (word_x_height < word->best_choice->min_x_height() ||
754 const double small_cap_delta = (x_height - small_cap_xheight) / 2.0;
756 small_cap_xheight - small_cap_delta <= word_x_height &&
757 word_x_height <= small_cap_xheight + small_cap_delta) {
767 if (num_upper > 0 && num_lower == 0)
778 *next_left = INT32_MAX;
779 if (index < words.
size()) {
780 *right = words[index]->word->bounding_box().right();
781 if (index + 1 < words.
size())
782 *next_left = words[index + 1]->word->bounding_box().left();
789 int first_index,
int end_index,
float* rating,
790 float* certainty,
bool* bad,
791 bool* valid_permuter) {
792 if (end_index <= first_index) {
794 *valid_permuter =
false;
796 for (
int index = first_index; index < end_index && index < words.
size();
799 if (choice ==
nullptr) {
802 *rating += choice->
rating();
803 *certainty = std::min(*certainty, choice->
certainty());
805 *valid_permuter =
false;
817 static int SelectBestWords(
double rating_ratio,
818 double certainty_margin,
827 int num_best = 0, num_new = 0;
828 while (b < best_words->size() || n < new_words->size()) {
830 int start_b = b, start_n = n;
831 while (b < best_words->size() || n < new_words->size()) {
832 int b_right = -INT32_MAX;
833 int next_b_left = INT32_MAX;
834 WordGap(*best_words, b, &b_right, &next_b_left);
835 int n_right = -INT32_MAX;
836 int next_n_left = INT32_MAX;
837 WordGap(*new_words, n, &n_right, &next_n_left);
838 if (std::max(b_right, n_right) < std::min(next_b_left, next_n_left)) {
843 if ((b_right < n_right && b < best_words->size()) ||
844 n == new_words->
size())
850 float b_rating = 0.0f, n_rating = 0.0f;
852 float b_certainty = 0.0f, n_certainty = 0.0f;
854 bool b_bad =
false, n_bad =
false;
856 bool b_valid_permuter =
true, n_valid_permuter =
true;
857 const int end_b = b < best_words->
size() ? b + 1 : b;
858 const int end_n = n < new_words->
size() ? n + 1 : n;
859 EvaluateWordSpan(*best_words, start_b, end_b, &b_rating, &b_certainty,
860 &b_bad, &b_valid_permuter);
861 EvaluateWordSpan(*new_words, start_n, end_n, &n_rating, &n_certainty,
862 &n_bad, &n_valid_permuter);
863 bool new_better =
false;
864 if (!n_bad && (b_bad || (n_certainty > b_certainty &&
865 n_rating < b_rating) ||
866 (!b_valid_permuter && n_valid_permuter &&
867 n_rating < b_rating * rating_ratio &&
868 n_certainty > b_certainty - certainty_margin))) {
870 for (
int i = start_n; i < end_n; ++i) {
872 (*new_words)[i] =
nullptr;
878 for (
int i = start_b; i < end_b; ++i) {
880 (*best_words)[i] =
nullptr;
885 tprintf(
"%d new words %s than %d old words: r: %g v %g c: %g v %g" 886 " valid dict: %d v %d\n",
887 end_n - start_n, new_better ?
"better" :
"worse",
888 end_b - start_b, n_rating, b_rating,
889 n_certainty, b_certainty, n_valid_permuter, b_valid_permuter);
897 for (
int i = 0; i < out_words.
size(); ++i)
899 return num_new - num_best;
910 tprintf(
"Trying word using lang %s, oem %d\n",
915 (this->*recognizer)(word_data, in_word, &new_words);
916 if (new_words.
empty()) {
923 for (
int i = 0; i < new_words.
size(); ++i)
924 new_words[i]->DebugTopChoice(
"Lang result");
930 debug, &new_words, best_words);
935 for (
int w = 0; w < words.
size(); ++w) {
936 if (words[w]->tess_failed || !words[w]->tess_accepted)
return false;
945 bool* make_next_word_fuzzy) {
946 #ifdef DISABLED_LEGACY_ENGINE 949 *make_next_word_fuzzy =
false;
963 &word_wanted, &overlapped_any_blob,
971 int num_overlapped = 0;
972 int num_overlapped_used = 0;
973 for (
int i = 0; i < overlapped_any_blob.
size(); ++i) {
974 if (overlapped_any_blob[i]) {
976 if (word_wanted[i]) ++num_overlapped_used;
980 outlines[i] =
nullptr;
986 int non_overlapped = 0;
987 int non_overlapped_used = 0;
988 for (
int i = 0; i < word_wanted.
size(); ++i) {
989 if (word_wanted[i]) ++non_overlapped_used;
990 if (outlines[i] !=
nullptr) ++non_overlapped_used;
993 tprintf(
"Used %d/%d overlapped %d/%d non-overlaped diacritics on word:",
994 num_overlapped_used, num_overlapped, non_overlapped_used,
1000 make_next_word_fuzzy)) {
1005 return num_overlapped_used != 0 || non_overlapped_used != 0;
1006 #endif // ndef DISABLED_LEGACY_ENGINE 1019 #ifndef DISABLED_LEGACY_ENGINE 1029 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
1030 C_BLOB* blob = blob_it.data();
1033 int num_blob_outlines = 0;
1034 for (
int i = 0; i < outlines.
size(); ++i) {
1036 !(*word_wanted)[i]) {
1037 blob_wanted[i] =
true;
1038 (*overlapped_any_blob)[i] =
true;
1039 ++num_blob_outlines;
1043 tprintf(
"%d noise outlines overlap blob at:", num_blob_outlines);
1052 outlines, num_blob_outlines,
1054 for (
int i = 0; i < blob_wanted.
size(); ++i) {
1055 if (blob_wanted[i]) {
1057 (*word_wanted)[i] =
true;
1058 (*target_blobs)[i] = blob;
1064 #endif // ndef DISABLED_LEGACY_ENGINE 1073 #ifndef DISABLED_LEGACY_ENGINE 1078 for (
int i = 0; i < outlines.
size(); ++i) {
1079 if (outlines[i] ==
nullptr)
continue;
1082 int num_blob_outlines = 0;
1083 TBOX total_ol_box(outlines[i]->bounding_box());
1084 while (i < outlines.
size() && outlines[i] !=
nullptr) {
1085 blob_wanted[i] =
true;
1086 total_ol_box += outlines[i]->bounding_box();
1088 ++num_blob_outlines;
1092 while (!blob_it.at_last() &&
1093 blob_it.data_relative(1)->bounding_box().left() <=
1094 total_ol_box.
left()) {
1100 tprintf(
"Num blobless outlines = %d\n", num_blob_outlines);
1101 C_BLOB* left_blob = blob_it.data();
1103 C_BLOB* right_blob = blob_it.at_last() ?
nullptr : blob_it.data_relative(1);
1104 if ((left_box.
x_overlap(total_ol_box) || right_blob ==
nullptr ||
1107 outlines, num_blob_outlines,
1110 for (
int j = 0; j < blob_wanted.
size(); ++j) {
1111 if (blob_wanted[j]) {
1112 (*word_wanted)[j] =
true;
1113 (*target_blobs)[j] = left_blob;
1116 }
else if (right_blob !=
nullptr &&
1120 right_blob, outlines,
1121 num_blob_outlines, &blob_wanted)) {
1123 for (
int j = 0; j < blob_wanted.
size(); ++j) {
1124 if (blob_wanted[j]) {
1125 (*word_wanted)[j] =
true;
1126 (*target_blobs)[j] = right_blob;
1130 outlines, num_blob_outlines,
1133 for (
int j = 0; j < blob_wanted.
size(); ++j) {
1134 if (blob_wanted[j]) {
1135 (*word_wanted)[j] =
true;
1136 (*target_blobs)[j] =
nullptr;
1141 #endif // ndef DISABLED_LEGACY_ENGINE 1151 #ifndef DISABLED_LEGACY_ENGINE 1153 float target_cert = certainty_threshold;
1154 if (blob !=
nullptr) {
1158 tprintf(
"No Noise blob classified as %s=%g(%g) at:", best_str.
string(),
1159 target_cert, target_c2);
1169 pr_it, blob, &all_str);
1172 for (
int i = 0; i < test_outlines.
size(); ++i) {
1173 if (test_outlines[i]) ol_box += outlines[i]->bounding_box();
1175 tprintf(
"All Noise blob classified as %s=%g, delta=%g at:",
1176 all_str.
string(), best_cert, best_cert - target_cert);
1182 while (num_outlines > 1 && best_index >= 0 &&
1183 (blob ==
nullptr || best_cert < target_cert || blob !=
nullptr)) {
1186 for (
int i = 0; i < outlines.
size(); ++i) {
1187 if (test_outlines[i]) {
1188 test_outlines[i] =
false;
1194 for (
int j = 0; j < outlines.
size(); ++j) {
1195 if (test_outlines[j]) ol_box += outlines[j]->bounding_box();
1196 tprintf(
"%d", test_outlines[j]);
1198 tprintf(
" blob classified as %s=%g, delta=%g) at:", str.
string(),
1199 cert, cert - target_cert);
1202 if (cert > best_cert) {
1205 best_outlines = test_outlines;
1207 test_outlines[i] =
true;
1210 if (best_index >= 0) {
1211 test_outlines[best_index] =
false;
1215 if (best_cert >= target_cert) {
1217 *ok_outlines = best_outlines;
1219 tprintf(
"%s noise combination ", blob ?
"Adding" :
"New");
1220 for (
int i = 0; i < best_outlines.
size(); ++i) {
1221 tprintf(
"%d", best_outlines[i]);
1223 tprintf(
" yields certainty %g, beating target of %g\n", best_cert,
1228 #endif // ndef DISABLED_LEGACY_ENGINE 1238 #ifndef DISABLED_LEGACY_ENGINE 1241 C_BLOB* local_blob =
nullptr;
1242 if (blob !=
nullptr) {
1244 ol_it.set_to_list(blob->
out_list());
1245 first_to_keep = ol_it.data();
1247 for (
int i = 0; i < ok_outlines.
size(); ++i) {
1248 if (ok_outlines[i]) {
1250 if (blob ==
nullptr) {
1251 local_blob =
new C_BLOB(outlines[i]);
1253 ol_it.set_to_list(blob->
out_list());
1255 ol_it.add_before_stay_put(outlines[i]);
1261 ol_it.move_to_first();
1262 if (first_to_keep ==
nullptr) {
1264 for (; !ol_it.empty(); ol_it.forward()) ol_it.extract();
1269 for (; ol_it.data() != first_to_keep; ol_it.forward()) {
1276 #endif // ndef DISABLED_LEGACY_ENGINE 1284 #ifndef DISABLED_LEGACY_ENGINE 1298 if (wd.word->raw_choice !=
nullptr) {
1299 tprintf(
"word xheight=%g, row=%g, range=[%g,%g]\n", word_res->
x_height,
1300 wd.row->x_height(), wd.word->raw_choice->min_x_height(),
1301 wd.word->raw_choice->max_x_height());
1303 tprintf(
"Got word with null raw choice xheight=%g, row=%g\n", word_res->
x_height,
1304 wd.row->x_height());
1308 if (wd.word->raw_choice !=
nullptr) {
1309 cert = wd.word->raw_choice->certainty();
1310 float rat = wd.word->raw_choice->rating();
1311 *c2 = rat > 0.0f ? cert * cert / rat : 0.0f;
1312 *best_str = wd.word->raw_choice->unichar_string();
1322 #endif // ndef DISABLED_LEGACY_ENGINE 1335 #ifdef DISABLED_LEGACY_ENGINE 1340 #endif // def DISABLED_LEGACY_ENGINE 1346 clock_t start_t = clock();
1349 tprintf(
"%s word with lang %s at:",
1350 word->
done ?
"Already done" :
"Processing",
1360 int sub = sub_langs_.size();
1361 if (most_recently_used_ !=
this) {
1363 for (sub = 0; sub < sub_langs_.size() &&
1364 most_recently_used_ != sub_langs_[sub]; ++sub) {}
1367 *word_data, recognizer, debug, &word_data->
lang_words[sub], &best_words);
1368 Tesseract* best_lang_tess = most_recently_used_;
1369 if (!WordsAcceptable(best_words)) {
1371 if (most_recently_used_ !=
this &&
1375 best_lang_tess =
this;
1377 for (
int i = 0; !WordsAcceptable(best_words) && i < sub_langs_.size();
1379 if (most_recently_used_ != sub_langs_[i] &&
1383 best_lang_tess = sub_langs_[i];
1387 most_recently_used_ = best_lang_tess;
1388 if (!best_words.
empty()) {
1389 if (best_words.
size() == 1 && !best_words[0]->combination) {
1394 word_data->
word = best_words.
back();
1401 clock_t ocr_t = clock();
1403 tprintf(
"%s (ocr took %.2f sec)\n",
1405 static_cast<double>(ocr_t-start_t)/CLOCKS_PER_SEC);
1418 ROW* row = word_data.
row;
1422 #ifndef ANDROID_BUILD 1423 #ifdef DISABLED_LEGACY_ENGINE 1428 #endif // def DISABLED_LEGACY_ENGINE 1431 if (!out_words->
empty())
1440 #ifndef DISABLED_LEGACY_ENGINE 1447 #endif // ndef DISABLED_LEGACY_ENGINE 1449 #endif // ndef ANDROID_BUILD 1451 #ifndef DISABLED_LEGACY_ENGINE 1472 #endif // ndef DISABLED_LEGACY_ENGINE 1478 tprintf(
"New XHT Match:%s = %s ",
1489 new_x_ht > 0.1 ?
"STILL DOUBT" :
"OK",
1490 accept_new_word ?
"ACCEPTED" :
"");
1493 #ifndef DISABLED_LEGACY_ENGINE 1501 if (original_misfits == 0)
1503 float baseline_shift = 0.0f;
1505 if (baseline_shift != 0.0f) {
1511 if (original_misfits > 0) {
1512 float new_baseline_shift;
1534 float baseline_shift,
float new_x_ht,
1536 bool accept_new_x_ht =
false;
1553 tprintf(
"Old misfits=%d with x-height %f, new=%d with x-height %f\n",
1555 new_misfits, new_x_ht);
1556 tprintf(
"Old rating= %f, certainty=%f, new=%f, %f\n",
1562 accept_new_x_ht = new_misfits < original_misfits &&
1571 if (accept_new_x_ht) {
1578 #endif // ndef DISABLED_LEGACY_ENGINE 1593 #ifndef DISABLED_LEGACY_ENGINE 1594 ROW* row = word_data.
row;
1621 #ifndef GRAPHICS_DISABLED 1635 #endif // ndef DISABLED_LEGACY_ENGINE 1638 #ifndef DISABLED_LEGACY_ENGINE 1656 tprintf(
"POST FIX_QUOTES FAIL String:\"%s\"; Strlen=%d;" 1673 #endif // ndef DISABLED_LEGACY_ENGINE 1684 if (choice !=
nullptr) {
1685 if (best_choice ==
nullptr || choice->
rating() < best_choice->
rating())
1686 best_choice = choice;
1695 static void CorrectRepcharChoices(
BLOB_CHOICE* blob_choice,
1701 if (choice ==
nullptr) {
1703 choice_it.add_before_stay_put(
new BLOB_CHOICE(*blob_choice));
1707 for (
int i = 0; i < word->
length(); ++i) {
1726 for (
int i = 0; i < word.
length(); ++i) {
1732 int max_count = rep_ch.MaxCount(&maxch_id);
1734 BLOB_CHOICE* best_choice = FindBestMatchingChoice(maxch_id, word_res);
1735 if (best_choice ==
nullptr) {
1736 tprintf(
"Failed to find a choice for %s, occurring %d times\n",
1740 word_res->
done =
true;
1746 C_BLOB* prev_blob = blob_it.data();
1747 for (blob_it.forward(); !blob_it.at_first(); blob_it.forward()) {
1748 C_BLOB* blob = blob_it.data();
1750 gap -= prev_blob->bounding_box().right();
1755 CorrectRepcharChoices(best_choice, word_res);
1760 const UNICHARSET& char_set,
const char *s,
const char *lengths) {
1763 int leading_punct_count;
1764 int upper_count = 0;
1765 int hyphen_pos = -1;
1768 if (strlen (lengths) > 20)
1774 offset += lengths[i++];
1775 leading_punct_count = i;
1778 while (s[offset] !=
'\0' && char_set.
get_isupper(s + offset, lengths[i])) {
1779 offset += lengths[i++];
1782 if (upper_count > 1) {
1786 while (s[offset] !=
'\0' && char_set.
get_islower(s + offset, lengths[i])) {
1787 offset += lengths[i++];
1795 if (lengths[i] == 1 && s[offset] ==
'-') {
1797 offset += lengths[i++];
1798 if (s[offset] !=
'\0') {
1799 while ((s[offset] !=
'\0') &&
1801 offset += lengths[i++];
1803 if (i < hyphen_pos + 3)
1808 if (lengths[i] == 1 && (s[offset] ==
'\'') &&
1809 lengths[i + 1] == 1 && (s[offset + lengths[i]] ==
's')) {
1810 offset += lengths[i++];
1811 offset += lengths[i++];
1814 if (upper_count > 0)
1821 if (lengths[i] == 1 && s[offset] !=
'\0' &&
1823 offset += lengths[i++];
1824 if (lengths[i] == 1 && s[offset] !=
'\0' && i > 0 &&
1825 s[offset - lengths[i - 1]] != s[offset] &&
1827 offset += lengths[i++];
1829 if (s[offset] !=
'\0')
1838 if (s[0] !=
'\0' && char_set.
get_isupper(s, lengths[0])) {
1840 while (s[offset] !=
'\0' &&
1842 lengths[i + 1] == 1 && s[offset + lengths[i]] ==
'.') {
1843 offset += lengths[i++];
1844 offset += lengths[i++];
1847 else if (s[0] !=
'\0' && char_set.
get_islower(s, lengths[0])) {
1849 while (s[offset] !=
'\0' &&
1851 lengths[i + 1] == 1 && s[offset + lengths[i]] ==
'.') {
1852 offset += lengths[i++];
1853 offset += lengths[i++];
1856 if (s[offset] !=
'\0')
1864 bool show_map_detail =
false;
1881 tprintf (
"classify_word_pass1 start\n");
1885 tprintf (
"make_reject_map: initial map");
1888 tprintf (
"make_reject_map: after NN");
1891 tprintf (
"classify_word_pass2 - START");
1894 tprintf (
"classify_word_pass2 - Pre Xht");
1897 tprintf (
"classify_word_pass2 - END");
1898 show_map_detail =
true;
1910 tprintf (
"After Poor quality rejection");
1913 tprintf (
"unrej_good_quality_words - START");
1916 tprintf (
"unrej_good_quality_words - END");
1919 tprintf (
"Write results pass");
1920 show_map_detail =
true;
1927 if (show_map_detail) {
1935 tprintf(
"null best choice\n");
1938 tprintf (
"Done flag: %s\n\n", word->
done ?
"TRUE" :
"FALSE");
1950 static void find_modal_font(
1959 font =
static_cast<int16_t
>(fonts->
mode ());
1962 *font_count = count < INT8_MAX ? count : INT8_MAX;
1963 fonts->
add (font, -*font_count);
1982 #ifndef DISABLED_LEGACY_ENGINE 1984 if (fontinfo_size == 0)
return;
1992 tprintf(
"Examining fonts in %s\n",
1997 if (choice ==
nullptr)
continue;
1999 for (
int f = 0; f < fonts.
size(); ++f) {
2000 const int fontinfo_id = fonts[f].fontinfo_id;
2001 if (0 <= fontinfo_id && fontinfo_id < fontinfo_size) {
2002 font_total_score[fontinfo_id] += fonts[f].score;
2007 int score1 = 0, score2 = 0;
2008 int16_t font_id1 = -1, font_id2 = -1;
2009 for (
int f = 0; f < fontinfo_size; ++f) {
2011 tprintf(
"Font %s, total score = %d\n",
2014 if (font_total_score[f] > score1) {
2016 font_id2 = font_id1;
2017 score1 = font_total_score[f];
2019 }
else if (font_total_score[f] > score2) {
2020 score2 = font_total_score[f];
2034 tprintf(
"Word modal font=%s, score=%d, 2nd choice %s/%d\n",
2039 tprintf(
"Word modal font=%s, score=%d. No 2nd choice\n",
2046 #endif // ndef DISABLED_LEGACY_ENGINE 2058 STATS doc_fonts(0, font_table_size_);
2063 word = page_res_it.
word();
2072 int8_t doc_font_count;
2073 find_modal_font(&doc_fonts, &doc_font, &doc_font_count);
2074 if (doc_font_count == 0)
2077 const FontInfo* modal_font =
nullptr;
2080 word = page_res_it.
word();
2095 word = page_res_it.
word();
2099 if (!(count == length || (length > 3 && count >= length * 3 / 4))) {
2116 if (word->best_choices.singleton())
2120 if (word->tesseract->getDict().valid_word(*best) != 0)
2123 WERD_CHOICE_IT choice_it(&word->best_choices);
2124 for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
2125 choice_it.forward()) {
2127 if (word->tesseract->getDict().valid_word(*alternate)) {
2130 tprintf(
"Dictionary correction replaces best choice '%s' with '%s'\n",
2135 word->ReplaceBestChoice(alternate);
void word_char_quality(WERD_RES *word, ROW *row, int16_t *match_count, int16_t *accepted_match_count)
UNICHAR_ID unichar_id() const
int16_t word_outline_errs(WERD_RES *word)
void recog_pseudo_word(PAGE_RES *page_res, TBOX &selection_box)
void GetNoiseOutlines(GenericVector< C_OUTLINE * > *outlines)
static void LastChanceBlame(bool debug, WERD_RES *word)
void full_print(FILE *fp)
bool AdaptableWord(WERD_RES *word)
C_OUTLINE_LIST * out_list()
WERD_RES * restart_page()
void AssignDiacriticsToOverlappingBlobs(const GenericVector< C_OUTLINE * > &outlines, int pass, WERD *real_word, PAGE_RES_IT *pr_it, GenericVector< bool > *word_wanted, GenericVector< bool > *overlapped_any_blob, GenericVector< C_BLOB * > *target_blobs)
bool major_overlap(const TBOX &box) const
int tessedit_ocr_engine_mode
void ReplaceBestChoice(WERD_CHOICE *choice)
UnicityTable< FontInfo > fontinfo_table_
WERD_RES * InsertSimpleCloneWord(const WERD_RES &clone_res, WERD *new_word)
GenericVector< int > blame_reasons
bool tessedit_dump_choices
bool poly_allow_detailed_fx
float ComputeCompatibleXheight(WERD_RES *word_res, float *baseline_shift)
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
bool tessedit_test_adaption
FCOORD classify_rotation() const
WERD_CHOICE * prev_word_best_choice_
bool word_adaptable(WERD_RES *word, uint16_t mode)
void LSTMRecognizeWord(const BLOCK &block, ROW *row, WERD_RES *word, PointerVector< WERD_RES > *words)
BLOB_CHOICE * GetBlobChoice(int index) const
POLY_BLOCK * poly_block() const
void ZoomToRectangle(int x1, int y1, int x2, int y2)
bool recog_all_words(PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config, int dopasses)
const UNICHARSET & GetUnicharset() const
static void PrintParams(FILE *fp, const ParamsVectors *member_params)
void add_str_int(const char *str, int number)
const STRING & unichar_string() const
C_BLOB_LIST * rej_cblob_list()
GenericVector< STRING > misadaption_log
bool tessedit_fix_fuzzy_spaces
void match_word_pass_n(int pass_n, WERD_RES *word, ROW *row, BLOCK *block)
BLOCK_RES * block() const
float min_x_height() const
void fix_fuzzy_spaces(ETEXT_DESC *monitor, int32_t word_count, PAGE_RES *page_res)
int16_t doc_good_char_quality
WERD_CHOICE_LIST best_choices
bool contains(const FCOORD pt) const
bool tessedit_enable_bigram_correction
void(Tesseract::*)(const WordData &, WERD_RES **, PointerVector< WERD_RES > *) WordRecognizer
double quality_outline_pc
void script_pos_pass(PAGE_RES *page_res)
bool EqualIgnoringCaseAndTerminalPunct(const WERD_CHOICE &word1, const WERD_CHOICE &word2)
bool AddSelectedOutlines(const GenericVector< bool > &wanted, const GenericVector< C_BLOB * > &target_blobs, const GenericVector< C_OUTLINE * > &outlines, bool *make_next_word_fuzzy)
TBOX bounding_box() const
void CopyTruth(const BlamerBundle &other)
void add(int32_t value, int32_t count)
void init_to_size(int size, const T &t)
bool TestNewNormalization(int original_misfits, float baseline_shift, float new_x_ht, WERD_RES *word, BLOCK *block, ROW *row)
bool tessedit_reject_bad_qual_wds
void plot(ScrollView *window)
bool right_to_left() const
tesseract::Tesseract * tesseract
PointerVector< WERD_RES > lang_words
double noise_cert_basechar
bool tess_acceptable_word(WERD_RES *word)
int16_t word_blob_quality(WERD_RES *word, ROW *row)
bool tessedit_debug_fonts
void StartBackupAdaptiveClassifier()
int16_t progress
chars in this buffer(0)
bool script_has_xheight() const
bool tessedit_minimal_rejection
void SetMisAdaptionDebug(const WERD_CHOICE *best_choice, bool debug)
void ReportXhtFixResult(bool accept_new_word, float new_x_ht, WERD_RES *word, WERD_RES *new_word)
const double kMinRefitXHeightFraction
const UNICHARSET * uch_set
BLOB_CHOICE * FindMatchingChoice(UNICHAR_ID char_id, BLOB_CHOICE_LIST *bc_list)
double noise_cert_disjoint
bool AdaptiveClassifierIsFull() const
bool tessedit_word_for_word
volatile int8_t ocr_alive
true if not last
void tess_add_doc_word(WERD_CHOICE *word_choice)
int tessedit_tess_adaption_mode
const FontInfo * fontinfo2
static int SortByXMiddle(const void *v1, const void *v2)
bool tessedit_display_outwords
int tessedit_bigram_debug
bool tessedit_timing_debug
bool ProcessTargetWord(const TBOX &word_box, const TBOX &target_word_box, const char *word_config, int pass)
IncorrectResultReason incorrect_result_reason() const
int8_t fontinfo_id2_count
bool tessedit_debug_quality_metrics
void * cancel_this
monitor-aware progress callback
void output_pass(PAGE_RES_IT &page_res_it, const TBOX *target_word_box)
bool check_debug_pt(WERD_RES *word, int location)
char * chs_trailing_punct2
bool x_overlap(const TBOX &box) const
bool RecogAllWordsPassN(int pass_n, ETEXT_DESC *monitor, PAGE_RES_IT *pr_it, GenericVector< WordData > *words)
void initialise(int16_t length)
ACCEPTABLE_WERD_TYPE acceptable_word_string(const UNICHARSET &char_set, const char *s, const char *lengths)
int32_t x_height() const
return xheight
const FontInfo * fontinfo
const char * string() const
int32_t pile_count(int32_t value) const
void font_recognition_pass(PAGE_RES *page_res)
void PrerecAllWordsPar(const GenericVector< WordData > &words)
DLLSYM void tprintf(const char *format,...)
bool AdaptiveClassifierIsEmpty() const
void set_word_fonts(WERD_RES *word)
void Add(T value, int count)
TBOX bounding_box() const
PAGE_RES_IT * make_pseudo_word(PAGE_RES *page_res, const TBOX &selection_box)
void set_unichar_id(UNICHAR_ID unichar_id, int index)
tesseract::BoxWord * box_word
float ClassifyBlobAsWord(int pass_n, PAGE_RES_IT *pr_it, C_BLOB *blob, STRING *best_str, float *c2)
Dict & getDict() override
bool tessedit_enable_dict_correction
bool ReassignDiacritics(int pass, PAGE_RES_IT *pr_it, bool *make_next_word_fuzzy)
bool SubAndSuperscriptFix(WERD_RES *word_res)
bool TrainedXheightFix(WERD_RES *word, BLOCK *block, ROW *row)
bool tessedit_fix_hyphens
bool top_bottom_useful() const
bool tessedit_rejection_debug
PDBLK pdblk
Page Description Block.
float ClassifyBlobPlusOutlines(const GenericVector< bool > &ok_outlines, const GenericVector< C_OUTLINE * > &outlines, int pass_n, PAGE_RES_IT *pr_it, C_BLOB *blob, STRING *best_str)
char * chs_trailing_punct1
double classify_max_certainty_margin
void bigram_correction_pass(PAGE_RES *page_res)
const GenericVector< tesseract::ScoredFont > & fonts() const
void SetupWordPassN(int pass_n, WordData *word)
bool contains(char c) const
void ConsumeWordResults(WERD_RES *word)
STRING debug_str(UNICHAR_ID id) const
TBOX bounding_box() const
void GetNonSuperscriptSpan(int *start, int *end) const
void BestChoiceToCorrectText()
UNICHAR_ID unichar_id(int index) const
#define LOC_WRITE_RESULTS
void rej_word_bad_quality()
WERD_CHOICE * best_choice
WERD * ConstructFromSingleBlob(bool bol, bool eol, C_BLOB *blob)
int quality_min_initial_alphas_reqd
void set_global_subloc_code(int loc_code)
int32_t get_total() const
void rejection_passes(PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config)
bool tessedit_enable_doc_dict
void AssignDiacriticsToNewBlobs(const GenericVector< C_OUTLINE * > &outlines, int pass, WERD *real_word, PAGE_RES_IT *pr_it, GenericVector< bool > *word_wanted, GenericVector< C_BLOB * > *target_blobs)
UnicityTable< FontInfo > & get_fontinfo_table()
void quality_based_rejection(PAGE_RES_IT &page_res_it, bool good_quality_doc)
void classify_word_pass1(const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)
bool flag(WERD_FLAGS mask) const
void MakeCurrentWordFuzzy()
int multilang_debug_level
double classify_max_rating_ratio
void blamer_pass(PAGE_RES *page_res)
void LearnWord(const char *fontname, WERD_RES *word)
bool wordrec_debug_blamer
static const double kXHeightCapRatio
void InitForRetryRecognition(const WERD_RES &source)
bool valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) const
void CleanupSingleRowResult(PageSegMode pageseg_mode, PAGE_RES *page_res)
static C_BLOB * deep_copy(const C_BLOB *src)
const STRING & misadaption_debug() const
bool get_isupper(UNICHAR_ID unichar_id) const
float max_x_height() const
int tessedit_pageseg_mode
const STRING debug_string() const
void dictionary_correction_pass(PAGE_RES *page_res)
int CountMisfitTops(WERD_RES *word_res)
int RetryWithLanguage(const WordData &word_data, WordRecognizer recognizer, bool debug, WERD_RES **in_word, PointerVector< WERD_RES > *best_words)
const char *const kBackUpConfigFile
bool deadline_exceeded() const
void make_reject_map(WERD_RES *word, ROW *row, int16_t pass)
bool major_x_overlap(const TBOX &box) const
void PrintBestChoices() const
bool tessedit_minimal_rej_pass1
void fix_rep_char(PAGE_RES_IT *page_res_it)
WERD_CHOICE shallow_copy(int start, int end) const
void classify_word_and_language(int pass_n, PAGE_RES_IT *pr_it, WordData *word_data)
void SwitchAdaptiveClassifier()
void set_global_loc_code(int loc_code)
static bool ReadParamsFile(const char *file, SetParamConstraint constraint, ParamsVectors *member_params)
void SetScriptPositions()
void tess_segment_pass_n(int pass_n, WERD_RES *word)
static const char * IncorrectReasonName(IncorrectResultReason irr)
bool recog_interactive(PAGE_RES_IT *pr_it)
BLOB_CHOICE_LIST * GetBlobChoices(int index) const
void classify_word_pass2(const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)
PROGRESS_FUNC2 progress_callback2
called whenever progress increases
bool classify_bln_numeric_mode
static bool valid_word_permuter(uint8_t perm, bool numbers_ok)
Check all the DAWGs to see if this word is in any of them.
void SetupAllWordsPassN(int pass_n, const TBOX *target_word_box, const char *word_config, PAGE_RES *page_res, GenericVector< WordData > *words)
bool get_islower(UNICHAR_ID unichar_id) const
bool textord_use_cjk_fp_model
bool SelectGoodDiacriticOutlines(int pass, float certainty_threshold, PAGE_RES_IT *pr_it, C_BLOB *blob, const GenericVector< C_OUTLINE * > &outlines, int num_outlines, GenericVector< bool > *ok_outlines)
void ReplaceCurrentWord(tesseract::PointerVector< WERD_RES > *words)
BlamerBundle * blamer_bundle
CANCEL_FUNC cancel
for errcode use
C_BLOB_LIST * cblob_list()