Applies the box file based on the image name fname, and resegments the words in the block_list (page), with: blob-mode: one blob per line in the box file, words as input. word/line-mode: one blob per space-delimited unit after the #, and one word per line in the box file. (See comment above for box file format.) If find_segmentation is true, (word/line mode) then the classifier is used to re-segme
| 115 | // converted to a best_choice using CorrectClassifyWords. CorrectClassifyWords |
| 116 | // is not required before calling ApplyBoxTraining. |
| 117 | PAGE_RES* Tesseract::ApplyBoxes(const STRING& fname, |
| 118 | bool find_segmentation, |
| 119 | BLOCK_LIST *block_list) { |
| 120 | GenericVector<TBOX> boxes; |
| 121 | GenericVector<STRING> texts, full_texts; |
| 122 | if (!ReadAllBoxes(applybox_page, true, fname, &boxes, &texts, &full_texts, |
| 123 | NULL)) { |
| 124 | return NULL; // Can't do it. |
| 125 | } |
| 126 | |
| 127 | int box_count = boxes.size(); |
| 128 | int box_failures = 0; |
| 129 | // Add an empty everything to the end. |
| 130 | boxes.push_back(TBOX()); |
| 131 | texts.push_back(STRING()); |
| 132 | full_texts.push_back(STRING()); |
| 133 | |
| 134 | // In word mode, we use the boxes to make a word for each box, but |
| 135 | // in blob mode we use the existing words and maximally chop them first. |
| 136 | PAGE_RES* page_res = find_segmentation ? |
| 137 | NULL : SetupApplyBoxes(boxes, block_list); |
| 138 | clear_any_old_text(block_list); |
| 139 | |
| 140 | for (int i = 0; i < boxes.size() - 1; i++) { |
| 141 | bool foundit = false; |
| 142 | if (page_res != NULL) { |
| 143 | if (i == 0) { |
| 144 | foundit = ResegmentCharBox(page_res, NULL, boxes[i], boxes[i + 1], |
| 145 | full_texts[i].string()); |
| 146 | } else { |
| 147 | foundit = ResegmentCharBox(page_res, &boxes[i-1], boxes[i], |
| 148 | boxes[i + 1], full_texts[i].string()); |
| 149 | } |
| 150 | } else { |
| 151 | foundit = ResegmentWordBox(block_list, boxes[i], boxes[i + 1], |
| 152 | texts[i].string()); |
| 153 | } |
| 154 | if (!foundit) { |
| 155 | box_failures++; |
| 156 | ReportFailedBox(i, boxes[i], texts[i].string(), |
| 157 | "FAILURE! Couldn't find a matching blob"); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if (page_res == NULL) { |
| 162 | // In word/line mode, we now maximally chop all the words and resegment |
| 163 | // them with the classifier. |
| 164 | page_res = SetupApplyBoxes(boxes, block_list); |
| 165 | ReSegmentByClassification(page_res); |
| 166 | } |
| 167 | if (applybox_debug > 0) { |
| 168 | tprintf("APPLY_BOXES:\n"); |
| 169 | tprintf(" Boxes read from boxfile: %6d\n", box_count); |
| 170 | if (box_failures > 0) |
| 171 | tprintf(" Boxes failed resegmentation: %6d\n", box_failures); |
| 172 | } |
| 173 | TidyUp(page_res); |
| 174 | return page_res; |
no test coverage detected