66 TabVector_LIST* vlines,
int vertical_x,
int vertical_y,
69 resolution_(resolution),
70 image_origin_(0, tright.y() - 1) {
72 v_it_.set_to_list(&vectors_);
73 v_it_.add_list_after(vlines);
74 SetVerticalSkewAndParellelize(vertical_x, vertical_y);
79 if (width_cb_ != NULL)
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 ?
MAX(top_x, bottom_x) :
MIN(top_x, bottom_x);
171 int min_gap = max_gutter_width;
174 while ((blob = sidesearch.
NextSideSearch(right_to_left)) != NULL) {
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 != NULL) {
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 != NULL) {
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 == NULL || x < best_x) {
335 key_limit = v->
sort_key() + max_key - min_key;
340 if (v_it_.at_last() ||
341 (best_v != NULL && 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 == NULL || x > best_x) {
380 key_limit = v->
sort_key() - (max_key - min_key);
385 if (v_it_.at_first() ||
386 (best_v != NULL && 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 445 image_origin_.
x(), image_origin_.
y());
452 #endif // GRAPHICS_DISABLED 473 BLOBNBOX_IT blob_it = &block->
blobs;
475 for (large_it.mark_cycle_pt(); !large_it.cycled_list(); large_it.forward()) {
476 BLOBNBOX* large_blob = large_it.data();
477 if (large_blob->
owner() != NULL) {
478 blob_it.add_to_end(large_it.extract());
483 tprintf(
"Moved %d large blobs to normal list\n",
485 #ifndef GRAPHICS_DISABLED 490 #endif // GRAPHICS_DISABLED 499 *min_key =
MIN(key1, key2);
500 *max_key =
MAX(key1, key2);
504 #ifndef GRAPHICS_DISABLED 506 TabVector_IT it(&vectors_);
507 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
521 int min_gutter_width,
522 double tabfind_aligned_gap_fraction,
529 if (image_blobs != NULL)
532 ScrollView* initial_win = FindTabBoxes(min_gutter_width,
533 tabfind_aligned_gap_fraction);
534 FindAllTabVectors(min_gutter_width);
548 #ifndef GRAPHICS_DISABLED 549 for (
int i = 0; i < boxes.
size(); ++i) {
550 TBOX box = boxes[i]->bounding_box();
551 int left_x = box.
left();
552 int right_x = box.
right();
553 int top_y = box.
top();
554 int bottom_y = box.
bottom();
557 win->
Rectangle(left_x, bottom_y, right_x, top_y);
560 #endif // GRAPHICS_DISABLED 565 ScrollView* TabFind::FindTabBoxes(
int min_gutter_width,
566 double tabfind_aligned_gap_fraction) {
567 left_tab_boxes_.
clear();
568 right_tab_boxes_.
clear();
570 GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(
this);
571 gsearch.StartFullSearch();
573 while ((bbox = gsearch.NextFullSearch()) != NULL) {
574 if (TestBoxForTabs(bbox, min_gutter_width, tabfind_aligned_gap_fraction)) {
584 left_tab_boxes_.
sort(SortByBoxLeft<BLOBNBOX>);
585 right_tab_boxes_.
sort(SortRightToLeft<BLOBNBOX>);
587 #ifndef GRAPHICS_DISABLED 593 DisplayBoxVector(left_tab_boxes_, tab_win);
594 DisplayBoxVector(right_tab_boxes_, tab_win);
597 #endif // GRAPHICS_DISABLED 601 bool TabFind::TestBoxForTabs(
BLOBNBOX* bbox,
int min_gutter_width,
602 double tabfind_aligned_gap_fraction) {
603 GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> radsearch(
this);
606 int left_column_edge = bbox->
left_rule();
609 int left_x = box.
left();
610 int right_x = box.
right();
611 int top_y = box.
top();
612 int bottom_y = box.
bottom();
613 int height = box.
height();
616 tprintf(
"Column edges for blob at (%d,%d)->(%d,%d) are [%d, %d]\n",
617 left_x, top_y, right_x, bottom_y,
618 left_column_edge, right_column_edge);
622 radsearch.StartRadSearch((left_x + right_x)/2, (top_y + bottom_y)/2, radius);
628 static_cast<int>(height * tabfind_aligned_gap_fraction);
629 if (min_gutter_width > min_spacing)
630 min_spacing = min_gutter_width;
632 if (min_gutter_width > min_ragged_gutter)
633 min_ragged_gutter = min_gutter_width;
634 int target_right = left_x - min_spacing;
635 int target_left = right_x + min_spacing;
651 bool is_left_tab =
true;
652 bool is_right_tab =
true;
653 bool maybe_ragged_left =
true;
654 bool maybe_ragged_right =
true;
655 int maybe_left_tab_up = 0;
656 int maybe_right_tab_up = 0;
657 int maybe_left_tab_down = 0;
658 int maybe_right_tab_down = 0;
661 maybe_ragged_left =
false;
666 is_right_tab =
false;
667 maybe_ragged_right =
false;
673 while ((neighbour = radsearch.NextRadSearch()) != NULL) {
674 if (neighbour == bbox)
677 int n_left = nbox.
left();
678 int n_right = nbox.
right();
680 tprintf(
"Neighbour at (%d,%d)->(%d,%d)\n",
681 n_left, nbox.
bottom(), n_right, nbox.
top());
684 if (n_right > right_column_edge || n_left < left_column_edge ||
685 left_x < neighbour->left_rule() || right_x > neighbour->
right_rule())
687 int n_mid_x = (n_left + n_right) / 2;
688 int n_mid_y = (nbox.
top() + nbox.
bottom()) / 2;
689 if (n_mid_x <= left_x && n_right >= target_right) {
695 if (n_mid_y > bottom_y)
697 }
else if (
NearlyEqual(left_x, n_left, alignment_tolerance)) {
700 if (n_mid_y > top_y && maybe_left_tab_up > -
MAX_INT32)
702 if (n_mid_y < bottom_y && maybe_left_tab_down > -
MAX_INT32)
703 ++maybe_left_tab_down;
704 }
else if (n_left < left_x && n_right >= left_x) {
707 tprintf(
"Maybe Not a left tab\n");
708 if (n_mid_y > top_y && maybe_left_tab_up > -
MAX_INT32)
710 if (n_mid_y < bottom_y && maybe_left_tab_down > -
MAX_INT32)
711 --maybe_left_tab_down;
713 if (n_left < left_x && nbox.
y_overlap(box) && n_right >= target_right) {
714 maybe_ragged_left =
false;
716 tprintf(
"Not a ragged left\n");
718 if (n_mid_x >= right_x && n_left <= target_left) {
721 is_right_tab =
false;
724 if (n_mid_y > bottom_y)
726 }
else if (
NearlyEqual(right_x, n_right, alignment_tolerance)) {
728 tprintf(
"Maybe a right tab\n");
729 if (n_mid_y > top_y && maybe_right_tab_up > -
MAX_INT32)
730 ++maybe_right_tab_up;
731 if (n_mid_y < bottom_y && maybe_right_tab_down > -
MAX_INT32)
732 ++maybe_right_tab_down;
733 }
else if (n_right > right_x && n_left <= right_x) {
736 tprintf(
"Maybe Not a right tab\n");
737 if (n_mid_y > top_y && maybe_right_tab_up > -
MAX_INT32)
738 --maybe_right_tab_up;
739 if (n_mid_y < bottom_y && maybe_right_tab_down > -
MAX_INT32)
740 --maybe_right_tab_down;
742 if (n_right > right_x && nbox.
y_overlap(box) && n_left <= target_left) {
743 maybe_ragged_right =
false;
745 tprintf(
"Not a ragged right\n");
751 if (is_left_tab || maybe_left_tab_up > 1 || maybe_left_tab_down > 1) {
753 }
else if (maybe_ragged_left && ConfirmRaggedLeft(bbox, min_ragged_gutter)) {
758 if (is_right_tab || maybe_right_tab_up > 1 || maybe_right_tab_down > 1) {
760 }
else if (maybe_ragged_right &&
761 ConfirmRaggedRight(bbox, min_ragged_gutter)) {
767 tprintf(
"Left result = %s, Right result=%s\n",
778 bool TabFind::ConfirmRaggedLeft(
BLOBNBOX* bbox,
int min_gutter) {
781 search_box.set_left(search_box.left() - min_gutter);
782 return NothingYOverlapsInBox(search_box, bbox->
bounding_box());
787 bool TabFind::ConfirmRaggedRight(
BLOBNBOX* bbox,
int min_gutter) {
789 search_box.
set_left(search_box.right());
790 search_box.set_right(search_box.right() + min_gutter);
791 return NothingYOverlapsInBox(search_box, bbox->
bounding_box());
796 bool TabFind::NothingYOverlapsInBox(
const TBOX& search_box,
797 const TBOX& target_box) {
799 rsearch.StartRectSearch(search_box);
801 while ((blob = rsearch.NextRectSearch()) != NULL) {
803 if (box.
y_overlap(target_box) && !(box == target_box))
809 void TabFind::FindAllTabVectors(
int min_gutter_width) {
811 TabVector_LIST dummy_vectors;
822 &vertical_x, &vertical_y);
826 &vertical_x, &vertical_y);
827 if (vector_count > 0)
831 dummy_vectors.clear();
832 for (
int i = 0; i < left_tab_boxes_.
size(); ++i) {
833 BLOBNBOX* bbox = left_tab_boxes_[i];
837 for (
int i = 0; i < right_tab_boxes_.
size(); ++i) {
838 BLOBNBOX* bbox = right_tab_boxes_[i];
843 tprintf(
"Beginning real tab search with vertical = %d,%d...\n",
844 vertical_x, vertical_y);
850 &dummy_vectors, &vertical_x, &vertical_y);
852 &dummy_vectors, &vertical_x, &vertical_y);
854 &dummy_vectors, &vertical_x, &vertical_y);
856 &dummy_vectors, &vertical_x, &vertical_y);
858 TabVector_IT v_it(&vectors_);
859 v_it.add_list_after(&dummy_vectors);
861 SetVerticalSkewAndParellelize(vertical_x, vertical_y);
866 int min_gutter_width, TabVector_LIST* vectors,
867 int* vertical_x,
int* vertical_y) {
868 TabVector_IT vector_it(
vectors);
869 int vector_count = 0;
874 for (
int i = 0; i < boxes.
size(); ++i) {
878 TabVector* vector = FindTabVector(search_size_multiple, min_gutter_width,
880 bbox, vertical_x, vertical_y);
881 if (vector != NULL) {
883 vector_it.add_to_end(vector);
897 TabVector* TabFind::FindTabVector(
int search_size_multiple,
898 int min_gutter_width,
901 int* vertical_x,
int* vertical_y) {
903 AlignedBlobParams align_params(*vertical_x, *vertical_y,
905 search_size_multiple, min_gutter_width,
913 void TabFind::SetVerticalSkewAndParellelize(
int vertical_x,
int vertical_y) {
917 tprintf(
"Vertical skew vector=(%d,%d)\n",
919 v_it_.set_to_list(&vectors_);
920 for (v_it_.mark_cycle_pt(); !v_it_.cycled_list(); v_it_.forward()) {
921 TabVector* v = v_it_.data();
929 void TabFind::SortVectors() {
931 v_it_.set_to_list(&vectors_);
935 void TabFind::EvaluateTabs() {
936 TabVector_IT rule_it(&vectors_);
937 for (rule_it.mark_cycle_pt(); !rule_it.cycled_list(); rule_it.forward()) {
938 TabVector* tab = rule_it.data();
939 if (!tab->IsSeparator()) {
943 tab->Print(
"Too few boxes");
944 delete rule_it.extract();
945 v_it_.set_to_list(&vectors_);
947 tab->Print(
"Evaluated tab");
956 void TabFind::ComputeColumnWidths(
ScrollView* tab_win,
957 ColPartitionGrid* part_grid) {
958 #ifndef GRAPHICS_DISABLED 961 #endif // GRAPHICS_DISABLED 964 STATS col_widths(0, col_widths_size + 1);
965 ApplyPartitionsToColumnWidths(part_grid, &col_widths);
966 #ifndef GRAPHICS_DISABLED 967 if (tab_win != NULL) {
970 #endif // GRAPHICS_DISABLED 974 MakeColumnWidths(col_widths_size, &col_widths);
976 ApplyPartitionsToColumnWidths(part_grid, NULL);
985 void TabFind::ApplyPartitionsToColumnWidths(ColPartitionGrid* part_grid,
990 gsearch.StartFullSearch();
992 while ((part = gsearch.NextFullSearch()) != NULL) {
993 BLOBNBOX_C_IT blob_it(part->boxes());
996 BLOBNBOX* left_blob = blob_it.data();
997 blob_it.move_to_last();
998 BLOBNBOX* right_blob = blob_it.data();
1001 if (left_vector == NULL || left_vector->IsRightTab())
1005 if (right_vector == NULL || right_vector->IsLeftTab())
1011 int width = line_right - line_left;
1012 if (col_widths != NULL) {
1013 AddPartnerVector(left_blob, right_blob, left_vector, right_vector);
1018 ICOORDELT_IT it(&column_widths_);
1019 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1021 if (NearlyEqual<int>(width, w->
y(), 1)) {
1023 if (true_width <= w->y() && true_width > w->
x())
1024 w->
set_x(true_width);
1035 void TabFind::MakeColumnWidths(
int col_widths_size,
STATS* col_widths) {
1036 ICOORDELT_IT w_it(&column_widths_);
1037 int total_col_count = col_widths->
get_total();
1039 int width = col_widths->
mode();
1040 int col_count = col_widths->
pile_count(width);
1041 col_widths->
add(width, -col_count);
1043 for (
int left = width - 1; left > 0 &&
1046 int new_count = col_widths->
pile_count(left);
1047 col_count += new_count;
1048 col_widths->
add(left, -new_count);
1050 for (
int right = width + 1; right < col_widths_size &&
1053 int new_count = col_widths->
pile_count(right);
1054 col_count += new_count;
1055 col_widths->
add(right, -new_count);
1060 w_it.add_after_then_move(w);
1062 tprintf(
"Column of width %d has %d = %.2f%% lines\n",
1064 100.0 * col_count / total_col_count);
1071 void TabFind::MarkVerticalText() {
1073 tprintf(
"Checking for vertical lines\n");
1075 gsearch.StartFullSearch();
1077 while ((blob = gsearch.NextFullSearch()) != NULL) {
1086 int TabFind::FindMedianGutterWidth(TabVector_LIST *lines) {
1087 TabVector_IT it(lines);
1088 int prev_right = -1;
1090 STATS gaps(0, max_gap);
1091 STATS heights(0, max_gap);
1092 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1093 TabVector* v = it.data();
1094 TabVector* partner = v->GetSinglePartner();
1095 if (!v->IsLeftTab() || v->IsSeparator() || !partner)
continue;
1096 heights.add(partner->startpt().x() - v->startpt().x(), 1);
1097 if (prev_right > 0 && v->startpt().x() > prev_right) {
1098 gaps.add(v->startpt().x() - prev_right, 1);
1100 prev_right = partner->startpt().x();
1103 tprintf(
"TabGutter total %d median_gap %.2f median_hgt %.2f\n",
1104 gaps.get_total(), gaps.median(), heights.median());
1106 return static_cast<int>(gaps.median());
1115 bool look_left,
bool ignore_images,
1116 double min_overlap_fraction,
1117 int gap_limit,
int top_y,
int bottom_y) {
1118 GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> sidesearch(
this);
1120 int left = box.
left();
1121 int right = box.
right();
1122 int mid_x = (left + right) / 2;
1123 sidesearch.StartSideSearch(mid_x, bottom_y, top_y);
1128 while ((neighbour = sidesearch.NextSideSearch(look_left)) != NULL) {
1130 tprintf(
"Adjacent blob: considering box:");
1133 if (neighbour == bbox ||
1137 int n_top_y = nbox.
top();
1138 int n_bottom_y = nbox.
bottom();
1139 int v_overlap =
MIN(n_top_y, top_y) -
MAX(n_bottom_y, bottom_y);
1140 int height = top_y - bottom_y;
1141 int n_height = n_top_y - n_bottom_y;
1142 if (v_overlap > min_overlap_fraction *
MIN(height, n_height) &&
1143 (min_overlap_fraction == 0.0 || !
DifferentSizes(height, n_height))) {
1144 int n_left = nbox.
left();
1145 int n_right = nbox.
right();
1146 int h_gap =
MAX(n_left, left) -
MIN(n_right, right);
1147 int n_mid_x = (n_left + n_right) / 2;
1148 if (look_left == (n_mid_x < mid_x) && n_mid_x != mid_x) {
1149 if (h_gap > gap_limit) {
1152 tprintf(
"Giving up due to big gap = %d vs %d\n",
1161 tprintf(
"Collision with like tab of type %d at %d,%d\n",
1169 if (result == NULL || h_gap < best_gap) {
1182 tprintf(
"Insufficient overlap\n");
1186 tprintf(
"Giving up due to end of search\n");
1195 TabVector* left, TabVector* right) {
1198 if (left->IsSeparator()) {
1201 if (v != NULL && v != left && v->IsLeftTab() &&
1202 v->XAtY(left_box.
top()) > left->XAtY(left_box.
top())) {
1204 left->ExtendToBox(left_blob);
1209 v_it_.move_to_first();
1212 if (right->IsSeparator()) {
1215 tprintf(
"Box edge (%d,%d-%d)",
1217 right->Print(
" looking for improvement for");
1220 if (v != NULL && v != right && v->IsRightTab() &&
1221 v->XAtY(right_box.
top()) < right->XAtY(right_box.
top())) {
1223 right->ExtendToBox(right_blob);
1225 right->Print(
"Extended vector");
1232 v_it_.move_to_first();
1234 right->Print(
"Created new vector");
1238 left->AddPartner(right);
1239 right->AddPartner(left);
1244 void TabFind::CleanupTabs() {
1248 TabVector_IT it(&vectors_);
1249 TabVector_IT dead_it(&dead_vectors_);
1250 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1251 TabVector* v = it.data();
1252 if (v->IsSeparator() || v->Partnerless()) {
1253 dead_it.add_after_then_move(it.extract());
1254 v_it_.set_to_list(&vectors_);
1263 BLOBNBOX_IT it(blobs);
1264 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1265 it.data()->rotate_box(rotation);
1271 bool TabFind::Deskew(TabVector_LIST* hlines, BLOBNBOX_LIST* image_blobs,
1273 ComputeDeskewVectors(deskew, reskew);
1284 int width = pixGetWidth(pix_grey);
1285 int height = pixGetHeight(pix_grey);
1286 float angle = atan2(deskew->
y(), deskew->
x());
1288 Pix* pix_rot = pixRotate(pix_grey, -angle, L_ROTATE_AREA_MAP,
1289 L_BRING_IN_WHITE, width, height);
1292 ICOORD center_offset(width / 2, height / 2);
1293 ICOORD new_center_offset(center_offset);
1294 new_center_offset.rotate(*deskew);
1295 image_origin_ += new_center_offset - center_offset;
1299 ICOORD corner_offset((width - pixGetWidth(pix_rot)) / 2,
1300 (pixGetHeight(pix_rot) - height) / 2);
1301 image_origin_ += corner_offset;
1303 pixDestroy(&pix_grey);
1304 pixDestroy(&pix_rot);
1309 TabVector_IT h_it(hlines);
1310 for (h_it.mark_cycle_pt(); !h_it.cycled_list(); h_it.forward()) {
1311 TabVector* h = h_it.data();
1314 TabVector_IT d_it(&dead_vectors_);
1315 for (d_it.mark_cycle_pt(); !d_it.cycled_list(); d_it.forward()) {
1316 TabVector* d = d_it.data();
1319 SetVerticalSkewAndParellelize(0, 1);
1322 grid_box.rotate_large(*deskew);
1323 Init(
gridsize(), grid_box.botleft(), grid_box.topright());
1333 TabVector_LIST* horizontal_lines,
1334 int* min_gutter_width) {
1338 TabVector_LIST ex_verticals;
1339 TabVector_IT ex_v_it(&ex_verticals);
1340 TabVector_LIST vlines;
1341 TabVector_IT v_it(&vlines);
1342 while (!v_it_.empty()) {
1346 ex_v_it.add_after_then_move(v);
1348 v_it.add_after_then_move(v);
1355 int median_gutter = FindMedianGutterWidth(&vlines);
1356 if (median_gutter > *min_gutter_width)
1357 *min_gutter_width = median_gutter;
1359 TabVector_IT h_it(horizontal_lines);
1360 for (h_it.mark_cycle_pt(); !h_it.cycled_list(); h_it.forward()) {
1364 v_it_.add_list_after(horizontal_lines);
1365 v_it_.move_to_first();
1366 h_it.set_to_list(horizontal_lines);
1367 h_it.add_list_after(&ex_verticals);
1378 v_it_.move_to_first();
1379 for (v_it_.mark_cycle_pt(); !v_it_.cycled_list(); v_it_.forward()) {
1380 if (!v_it_.data()->IsSeparator())
1381 delete v_it_.extract();
1389 TabVector_LIST temp_list;
1390 TabVector_IT temp_it(&temp_list);
1391 v_it_.move_to_first();
1395 while (!v_it_.empty()) {
1399 temp_it.add_before_then_move(v);
1401 v_it_.add_list_after(&temp_list);
1402 v_it_.move_to_first();
1405 int tmp = grid_box.
left();
1412 void TabFind::ComputeDeskewVectors(
FCOORD* deskew,
FCOORD* reskew) {
1414 length = sqrt(length);
1417 reskew->
set_x(deskew->
x());
1418 reskew->
set_y(-deskew->
y());
1423 void TabFind::ApplyTabConstraints() {
1424 TabVector_IT it(&vectors_);
1425 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1426 TabVector* v = it.data();
1427 v->SetupConstraints();
1429 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1430 TabVector* v = it.data();
1434 v->SetupPartnerConstraints();
1439 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1440 TabVector* v = it.data();
1441 if (!v->IsRightTab())
1444 TabVector_IT partner_it(it);
1445 for (partner_it.forward(); !partner_it.at_first(); partner_it.forward()) {
1446 TabVector* partner = partner_it.data();
1447 if (!partner->IsLeftTab() || !v->VOverlap(*partner))
1449 v->SetupPartnerConstraints(partner);
1453 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1454 TabVector* v = it.data();
1455 if (!v->IsSeparator())
1456 v->ApplyConstraints();
bool leader_on_left() const
tesseract::ColPartition * owner() const
const TBOX & bounding_box() const
void Image(struct Pix *image, int x_pos, int y_pos)
TabVector * LeftTabForBox(const TBOX &box, bool crossing, bool extended)
void SetBlockRuleEdges(TO_BLOCK *block)
bool y_overlap(const TBOX &box) const
const double kLineFragmentAspectRatio
static bool UnMergeableType(BlobRegionType type)
const double kMaxGutterWidthAbsolute
const double kAlignedFraction
bool NearlyEqual(T x, T y, T tolerance)
void Display(ScrollView *tab_win)
bool UniquelyVertical() const
const ICOORD & tright() const
const ICOORD & topright() const
bool textord_debug_images
bool InsertBlob(bool h_spread, bool v_spread, BLOBNBOX *blob, BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > *grid)
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
void TidyBlobs(TO_BLOCK *block)
void ResetForVerticalText(const FCOORD &rotate, const FCOORD &rerotate, TabVector_LIST *horizontal_lines, int *min_gutter_width)
static bool WithinTestRegion(int detail_level, int x, int y)
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
static bool DifferentSizes(int size1, int size2)
void add(inT32 value, inT32 count)
const int kMaxVerticalSearch
ScrollView * DisplayTabVectors(ScrollView *tab_win)
const int kTabRadiusFactor
const int kRaggedGutterMultiple
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)
BlobTextFlowType flow() const
TabVector * RightTabForBox(const TBOX &box, bool crossing, bool extended)
static int SortVectorsByKey(const void *v1, const void *v2)
static bool VeryDifferentSizes(int size1, int size2)
int RightEdgeForBox(const TBOX &box, bool crossing, bool extended)
const int kMinEvaluatedTabs
const int kColumnWidthFactor
void DisplayBoxes(ScrollView *window)
void set_with_shrink(int x, int y)
Set from the given x,y, shrinking the vector to fit if needed.
TabType right_tab_type() const
static int SortKey(const ICOORD &vertical, int x, int y)
void DeleteUnownedNoise()
int ExtendedOverlap(int top_y, int bottom_y) const
bool CommonWidth(int width)
bool leader_on_right() const
void plot_noise_blobs(ScrollView *to_win)
static const STRING & textord_debug_pix()
int VOverlap(const TabVector &other) const
void set_right_rule(int new_right)
void set_x(float xin)
rewrite function
const double kCosMaxSkewAngle
bool textord_tabfind_show_finaltabs
BLOBNBOX_LIST noise_blobs
bool joined_to_prev() const
static void MergeSimilarTabVectors(const ICOORD &vertical, TabVector_LIST *vectors, BlobGrid *grid)
ScrollView * MakeWindow(int x, int y, const char *window_name)
void set_left_rule(int new_left)
void StartSideSearch(int x, int ymin, int ymax)
int LeftEdgeForBox(const TBOX &box, bool crossing, bool extended)
inT16 x() const
access function
void InsertBlobsToGrid(bool h_spread, bool v_spread, BLOBNBOX_LIST *blobs, BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > *grid)
BLOBNBOX_LIST large_blobs
BBC * NextSideSearch(bool right_to_left)
void set_y(float yin)
rewrite function
void Rotate(const FCOORD &rotation)
TabVector_LIST * vectors()
void Deskew(const FCOORD &deskew)
void set_right_tab_type(TabType new_type)
GridSearch< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > BlobGridSearch
const int kMinLinesInColumn
const double kMinColumnWidth
void Rectangle(int x1, int y1, int x2, int y2)
int GutterWidth(int bottom_y, int top_y, const TabVector &v, bool ignore_unmergeables, int max_gutter_width, int *required_shift)
int textord_debug_tabfind
const int kMaxRaggedSearch
void set_left_tab_type(TabType new_type)
TabVector * FindVerticalAlignment(AlignedBlobParams align_params, BLOBNBOX *bbox, int *vertical_x, int *vertical_y)
inT32 pile_count(inT32 value) const
BLOBNBOX_LIST small_blobs
void plot_graded_blobs(ScrollView *to_win)
void rotate_large(const FCOORD &vec)
const int kMinVerticalSearch
void set_x(inT16 xin)
rewrite function
ScrollView * FindInitialTabVectors(BLOBNBOX_LIST *image_blobs, int min_gutter_width, double tabfind_aligned_gap_fraction, TO_BLOCK *block)
const ICOORD & bleft() const
bool textord_tabfind_show_initialtabs
void SetupTabSearch(int x, int y, int *min_key, int *max_key)
void GutterWidthAndNeighbourGap(int tab_x, int mean_height, int max_gutter, bool left, BLOBNBOX *bbox, int *gutter_width, int *neighbour_gap)
void set_region_type(BlobRegionType new_type)
TabFind(int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVector_LIST *vlines, int vertical_x, int vertical_y, int resolution)
void set_right_crossing_rule(int new_right)
const double kMinFractionalLinesInColumn
BlobRegionType region_type() const
void SetBlobRuleEdges(BLOBNBOX_LIST *blobs)
#define BOOL_VAR(name, val, comment)
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
static void RotateBlobList(const FCOORD &rotation, BLOBNBOX_LIST *blobs)
void DontFindTabVectors(BLOBNBOX_LIST *image_blobs, TO_BLOCK *block, FCOORD *deskew, FCOORD *reskew)
const ICOORD & botleft() const
void set_left_crossing_rule(int new_left)
TabType left_tab_type() const
ScrollView * DisplayTabs(const char *window_name, ScrollView *tab_win)
inT16 y() const
access_function