- Counts up the labelled words and the blobs within. - Deletes all unused or emptied words, counting the unused ones. - Resets W_BOL and W_EOL flags correctly. - Builds the rebuild_word and rebuilds the box_word and the best_choice.
| 704 | /// - Resets W_BOL and W_EOL flags correctly. |
| 705 | /// - Builds the rebuild_word and rebuilds the box_word and the best_choice. |
| 706 | void Tesseract::TidyUp(PAGE_RES* page_res) { |
| 707 | int ok_blob_count = 0; |
| 708 | int bad_blob_count = 0; |
| 709 | int ok_word_count = 0; |
| 710 | int unlabelled_words = 0; |
| 711 | PAGE_RES_IT pr_it(page_res); |
| 712 | WERD_RES* word_res; |
| 713 | for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) { |
| 714 | int ok_in_word = 0; |
| 715 | int blob_count = word_res->correct_text.size(); |
| 716 | WERD_CHOICE* word_choice = new WERD_CHOICE(word_res->uch_set, blob_count); |
| 717 | word_choice->set_permuter(TOP_CHOICE_PERM); |
| 718 | for (int c = 0; c < blob_count; ++c) { |
| 719 | if (word_res->correct_text[c].length() > 0) { |
| 720 | ++ok_in_word; |
| 721 | } |
| 722 | // Since we only need a fake word_res->best_choice, the actual |
| 723 | // unichar_ids do not matter. Which is fortunate, since TidyUp() |
| 724 | // can be called while training Tesseract, at the stage where |
| 725 | // unicharset is not meaningful yet. |
| 726 | word_choice->append_unichar_id_space_allocated( |
| 727 | INVALID_UNICHAR_ID, word_res->best_state[c], 1.0f, -1.0f); |
| 728 | } |
| 729 | if (ok_in_word > 0) { |
| 730 | ok_blob_count += ok_in_word; |
| 731 | bad_blob_count += word_res->correct_text.size() - ok_in_word; |
| 732 | word_res->LogNewRawChoice(word_choice); |
| 733 | word_res->LogNewCookedChoice(1, false, word_choice); |
| 734 | } else { |
| 735 | ++unlabelled_words; |
| 736 | if (applybox_debug > 0) { |
| 737 | tprintf("APPLY_BOXES: Unlabelled word at :"); |
| 738 | word_res->word->bounding_box().print(); |
| 739 | } |
| 740 | pr_it.DeleteCurrentWord(); |
| 741 | delete word_choice; |
| 742 | } |
| 743 | } |
| 744 | pr_it.restart_page(); |
| 745 | for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) { |
| 746 | // Denormalize back to a BoxWord. |
| 747 | word_res->RebuildBestState(); |
| 748 | word_res->SetupBoxWord(); |
| 749 | word_res->word->set_flag(W_BOL, pr_it.prev_row() != pr_it.row()); |
| 750 | word_res->word->set_flag(W_EOL, pr_it.next_row() != pr_it.row()); |
| 751 | } |
| 752 | if (applybox_debug > 0) { |
| 753 | tprintf(" Found %d good blobs.\n", ok_blob_count); |
| 754 | if (bad_blob_count > 0) { |
| 755 | tprintf(" Leaving %d unlabelled blobs in %d words.\n", |
| 756 | bad_blob_count, ok_word_count); |
| 757 | } |
| 758 | if (unlabelled_words > 0) |
| 759 | tprintf(" %d remaining unlabelled words deleted.\n", unlabelled_words); |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | /** Logs a bad box by line in the box file and box coords.*/ |
no test coverage detected