21 #include "config_auto.h" 67 TabVector_LIST* vlines,
int vertical_x,
int vertical_y,
70 resolution_(resolution),
71 image_origin_(0, tright.y() - 1),
74 v_it_.add_list_after(vlines);
75 SetVerticalSkewAndParallelize(vertical_x, vertical_y);
95 BLOBNBOX_C_IT>* grid) {
96 BLOBNBOX_IT blob_it(blobs);
99 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
102 if (
InsertBlob(h_spread, v_spread, blob, grid)) {
109 tprintf(
"Inserted %d blobs into grid, %d rejected.\n",
110 b_count, reject_count);
121 BLOBNBOX_C_IT>* grid) {
129 grid->InsertBBox(h_spread, v_spread, blob);
144 BLOBNBOX_IT blob_it(blobs);
145 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
163 bool ignore_unmergeables,
int max_gutter_width,
164 int* required_shift) {
166 int bottom_x = v.
XAtY(bottom_y);
167 int top_x = v.
XAtY(top_y);
168 int start_x = right_to_left ? std::max(top_x, bottom_x) : std::min(top_x, bottom_x);
171 int min_gap = max_gutter_width;
174 while ((blob = sidesearch.
NextSideSearch(right_to_left)) !=
nullptr) {
176 if (box.
bottom() >= top_y || box.
top() <= bottom_y)
185 int mid_y = (box.
bottom() + box.
top()) / 2;
190 int tab_x = v.
XAtY(mid_y);
193 gap = tab_x - box.
right();
194 if (gap < 0 && box.
left() - tab_x < *required_shift)
195 *required_shift = box.
left() - tab_x;
197 gap = box.
left() - tab_x;
198 if (gap < 0 && box.
right() - tab_x > *required_shift)
199 *required_shift = box.
right() - tab_x;
201 if (gap > 0 && gap < min_gap)
205 return min_gap - abs(*required_shift);
210 int max_gutter,
bool left,
212 int* neighbour_gap) {
215 int gutter_x = left ? box.
left() : box.
right();
216 int internal_x = left ? box.
right() : box.
left();
218 int tab_gap = left ? gutter_x - tab_x : tab_x - gutter_x;
219 *gutter_width = max_gutter;
223 *gutter_width += tab_gap;
226 tprintf(
"Looking in gutter\n");
228 BLOBNBOX* gutter_bbox = AdjacentBlob(bbox, left,
231 if (gutter_bbox !=
nullptr) {
233 *gutter_width = left ? tab_x - gutter_box.
right()
234 : gutter_box.
left() - tab_x;
236 if (*gutter_width >= max_gutter) {
238 TBOX gutter_box(box);
240 gutter_box.
set_left(tab_x - max_gutter - 1);
241 gutter_box.
set_right(tab_x - max_gutter);
243 if (tab_gutter < tab_x - 1)
244 *gutter_width = tab_x - tab_gutter;
246 gutter_box.
set_left(tab_x + max_gutter);
247 gutter_box.
set_right(tab_x + max_gutter + 1);
249 if (tab_gutter > tab_x + 1)
250 *gutter_width = tab_gutter - tab_x;
253 if (*gutter_width > max_gutter)
254 *gutter_width = max_gutter;
257 tprintf(
"Looking for neighbour\n");
258 BLOBNBOX* neighbour = AdjacentBlob(bbox, !left,
263 if (neighbour !=
nullptr) {
269 if (left && n_box.
left() < neighbour_edge)
270 neighbour_edge = n_box.
left();
271 else if (!left && n_box.
right() > neighbour_edge)
272 neighbour_edge = n_box.
right();
274 *neighbour_gap = left ? neighbour_edge - internal_x
275 : internal_x - neighbour_edge;
309 int top_y = box.
top();
310 int bottom_y = box.
bottom();
311 int mid_y = (top_y + bottom_y) / 2;
312 int right = crossing ? (box.
left() + box.
right()) / 2 : box.
right();
313 int min_key, max_key;
316 while (!v_it_.at_first() && v_it_.data()->sort_key() >= min_key)
318 while (!v_it_.at_last() && v_it_.data()->sort_key() < min_key)
326 int x = v->
XAtY(mid_y);
328 (v->
VOverlap(top_y, bottom_y) > 0 ||
330 if (best_v ==
nullptr || x < best_x) {
335 key_limit = v->
sort_key() + max_key - min_key;
340 if (v_it_.at_last() ||
341 (best_v !=
nullptr && v->
sort_key() > key_limit))
344 }
while (!v_it_.at_first());
353 int top_y = box.
top();
354 int bottom_y = box.
bottom();
355 int mid_y = (top_y + bottom_y) / 2;
356 int left = crossing ? (box.
left() + box.
right()) / 2 : box.
left();
357 int min_key, max_key;
360 while (!v_it_.at_last() && v_it_.data()->sort_key() <= max_key)
362 while (!v_it_.at_first() && v_it_.data()->sort_key() > max_key) {
371 int x = v->
XAtY(mid_y);
373 (v->
VOverlap(top_y, bottom_y) > 0 ||
375 if (best_v ==
nullptr || x > best_x) {
380 key_limit = v->
sort_key() - (max_key - min_key);
385 if (v_it_.at_first() ||
386 (best_v !=
nullptr && v->
sort_key() < key_limit))
389 }
while (!v_it_.at_last());
397 ICOORDELT_IT it(&column_widths_);
398 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
400 if (w->
x() - 1 <= width && width <= w->
y() + 1)
409 return size1 > size2 * 2 || size2 > size1 * 2;
415 return size1 > size2 * 5 || size2 > size1 * 5;
424 BLOBNBOX_LIST* image_blobs,
TO_BLOCK* block,
425 int min_gutter_width,
426 double tabfind_aligned_gap_fraction,
430 tabfind_aligned_gap_fraction,
432 ComputeColumnWidths(tab_win, part_grid);
436 if (!Deskew(hlines, image_blobs, block, deskew, reskew))
438 part_grid->
Deskew(*deskew);
439 ApplyTabConstraints();
440 #ifndef GRAPHICS_DISABLED 447 #endif // GRAPHICS_DISABLED 468 BLOBNBOX_IT blob_it = &block->
blobs;
470 for (large_it.mark_cycle_pt(); !large_it.cycled_list(); large_it.forward()) {
471 BLOBNBOX* large_blob = large_it.data();
472 if (large_blob->
owner() !=
nullptr) {
473 blob_it.add_to_end(large_it.extract());
478 tprintf(
"Moved %d large blobs to normal list\n",
480 #ifndef GRAPHICS_DISABLED 485 #endif // GRAPHICS_DISABLED 494 *min_key = std::min(key1, key2);
495 *max_key = std::max(key1, key2);
499 #ifndef GRAPHICS_DISABLED 501 TabVector_IT it(&vectors_);
502 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
516 int min_gutter_width,
517 double tabfind_aligned_gap_fraction,
524 if (image_blobs !=
nullptr)
527 ScrollView* initial_win = FindTabBoxes(min_gutter_width,
528 tabfind_aligned_gap_fraction);
529 FindAllTabVectors(min_gutter_width);
543 #ifndef GRAPHICS_DISABLED 544 for (
int i = 0; i < boxes.
size(); ++i) {
545 TBOX box = boxes[i]->bounding_box();
546 int left_x = box.
left();
547 int right_x = box.
right();
548 int top_y = box.
top();
549 int bottom_y = box.
bottom();
552 win->
Rectangle(left_x, bottom_y, right_x, top_y);
555 #endif // GRAPHICS_DISABLED 560 ScrollView* TabFind::FindTabBoxes(
int min_gutter_width,
561 double tabfind_aligned_gap_fraction) {
562 left_tab_boxes_.
clear();
563 right_tab_boxes_.
clear();
565 GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(
this);
566 gsearch.StartFullSearch();
568 while ((bbox = gsearch.NextFullSearch()) !=
nullptr) {
569 if (TestBoxForTabs(bbox, min_gutter_width, tabfind_aligned_gap_fraction)) {
579 left_tab_boxes_.
sort(SortByBoxLeft<BLOBNBOX>);
580 right_tab_boxes_.
sort(SortRightToLeft<BLOBNBOX>);
582 #ifndef GRAPHICS_DISABLED 588 DisplayBoxVector(left_tab_boxes_, tab_win);
589 DisplayBoxVector(right_tab_boxes_, tab_win);
592 #endif // GRAPHICS_DISABLED 596 bool TabFind::TestBoxForTabs(
BLOBNBOX* bbox,
int min_gutter_width,
597 double tabfind_aligned_gap_fraction) {
598 GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> radsearch(
this);
601 int left_column_edge = bbox->
left_rule();
604 int left_x = box.
left();
605 int right_x = box.
right();
606 int top_y = box.
top();
607 int bottom_y = box.
bottom();
608 int height = box.
height();
611 tprintf(
"Column edges for blob at (%d,%d)->(%d,%d) are [%d, %d]\n",
612 left_x, top_y, right_x, bottom_y,
613 left_column_edge, right_column_edge);
617 radsearch.StartRadSearch((left_x + right_x)/2, (top_y + bottom_y)/2, radius);
623 static_cast<int>(height * tabfind_aligned_gap_fraction);
624 if (min_gutter_width > min_spacing)
625 min_spacing = min_gutter_width;
627 if (min_gutter_width > min_ragged_gutter)
628 min_ragged_gutter = min_gutter_width;
629 int target_right = left_x - min_spacing;
630 int target_left = right_x + min_spacing;
646 bool is_left_tab =
true;
647 bool is_right_tab =
true;
648 bool maybe_ragged_left =
true;
649 bool maybe_ragged_right =
true;
650 int maybe_left_tab_up = 0;
651 int maybe_right_tab_up = 0;
652 int maybe_left_tab_down = 0;
653 int maybe_right_tab_down = 0;
656 maybe_ragged_left =
false;
657 maybe_left_tab_up = -INT32_MAX;
658 maybe_left_tab_down = -INT32_MAX;
661 is_right_tab =
false;
662 maybe_ragged_right =
false;
663 maybe_right_tab_up = -INT32_MAX;
664 maybe_right_tab_down = -INT32_MAX;
668 while ((neighbour = radsearch.NextRadSearch()) !=
nullptr) {
669 if (neighbour == bbox)
672 int n_left = nbox.
left();
673 int n_right = nbox.
right();
675 tprintf(
"Neighbour at (%d,%d)->(%d,%d)\n",
676 n_left, nbox.
bottom(), n_right, nbox.
top());
679 if (n_right > right_column_edge || n_left < left_column_edge ||
680 left_x < neighbour->left_rule() || right_x > neighbour->
right_rule())
682 int n_mid_x = (n_left + n_right) / 2;
683 int n_mid_y = (nbox.
top() + nbox.
bottom()) / 2;
684 if (n_mid_x <= left_x && n_right >= target_right) {
689 maybe_left_tab_down = -INT32_MAX;
690 if (n_mid_y > bottom_y)
691 maybe_left_tab_up = -INT32_MAX;
692 }
else if (
NearlyEqual(left_x, n_left, alignment_tolerance)) {
695 if (n_mid_y > top_y && maybe_left_tab_up > -INT32_MAX)
697 if (n_mid_y < bottom_y && maybe_left_tab_down > -INT32_MAX)
698 ++maybe_left_tab_down;
699 }
else if (n_left < left_x && n_right >= left_x) {
702 tprintf(
"Maybe Not a left tab\n");
703 if (n_mid_y > top_y && maybe_left_tab_up > -INT32_MAX)
705 if (n_mid_y < bottom_y && maybe_left_tab_down > -INT32_MAX)
706 --maybe_left_tab_down;
708 if (n_left < left_x && nbox.
y_overlap(box) && n_right >= target_right) {
709 maybe_ragged_left =
false;
711 tprintf(
"Not a ragged left\n");
713 if (n_mid_x >= right_x && n_left <= target_left) {
716 is_right_tab =
false;
718 maybe_right_tab_down = -INT32_MAX;
719 if (n_mid_y > bottom_y)
720 maybe_right_tab_up = -INT32_MAX;
721 }
else if (
NearlyEqual(right_x, n_right, alignment_tolerance)) {
723 tprintf(
"Maybe a right tab\n");
724 if (n_mid_y > top_y && maybe_right_tab_up > -INT32_MAX)
725 ++maybe_right_tab_up;
726 if (n_mid_y < bottom_y && maybe_right_tab_down > -INT32_MAX)
727 ++maybe_right_tab_down;
728 }
else if (n_right > right_x && n_left <= right_x) {
731 tprintf(
"Maybe Not a right tab\n");
732 if (n_mid_y > top_y && maybe_right_tab_up > -INT32_MAX)
733 --maybe_right_tab_up;
734 if (n_mid_y < bottom_y && maybe_right_tab_down > -INT32_MAX)
735 --maybe_right_tab_down;
737 if (n_right > right_x && nbox.
y_overlap(box) && n_left <= target_left) {
738 maybe_ragged_right =
false;
740 tprintf(
"Not a ragged right\n");
742 if (maybe_left_tab_down == -INT32_MAX && maybe_left_tab_up == -INT32_MAX &&
743 maybe_right_tab_down == -INT32_MAX && maybe_right_tab_up == -INT32_MAX)
746 if (is_left_tab || maybe_left_tab_up > 1 || maybe_left_tab_down > 1) {
748 }
else if (maybe_ragged_left && ConfirmRaggedLeft(bbox, min_ragged_gutter)) {
753 if (is_right_tab || maybe_right_tab_up > 1 || maybe_right_tab_down > 1) {
755 }
else if (maybe_ragged_right &&
756 ConfirmRaggedRight(bbox, min_ragged_gutter)) {
762 tprintf(
"Left result = %s, Right result=%s\n",
773 bool TabFind::ConfirmRaggedLeft(
BLOBNBOX* bbox,
int min_gutter) {
776 search_box.set_left(search_box.left() - min_gutter);
777 return NothingYOverlapsInBox(search_box, bbox->
bounding_box());
782 bool TabFind::ConfirmRaggedRight(
BLOBNBOX* bbox,
int min_gutter) {
784 search_box.
set_left(search_box.right());
785 search_box.set_right(search_box.right() + min_gutter);
786 return NothingYOverlapsInBox(search_box, bbox->
bounding_box());
791 bool TabFind::NothingYOverlapsInBox(
const TBOX& search_box,
792 const TBOX& target_box) {
794 rsearch.StartRectSearch(search_box);
796 while ((blob = rsearch.NextRectSearch()) !=
nullptr) {
798 if (box.
y_overlap(target_box) && !(box == target_box))
804 void TabFind::FindAllTabVectors(
int min_gutter_width) {
806 TabVector_LIST dummy_vectors;
817 &vertical_x, &vertical_y);
821 &vertical_x, &vertical_y);
822 if (vector_count > 0)
826 dummy_vectors.clear();
827 for (
int i = 0; i < left_tab_boxes_.
size(); ++i) {
828 BLOBNBOX* bbox = left_tab_boxes_[i];
832 for (
int i = 0; i < right_tab_boxes_.
size(); ++i) {
833 BLOBNBOX* bbox = right_tab_boxes_[i];
838 tprintf(
"Beginning real tab search with vertical = %d,%d...\n",
839 vertical_x, vertical_y);
845 &dummy_vectors, &vertical_x, &vertical_y);
847 &dummy_vectors, &vertical_x, &vertical_y);
849 &dummy_vectors, &vertical_x, &vertical_y);
851 &dummy_vectors, &vertical_x, &vertical_y);
853 TabVector_IT v_it(&vectors_);
854 v_it.add_list_after(&dummy_vectors);
856 SetVerticalSkewAndParallelize(vertical_x, vertical_y);
861 int min_gutter_width, TabVector_LIST* vectors,
862 int* vertical_x,
int* vertical_y) {
863 TabVector_IT vector_it(
vectors);
864 int vector_count = 0;
869 for (
int i = 0; i < boxes.
size(); ++i) {
873 TabVector* vector = FindTabVector(search_size_multiple, min_gutter_width,
875 bbox, vertical_x, vertical_y);
876 if (vector !=
nullptr) {
878 vector_it.add_to_end(vector);
892 TabVector* TabFind::FindTabVector(
int search_size_multiple,
893 int min_gutter_width,
896 int* vertical_x,
int* vertical_y) {
898 AlignedBlobParams align_params(*vertical_x, *vertical_y,
900 search_size_multiple, min_gutter_width,
908 void TabFind::SetVerticalSkewAndParallelize(
int vertical_x,
int vertical_y) {
912 tprintf(
"Vertical skew vector=(%d,%d)\n",
914 v_it_.set_to_list(&vectors_);
915 for (v_it_.mark_cycle_pt(); !v_it_.cycled_list(); v_it_.forward()) {
916 TabVector* v = v_it_.data();
924 void TabFind::SortVectors() {
926 v_it_.set_to_list(&vectors_);
930 void TabFind::EvaluateTabs() {
931 TabVector_IT rule_it(&vectors_);
932 for (rule_it.mark_cycle_pt(); !rule_it.cycled_list(); rule_it.forward()) {
933 TabVector* tab = rule_it.data();
934 if (!tab->IsSeparator()) {
938 tab->Print(
"Too few boxes");
939 delete rule_it.extract();
940 v_it_.set_to_list(&vectors_);
942 tab->Print(
"Evaluated tab");
951 void TabFind::ComputeColumnWidths(
ScrollView* tab_win,
952 ColPartitionGrid* part_grid) {
953 #ifndef GRAPHICS_DISABLED 954 if (tab_win !=
nullptr)
956 #endif // GRAPHICS_DISABLED 959 STATS col_widths(0, col_widths_size + 1);
960 ApplyPartitionsToColumnWidths(part_grid, &col_widths);
961 #ifndef GRAPHICS_DISABLED 962 if (tab_win !=
nullptr) {
965 #endif // GRAPHICS_DISABLED 969 MakeColumnWidths(col_widths_size, &col_widths);
971 ApplyPartitionsToColumnWidths(part_grid,
nullptr);
980 void TabFind::ApplyPartitionsToColumnWidths(ColPartitionGrid* part_grid,
985 gsearch.StartFullSearch();
987 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
988 BLOBNBOX_C_IT blob_it(part->boxes());
991 BLOBNBOX* left_blob = blob_it.data();
992 blob_it.move_to_last();
993 BLOBNBOX* right_blob = blob_it.data();
996 if (left_vector ==
nullptr || left_vector->IsRightTab())
1000 if (right_vector ==
nullptr || right_vector->IsLeftTab())
1006 int width = line_right - line_left;
1007 if (col_widths !=
nullptr) {
1008 AddPartnerVector(left_blob, right_blob, left_vector, right_vector);
1013 ICOORDELT_IT it(&column_widths_);
1014 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1016 if (NearlyEqual<int>(width, w->
y(), 1)) {
1018 if (true_width <= w->y() && true_width > w->
x())
1019 w->
set_x(true_width);
1030 void TabFind::MakeColumnWidths(
int col_widths_size,
STATS* col_widths) {
1031 ICOORDELT_IT w_it(&column_widths_);
1032 int total_col_count = col_widths->
get_total();
1034 int width = col_widths->
mode();
1035 int col_count = col_widths->
pile_count(width);
1036 col_widths->
add(width, -col_count);
1038 for (
int left = width - 1; left > 0 &&
1041 int new_count = col_widths->
pile_count(left);
1042 col_count += new_count;
1043 col_widths->
add(left, -new_count);
1045 for (
int right = width + 1; right < col_widths_size &&
1048 int new_count = col_widths->
pile_count(right);
1049 col_count += new_count;
1050 col_widths->
add(right, -new_count);
1055 w_it.add_after_then_move(w);
1057 tprintf(
"Column of width %d has %d = %.2f%% lines\n",
1059 100.0 * col_count / total_col_count);
1066 void TabFind::MarkVerticalText() {
1068 tprintf(
"Checking for vertical lines\n");
1070 gsearch.StartFullSearch();
1072 while ((blob = gsearch.NextFullSearch()) !=
nullptr) {
1081 int TabFind::FindMedianGutterWidth(TabVector_LIST *lines) {
1082 TabVector_IT it(lines);
1083 int prev_right = -1;
1085 STATS gaps(0, max_gap);
1086 STATS heights(0, max_gap);
1087 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1088 TabVector* v = it.data();
1089 TabVector* partner = v->GetSinglePartner();
1090 if (!v->IsLeftTab() || v->IsSeparator() || !partner)
continue;
1091 heights.add(partner->startpt().x() - v->startpt().x(), 1);
1092 if (prev_right > 0 && v->startpt().x() > prev_right) {
1093 gaps.add(v->startpt().x() - prev_right, 1);
1095 prev_right = partner->startpt().x();
1098 tprintf(
"TabGutter total %d median_gap %.2f median_hgt %.2f\n",
1099 gaps.get_total(), gaps.median(), heights.median());
1101 return static_cast<int>(gaps.median());
1110 bool look_left,
bool ignore_images,
1111 double min_overlap_fraction,
1112 int gap_limit,
int top_y,
int bottom_y) {
1113 GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> sidesearch(
this);
1115 int left = box.
left();
1116 int right = box.
right();
1117 int mid_x = (left + right) / 2;
1118 sidesearch.StartSideSearch(mid_x, bottom_y, top_y);
1123 while ((neighbour = sidesearch.NextSideSearch(look_left)) !=
nullptr) {
1125 tprintf(
"Adjacent blob: considering box:");
1128 if (neighbour == bbox ||
1132 int n_top_y = nbox.
top();
1133 int n_bottom_y = nbox.
bottom();
1134 int v_overlap = std::min(n_top_y, top_y) - std::max(n_bottom_y, bottom_y);
1135 int height = top_y - bottom_y;
1136 int n_height = n_top_y - n_bottom_y;
1137 if (v_overlap > min_overlap_fraction * std::min(height, n_height) &&
1138 (min_overlap_fraction == 0.0 || !
DifferentSizes(height, n_height))) {
1139 int n_left = nbox.
left();
1140 int n_right = nbox.
right();
1141 int h_gap = std::max(n_left, left) - std::min(n_right, right);
1142 int n_mid_x = (n_left + n_right) / 2;
1143 if (look_left == (n_mid_x < mid_x) && n_mid_x != mid_x) {
1144 if (h_gap > gap_limit) {
1147 tprintf(
"Giving up due to big gap = %d vs %d\n",
1156 tprintf(
"Collision with like tab of type %d at %d,%d\n",
1164 if (result ==
nullptr || h_gap < best_gap) {
1177 tprintf(
"Insufficient overlap\n");
1181 tprintf(
"Giving up due to end of search\n");
1190 TabVector* left, TabVector* right) {
1193 if (left->IsSeparator()) {
1196 if (v !=
nullptr && v != left && v->IsLeftTab() &&
1197 v->XAtY(left_box.
top()) > left->XAtY(left_box.
top())) {
1199 left->ExtendToBox(left_blob);
1204 v_it_.move_to_first();
1207 if (right->IsSeparator()) {
1210 tprintf(
"Box edge (%d,%d-%d)",
1212 right->Print(
" looking for improvement for");
1215 if (v !=
nullptr && v != right && v->IsRightTab() &&
1216 v->XAtY(right_box.
top()) < right->XAtY(right_box.
top())) {
1218 right->ExtendToBox(right_blob);
1220 right->Print(
"Extended vector");
1227 v_it_.move_to_first();
1229 right->Print(
"Created new vector");
1233 left->AddPartner(right);
1234 right->AddPartner(left);
1239 void TabFind::CleanupTabs() {
1243 TabVector_IT it(&vectors_);
1244 TabVector_IT dead_it(&dead_vectors_);
1245 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1246 TabVector* v = it.data();
1247 if (v->IsSeparator() || v->Partnerless()) {
1248 dead_it.add_after_then_move(it.extract());
1249 v_it_.set_to_list(&vectors_);
1258 BLOBNBOX_IT it(blobs);
1259 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1260 it.data()->rotate_box(rotation);
1266 bool TabFind::Deskew(TabVector_LIST* hlines, BLOBNBOX_LIST* image_blobs,
1268 ComputeDeskewVectors(deskew, reskew);
1278 TabVector_IT h_it(hlines);
1279 for (h_it.mark_cycle_pt(); !h_it.cycled_list(); h_it.forward()) {
1283 TabVector_IT d_it(&dead_vectors_);
1284 for (d_it.mark_cycle_pt(); !d_it.cycled_list(); d_it.forward()) {
1285 TabVector* d = d_it.data();
1288 SetVerticalSkewAndParallelize(0, 1);
1291 grid_box.rotate_large(*deskew);
1292 Init(
gridsize(), grid_box.botleft(), grid_box.topright());
1302 TabVector_LIST* horizontal_lines,
1303 int* min_gutter_width) {
1307 TabVector_LIST ex_verticals;
1308 TabVector_IT ex_v_it(&ex_verticals);
1309 TabVector_LIST vlines;
1310 TabVector_IT v_it(&vlines);
1311 while (!v_it_.empty()) {
1315 ex_v_it.add_after_then_move(v);
1317 v_it.add_after_then_move(v);
1324 int median_gutter = FindMedianGutterWidth(&vlines);
1325 if (median_gutter > *min_gutter_width)
1326 *min_gutter_width = median_gutter;
1328 TabVector_IT h_it(horizontal_lines);
1329 for (h_it.mark_cycle_pt(); !h_it.cycled_list(); h_it.forward()) {
1333 v_it_.add_list_after(horizontal_lines);
1334 v_it_.move_to_first();
1335 h_it.set_to_list(horizontal_lines);
1336 h_it.add_list_after(&ex_verticals);
1347 v_it_.move_to_first();
1348 for (v_it_.mark_cycle_pt(); !v_it_.cycled_list(); v_it_.forward()) {
1349 if (!v_it_.data()->IsSeparator())
1350 delete v_it_.extract();
1358 TabVector_LIST temp_list;
1359 TabVector_IT temp_it(&temp_list);
1360 v_it_.move_to_first();
1364 while (!v_it_.empty()) {
1368 temp_it.add_before_then_move(v);
1370 v_it_.add_list_after(&temp_list);
1371 v_it_.move_to_first();
1374 int tmp = grid_box.
left();
1381 void TabFind::ComputeDeskewVectors(
FCOORD* deskew,
FCOORD* reskew) {
1383 length = sqrt(length);
1386 reskew->
set_x(deskew->
x());
1387 reskew->
set_y(-deskew->
y());
1392 void TabFind::ApplyTabConstraints() {
1393 TabVector_IT it(&vectors_);
1394 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1395 TabVector* v = it.data();
1396 v->SetupConstraints();
1398 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1399 TabVector* v = it.data();
1403 v->SetupPartnerConstraints();
1408 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1409 TabVector* v = it.data();
1410 if (!v->IsRightTab())
1413 TabVector_IT partner_it(it);
1414 for (partner_it.forward(); !partner_it.at_first(); partner_it.forward()) {
1415 TabVector* partner = partner_it.data();
1416 if (!partner->IsLeftTab() || !v->VOverlap(*partner))
1418 v->SetupPartnerConstraints(partner);
1422 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1423 TabVector* v = it.data();
1424 if (!v->IsSeparator())
1425 v->ApplyConstraints();
const ICOORD & topright() const
static bool DifferentSizes(int size1, int size2)
void set_with_shrink(int x, int y)
Set from the given x,y, shrinking the vector to fit if needed.
void GutterWidthAndNeighbourGap(int tab_x, int mean_height, int max_gutter, bool left, BLOBNBOX *bbox, int *gutter_width, int *neighbour_gap)
int32_t pile_count(int32_t value) const
ScrollView * MakeWindow(int x, int y, const char *window_name)
const double kMinFractionalLinesInColumn
const int kMaxRaggedSearch
#define BOOL_VAR(name, val, comment)
void StartSideSearch(int x, int ymin, int ymax)
void set_x(int16_t xin)
rewrite function
bool FindTabVectors(TabVector_LIST *hlines, BLOBNBOX_LIST *image_blobs, TO_BLOCK *block, int min_gutter_width, double tabfind_aligned_gap_fraction, ColPartitionGrid *part_grid, FCOORD *deskew, FCOORD *reskew)
const ICOORD & bleft() const
int16_t y() const
access_function
int RightEdgeForBox(const TBOX &box, bool crossing, bool extended)
void TidyBlobs(TO_BLOCK *block)
BlobTextFlowType flow() const
static bool UnMergeableType(BlobRegionType type)
static bool WithinTestRegion(int detail_level, int x, int y)
void plot_noise_blobs(ScrollView *to_win)
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
int LeftEdgeForBox(const TBOX &box, bool crossing, bool extended)
ScrollView * DisplayTabVectors(ScrollView *tab_win)
TabVector * FindVerticalAlignment(AlignedBlobParams align_params, BLOBNBOX *bbox, int *vertical_x, int *vertical_y)
void set_x(float xin)
rewrite function
void set_left_rule(int new_left)
TabVector * RightTabForBox(const TBOX &box, bool crossing, bool extended)
void set_left_crossing_rule(int new_left)
const int kMinEvaluatedTabs
TabVector * LeftTabForBox(const TBOX &box, bool crossing, bool extended)
void set_right_tab_type(TabType new_type)
bool InsertBlob(bool h_spread, bool v_spread, BLOBNBOX *blob, BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > *grid)
const int kColumnWidthFactor
void Rotate(const FCOORD &rotation)
bool textord_tabfind_show_finaltabs
void set_right_rule(int new_right)
const int kRaggedGutterMultiple
bool CommonWidth(int width)
void plot_graded_blobs(ScrollView *to_win)
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
bool NearlyEqual(T x, T y, T tolerance)
int GutterWidth(int bottom_y, int top_y, const TabVector &v, bool ignore_unmergeables, int max_gutter_width, int *required_shift)
static bool VeryDifferentSizes(int size1, int size2)
void set_region_type(BlobRegionType new_type)
BBC * NextSideSearch(bool right_to_left)
bool leader_on_right() const
int16_t x() const
access function
BlobRegionType region_type() const
bool textord_tabfind_show_initialtabs
int textord_debug_tabfind
int ExtendedOverlap(int top_y, int bottom_y) const
bool joined_to_prev() const
TabType right_tab_type() const
TabType left_tab_type() const
GridSearch< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > BlobGridSearch
void rotate_large(const FCOORD &vec)
ScrollView * FindInitialTabVectors(BLOBNBOX_LIST *image_blobs, int min_gutter_width, double tabfind_aligned_gap_fraction, TO_BLOCK *block)
DLLSYM void tprintf(const char *format,...)
ScrollView * DisplayTabs(const char *window_name, ScrollView *tab_win)
const int kMinLinesInColumn
static int SortVectorsByKey(const void *v1, const void *v2)
void DeleteUnownedNoise()
void add(int32_t value, int32_t count)
const ICOORD & botleft() const
static int SortKey(const ICOORD &vertical, int x, int y)
void DontFindTabVectors(BLOBNBOX_LIST *image_blobs, TO_BLOCK *block, FCOORD *deskew, FCOORD *reskew)
TabFind(int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVector_LIST *vlines, int vertical_x, int vertical_y, int resolution)
void SetupTabSearch(int x, int y, int *min_key, int *max_key)
int VOverlap(const TabVector &other) const
void InsertBlobsToGrid(bool h_spread, bool v_spread, BLOBNBOX_LIST *blobs, BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > *grid)
bool y_overlap(const TBOX &box) const
const double kMinColumnWidth
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
void SetBlobRuleEdges(BLOBNBOX_LIST *blobs)
static void MergeSimilarTabVectors(const ICOORD &vertical, TabVector_LIST *vectors, BlobGrid *grid)
const TBOX & bounding_box() const
TabVector_LIST * vectors()
bool leader_on_left() const
void Rectangle(int x1, int y1, int x2, int y2)
tesseract::ColPartition * owner() const
void Deskew(const FCOORD &deskew)
static void RotateBlobList(const FCOORD &rotation, BLOBNBOX_LIST *blobs)
BLOBNBOX_LIST large_blobs
bool UniquelyVertical() const
const int kTabRadiusFactor
const double kCosMaxSkewAngle
const int kMaxVerticalSearch
void Display(ScrollView *tab_win)
void set_y(float yin)
rewrite function
void set_left_tab_type(TabType new_type)
void set_right_crossing_rule(int new_right)
const double kLineFragmentAspectRatio
const double kMaxGutterWidthAbsolute
int32_t get_total() const
void DisplayBoxes(ScrollView *window)
const int kMinVerticalSearch
void SetBlockRuleEdges(TO_BLOCK *block)
const ICOORD & tright() const
BLOBNBOX_LIST small_blobs
void ResetForVerticalText(const FCOORD &rotate, const FCOORD &rerotate, TabVector_LIST *horizontal_lines, int *min_gutter_width)
BLOBNBOX_LIST noise_blobs
const double kAlignedFraction