MCPcopy Create free account
hub / github.com/creatale/node-dv / fix_rep_char

Method fix_rep_char

deps/tesseract/ccmain/control.cpp:1629–1666  ·  view source on GitHub ↗

* fix_rep_char() * The word is a repeated char. (Leader.) Find the repeated char character. * Create the appropriate single-word or multi-word sequence according to * the size of spaces in between blobs, and correct the classifications * where some of the characters disagree with the majority. */

Source from the content-addressed store, hash-verified

1627 * where some of the characters disagree with the majority.
1628 */
1629void Tesseract::fix_rep_char(PAGE_RES_IT* page_res_it) {
1630 WERD_RES *word_res = page_res_it->word();
1631 const WERD_CHOICE &word = *(word_res->best_choice);
1632
1633 // Find the frequency of each unique character in the word.
1634 SortHelper<UNICHAR_ID> rep_ch(word.length());
1635 for (int i = 0; i < word.length(); ++i) {
1636 rep_ch.Add(word.unichar_id(i), 1);
1637 }
1638
1639 // Find the most frequent result.
1640 UNICHAR_ID maxch_id = INVALID_UNICHAR_ID; // most common char
1641 int max_count = rep_ch.MaxCount(&maxch_id);
1642 // Find the best exemplar of a classifier result for maxch_id.
1643 BLOB_CHOICE* best_choice = FindBestMatchingChoice(maxch_id, word_res);
1644 if (best_choice == NULL) {
1645 tprintf("Failed to find a choice for %s, occurring %d times\n",
1646 word_res->uch_set->debug_str(maxch_id).string(), max_count);
1647 return;
1648 }
1649 word_res->done = TRUE;
1650
1651 // Measure the mean space.
1652 int gap_count = 0;
1653 WERD* werd = word_res->word;
1654 C_BLOB_IT blob_it(werd->cblob_list());
1655 C_BLOB* prev_blob = blob_it.data();
1656 for (blob_it.forward(); !blob_it.at_first(); blob_it.forward()) {
1657 C_BLOB* blob = blob_it.data();
1658 int gap = blob->bounding_box().left();
1659 gap -= prev_blob->bounding_box().right();
1660 ++gap_count;
1661 prev_blob = blob;
1662 }
1663 // Just correct existing classification.
1664 CorrectRepcharChoices(best_choice, word_res);
1665 word_res->reject_map.initialise(word.length());
1666}
1667
1668ACCEPTABLE_WERD_TYPE Tesseract::acceptable_word_string(
1669 const UNICHARSET& char_set, const char *s, const char *lengths) {

Callers

nothing calls this directly

Calls 15

FindBestMatchingChoiceFunction · 0.85
CorrectRepcharChoicesFunction · 0.85
unichar_idMethod · 0.80
MaxCountMethod · 0.80
cblob_listMethod · 0.80
dataMethod · 0.80
initialiseMethod · 0.80
wordMethod · 0.45
lengthMethod · 0.45
AddMethod · 0.45
stringMethod · 0.45
debug_strMethod · 0.45

Tested by

no test coverage detected