21# include "config_auto.h"
31#include <allheaders.h>
37static INT_VAR(textord_tabfind_show_images,
false,
"Show image blobs");
61static bool HScanForEdge(uint32_t *data,
int wpl,
int x_start,
int x_end,
int min_count,
62 int mid_width,
int max_count,
int y_end,
int y_step,
int *y_start) {
64 for (
int y = *y_start;
y != y_end;
y += y_step) {
68 uint32_t *line = data + wpl *
y;
69 for (
int x = x_start;
x < x_end; ++
x) {
70 if (GET_DATA_BIT(line,
x)) {
74 if (mid_rows == 0 && pix_count < min_count) {
80 if (pix_count > max_count) {
84 if (mid_rows > mid_width) {
98static bool VScanForEdge(uint32_t *data,
int wpl,
int y_start,
int y_end,
int min_count,
99 int mid_width,
int max_count,
int x_end,
int x_step,
int *x_start) {
101 for (
int x = *x_start;
x != x_end;
x += x_step) {
103 uint32_t *line = data + y_start * wpl;
104 for (
int y = y_start;
y < y_end; ++
y, line += wpl) {
105 if (GET_DATA_BIT(line,
x)) {
109 if (mid_cols == 0 && pix_count < min_count) {
115 if (pix_count > max_count) {
119 if (mid_cols > mid_width) {
135static bool pixNearlyRectangular(Image pix,
double min_fraction,
double max_fraction,
136 double max_skew_gradient,
int *x_start,
int *y_start,
137 int *x_end,
int *y_end) {
140 *x_end = pixGetWidth(pix);
142 *y_end = pixGetHeight(pix);
144 uint32_t *data = pixGetData(pix);
145 int wpl = pixGetWpl(pix);
146 bool any_cut =
false;
147 bool left_done =
false;
148 bool right_done =
false;
149 bool top_done =
false;
150 bool bottom_done =
false;
154 int width = *x_end - *x_start;
155 int min_count =
static_cast<int>(width * min_fraction);
156 int max_count =
static_cast<int>(width * max_fraction);
157 int edge_width =
static_cast<int>(width * max_skew_gradient);
158 if (HScanForEdge(data, wpl, *x_start, *x_end, min_count, edge_width, max_count, *y_end, 1,
165 if (HScanForEdge(data, wpl, *x_start, *x_end, min_count, edge_width, max_count, *y_start, -1,
174 int height = *y_end - *y_start;
175 min_count =
static_cast<int>(height * min_fraction);
176 max_count =
static_cast<int>(height * max_fraction);
177 edge_width =
static_cast<int>(height * max_skew_gradient);
178 if (VScanForEdge(data, wpl, *y_start, *y_end, min_count, edge_width, max_count, *x_end, 1,
185 if (VScanForEdge(data, wpl, *y_start, *y_end, min_count, edge_width, max_count, *x_start, -1,
196 return left_done && right_done && top_done && bottom_done;
206static void ConnCompAndRectangularize(Image pix, DebugPixa *pixa_debug, Boxa **boxa,
211 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
212 pixa_debug->AddPix(pix,
"Conncompimage");
215 *boxa = pixConnComp(pix, pixa, 8);
220 if (*boxa !=
nullptr && *pixa !=
nullptr) {
221 npixes = pixaGetCount(*pixa);
223 for (
int i = 0;
i < npixes; ++
i) {
224 int x_start, x_end, y_start, y_end;
225 Image img_pix = pixaGetPix(*pixa,
i, L_CLONE);
226 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
227 pixa_debug->AddPix(img_pix,
"A component");
231 Image simple_pix = pixCreate(x_end - x_start, y_end - y_start, 1);
232 pixSetAll(simple_pix);
235 pixaReplacePix(*pixa,
i, simple_pix,
nullptr);
236 img_pix = pixaGetPix(*pixa,
i, L_CLONE);
238 l_int32
x,
y, width, height;
239 boxaGetBoxGeometry(*boxa,
i, &
x, &
y, &width, &height);
240 Box *simple_box = boxCreate(
x + x_start,
y + y_start, x_end - x_start, y_end - y_start);
241 boxaReplaceBox(*boxa,
i, simple_box);
253 auto width = pixGetWidth(pix);
254 auto height = pixGetHeight(pix);
260 return pixCreate(width, height, 1);
264 Image pixr = pixReduceRankBinaryCascade(pix, 1, 0, 0, 0);
265 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
266 pixa_debug->
AddPix(pixr,
"CascadeReduced");
270 l_int32 ht_found = 0;
271 Pixa *pixadb = (textord_tabfind_show_images && pixa_debug !=
nullptr) ? pixaCreate(0) :
nullptr;
272 Image pixht2 = pixGenerateHalftoneMask(pixr,
nullptr, &ht_found, pixadb);
274 Image pixdb = pixaDisplayTiledInColumns(pixadb, 3, 1.0, 20, 2);
275 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
276 pixa_debug->
AddPix(pixdb,
"HalftoneMask");
279 pixaDestroy(&pixadb);
282 if (!ht_found && pixht2 !=
nullptr) {
285 if (pixht2 ==
nullptr) {
286 return pixCreate(width, height, 1);
290 Image pixht = pixExpandReplicate(pixht2, 2);
291 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
292 pixa_debug->
AddPix(pixht,
"HalftoneReplicated");
297 Image pixt = pixSeedfillBinary(
nullptr, pixht, pix, 8);
302 Image pixfinemask = pixReduceRankBinaryCascade(pixht, 1, 1, 3, 3);
303 pixDilateBrick(pixfinemask, pixfinemask, 5, 5);
304 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
305 pixa_debug->
AddPix(pixfinemask,
"FineMask");
307 Image pixreduced = pixReduceRankBinaryCascade(pixht, 1, 1, 1, 1);
308 Image pixreduced2 = pixReduceRankBinaryCascade(pixreduced, 3, 3, 3, 0);
310 pixDilateBrick(pixreduced2, pixreduced2, 5, 5);
311 Image pixcoarsemask = pixExpandReplicate(pixreduced2, 8);
313 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
314 pixa_debug->
AddPix(pixcoarsemask,
"CoarseMask");
317 pixcoarsemask &= pixfinemask;
320 pixDilateBrick(pixcoarsemask, pixcoarsemask, 3, 3);
321 Image pixmask = pixExpandReplicate(pixcoarsemask, 16);
323 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
324 pixa_debug->
AddPix(pixmask,
"MaskDilated");
329 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
330 pixa_debug->
AddPix(pixht,
"FinalMask");
333 Image result = pixCreate(width, height, 1);
344 Box *input_box = boxCreate(*x_start, *y_start, *x_end - *x_start, *y_end - *y_start);
345 Box *output_box =
nullptr;
346 pixClipBoxToForeground(pix, input_box,
nullptr, &output_box);
347 bool result = output_box !=
nullptr;
349 l_int32
x,
y, width, height;
350 boxGetGeometry(output_box, &
x, &
y, &width, &height);
355 boxDestroy(&output_box);
357 boxDestroy(&input_box);
365 const uint8_t *point) {
369 line_vector[
i] =
static_cast<int>(line2[
i]) -
static_cast<int>(line1[
i]);
370 point_vector[
i] =
static_cast<int>(point[
i]) -
static_cast<int>(line1[
i]);
372 line_vector[L_ALPHA_CHANNEL] = 0;
375 cross[COLOR_RED] = line_vector[COLOR_GREEN] * point_vector[COLOR_BLUE] -
376 line_vector[COLOR_BLUE] * point_vector[COLOR_GREEN];
377 cross[COLOR_GREEN] = line_vector[COLOR_BLUE] * point_vector[COLOR_RED] -
378 line_vector[COLOR_RED] * point_vector[COLOR_BLUE];
379 cross[COLOR_BLUE] = line_vector[COLOR_RED] * point_vector[COLOR_GREEN] -
380 line_vector[COLOR_GREEN] * point_vector[COLOR_RED];
381 cross[L_ALPHA_CHANNEL] = 0;
383 double cross_sq = 0.0;
384 double line_sq = 0.0;
386 cross_sq +=
static_cast<double>(cross[j]) * cross[j];
387 line_sq +=
static_cast<double>(line_vector[j]) * line_vector[j];
389 if (line_sq == 0.0) {
392 return cross_sq / line_sq;
439 TBOX search_box(box1);
442 if (box1.
x_gap(box2) <= 0) {
448 if (box1.
y_gap(box2) <= 0) {
467 TBOX rotated_im_box(im_box);
468 rotated_im_box.
rotate(rotation);
470 pixRasterop(rect_pix, 0, 0, box.
width(), box.
height(), PIX_SRC, pix,
471 box.
left() - rotated_im_box.
left(), rotated_im_box.
top() - box.
top());
473 pixCountPixels(rect_pix, &result,
nullptr);
482static void AttemptToShrinkBox(
const FCOORD &rotation,
const FCOORD &rerotation,
const TBOX &im_box,
484 TBOX rotated_box(*slice);
485 rotated_box.rotate(rerotation);
486 TBOX rotated_im_box(im_box);
487 rotated_im_box.rotate(rerotation);
488 int left = rotated_box.left() - rotated_im_box.left();
489 int right = rotated_box.right() - rotated_im_box.left();
490 int top = rotated_im_box.top() - rotated_box.top();
491 int bottom = rotated_im_box.top() - rotated_box.bottom();
493 top = rotated_im_box.top() - top;
494 bottom = rotated_im_box.top() - bottom;
495 left += rotated_im_box.left();
496 right += rotated_im_box.left();
497 rotated_box.set_to_given_coords(left, bottom, right, top);
498 rotated_box.rotate(rotation);
499 slice->
set_left(rotated_box.left());
527static void CutChunkFromParts(
const TBOX &box,
const TBOX &im_box,
const FCOORD &rotation,
528 const FCOORD &rerotation, Image pix, ColPartition_LIST *part_list) {
530 ColPartition_IT part_it(part_list);
532 ColPartition *part = part_it.data();
533 TBOX part_box = part->bounding_box();
534 if (part_box.overlap(box)) {
540 if (box.top() < part_box.top()) {
541 TBOX slice(part_box);
544 AttemptToShrinkBox(rotation, rerotation, im_box, pix, &slice);
545 part_it.add_before_stay_put(
550 if (box.left() > part_box.left()) {
551 TBOX slice(part_box);
553 if (box.top() < part_box.top()) {
556 if (box.bottom() > part_box.bottom()) {
560 AttemptToShrinkBox(rotation, rerotation, im_box, pix, &slice);
561 part_it.add_before_stay_put(
566 if (box.right() < part_box.right()) {
567 TBOX slice(part_box);
569 if (box.top() < part_box.top()) {
572 if (box.bottom() > part_box.bottom()) {
576 AttemptToShrinkBox(rotation, rerotation, im_box, pix, &slice);
577 part_it.add_before_stay_put(
582 if (box.bottom() > part_box.bottom()) {
583 TBOX slice(part_box);
586 AttemptToShrinkBox(rotation, rerotation, im_box, pix, &slice);
587 part_it.add_before_stay_put(
592 delete part_it.extract();
595 }
while (!part_it.at_first());
605static void DivideImageIntoParts(
const TBOX &im_box,
const FCOORD &rotation,
606 const FCOORD &rerotation, Image pix,
609 ColPartition *pix_part =
611 ColPartition_IT part_it(part_list);
612 part_it.add_after_then_move(pix_part);
614 rectsearch->StartRectSearch(im_box);
616 while ((part = rectsearch->NextRectSearch()) !=
nullptr) {
617 TBOX part_box = part->bounding_box();
618 if (part_box.contains(im_box) && part->flow() >=
BTFT_CHAIN) {
620 for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
621 ColPartition *pix_part = part_it.extract();
622 pix_part->DeleteBoxes();
627 TBOX overlap_box = part_box.intersection(im_box);
630 if (black_area * 2 < part_box.area() || !im_box.contains(part_box)) {
633 int padding = part->blob_type() ==
BRT_VERT_TEXT ? part_box.width() : part_box.height();
634 part_box.set_top(part_box.top() + padding / 2);
635 part_box.set_bottom(part_box.bottom() - padding / 2);
636 CutChunkFromParts(part_box, im_box, rotation, rerotation, pix, part_list);
642 if (part_list->empty()) {
650static int ExpandImageLeft(
const TBOX &box,
int left_limit, ColPartitionGrid *part_grid) {
654 search.StartSideSearch(box.left(), box.bottom(), box.top());
655 while ((part =
search.NextSideSearch(
true)) !=
nullptr) {
657 const TBOX &part_box(part->bounding_box());
658 if (part_box.y_gap(box) < 0) {
659 if (part_box.right() > left_limit && part_box.right() < box.left()) {
660 left_limit = part_box.right();
666 if (part !=
nullptr) {
668 TBOX search_box(left_limit, box.bottom(), box.left(), box.top());
669 search.StartRectSearch(search_box);
670 while ((part =
search.NextRectSearch()) !=
nullptr) {
672 const TBOX &part_box(part->bounding_box());
673 if (part_box.y_gap(box) < 0) {
674 if (part_box.right() > left_limit && part_box.right() < box.left()) {
675 left_limit = part_box.right();
686static int ExpandImageRight(
const TBOX &box,
int right_limit, ColPartitionGrid *part_grid) {
690 search.StartSideSearch(box.right(), box.bottom(), box.top());
691 while ((part =
search.NextSideSearch(
false)) !=
nullptr) {
693 const TBOX &part_box(part->bounding_box());
694 if (part_box.y_gap(box) < 0) {
695 if (part_box.left() < right_limit && part_box.left() > box.right()) {
696 right_limit = part_box.left();
702 if (part !=
nullptr) {
704 TBOX search_box(box.left(), box.bottom(), right_limit, box.top());
705 search.StartRectSearch(search_box);
706 while ((part =
search.NextRectSearch()) !=
nullptr) {
708 const TBOX &part_box(part->bounding_box());
709 if (part_box.y_gap(box) < 0) {
710 if (part_box.left() < right_limit && part_box.left() > box.right()) {
711 right_limit = part_box.left();
722static int ExpandImageBottom(
const TBOX &box,
int bottom_limit, ColPartitionGrid *part_grid) {
726 search.StartVerticalSearch(box.left(), box.right(), box.bottom());
727 while ((part =
search.NextVerticalSearch(
true)) !=
nullptr) {
729 const TBOX &part_box(part->bounding_box());
730 if (part_box.x_gap(box) < 0) {
731 if (part_box.top() > bottom_limit && part_box.top() < box.bottom()) {
732 bottom_limit = part_box.top();
738 if (part !=
nullptr) {
740 TBOX search_box(box.left(), bottom_limit, box.right(), box.bottom());
741 search.StartRectSearch(search_box);
742 while ((part =
search.NextRectSearch()) !=
nullptr) {
744 const TBOX &part_box(part->bounding_box());
745 if (part_box.x_gap(box) < 0) {
746 if (part_box.top() > bottom_limit && part_box.top() < box.bottom()) {
747 bottom_limit = part_box.top();
758static int ExpandImageTop(
const TBOX &box,
int top_limit, ColPartitionGrid *part_grid) {
762 search.StartVerticalSearch(box.left(), box.right(), box.top());
763 while ((part =
search.NextVerticalSearch(
false)) !=
nullptr) {
765 const TBOX &part_box(part->bounding_box());
766 if (part_box.x_gap(box) < 0) {
767 if (part_box.bottom() < top_limit && part_box.bottom() > box.top()) {
768 top_limit = part_box.bottom();
774 if (part !=
nullptr) {
776 TBOX search_box(box.left(), box.top(), box.right(), top_limit);
777 search.StartRectSearch(search_box);
778 while ((part =
search.NextRectSearch()) !=
nullptr) {
780 const TBOX &part_box(part->bounding_box());
781 if (part_box.x_gap(box) < 0) {
782 if (part_box.bottom() < top_limit && part_box.bottom() > box.top()) {
783 top_limit = part_box.bottom();
797 ColPartitionGrid *part_grid,
TBOX *expanded_box) {
798 *expanded_box = im_box;
801 expanded_box->set_left(ExpandImageLeft(im_box, limit_box.left(), part_grid));
804 expanded_box->set_right(ExpandImageRight(im_box, limit_box.right(), part_grid));
807 expanded_box->set_top(ExpandImageTop(im_box, limit_box.top(), part_grid));
810 expanded_box->set_bottom(ExpandImageBottom(im_box, limit_box.bottom(), part_grid));
815 return expanded_box->area() - im_box.area();
822static void MaximalImageBoundingBox(ColPartitionGrid *part_grid,
TBOX *im_box) {
824 memset(dunnit, 0,
sizeof(dunnit));
825 TBOX limit_box(part_grid->bleft().x(), part_grid->bleft().y(), part_grid->tright().x(),
826 part_grid->tright().y());
827 TBOX text_box(*im_box);
828 for (
int iteration = 0; iteration <
BND_COUNT; ++iteration) {
833 for (
int dir = 0; dir <
BND_COUNT; ++dir) {
837 int area_delta = ExpandImageDir(bnd, text_box, limit_box, part_grid, &expanded_boxes[bnd]);
838 if (best_delta < 0 || area_delta < best_delta) {
839 best_delta = area_delta;
845 dunnit[best_dir] =
true;
846 text_box = expanded_boxes[best_dir];
855static void DeletePartition(ColPartition *part) {
864 part->SetBlobTypes();
883 ColPartitionGrid *part_grid, ColPartition **part_ptr) {
884 ColPartition *image_part = *part_ptr;
885 TBOX im_part_box = image_part->bounding_box();
886 if (textord_tabfind_show_images > 1) {
887 tprintf(
"Searching for merge with image part:");
890 max_image_box.print();
892 rectsearch->StartRectSearch(max_image_box);
894 ColPartition *best_part =
nullptr;
896 while ((part = rectsearch->NextRectSearch()) !=
nullptr) {
897 if (textord_tabfind_show_images > 1) {
898 tprintf(
"Considering merge with part:");
900 if (im_part_box.contains(part->bounding_box())) {
902 }
else if (!max_image_box.contains(part->bounding_box())) {
903 tprintf(
"Not within text box\n");
914 TBOX box = part->bounding_box();
915 if (max_image_box.contains(box) && part->blob_type() !=
BRT_NOISE) {
916 if (im_part_box.contains(box)) {
918 rectsearch->RemoveBBox();
919 DeletePartition(part);
922 int x_dist = std::max(0, box.x_gap(im_part_box));
923 int y_dist = std::max(0, box.y_gap(im_part_box));
924 int dist = x_dist * x_dist + y_dist * y_dist;
925 if (dist > box.area() || dist > im_part_box.area()) {
928 if (best_part ==
nullptr || dist < best_dist) {
935 if (best_part !=
nullptr) {
937 TBOX box = best_part->bounding_box();
938 if (textord_tabfind_show_images > 1) {
939 tprintf(
"Merging image part:");
946 DeletePartition(image_part);
947 part_grid->RemoveBBox(best_part);
948 DeletePartition(best_part);
949 rectsearch->RepositionIterator();
957static int IntersectArea(
const TBOX &box, ColPartition_LIST *part_list) {
958 int intersect_area = 0;
959 ColPartition_IT part_it(part_list);
961 for (part_it.mark_cycle_pt(); !part_it.cycled_list(); part_it.forward()) {
962 ColPartition *image_part = part_it.data();
963 TBOX intersect = box.intersection(image_part->bounding_box());
964 intersect_area += intersect.area();
966 return intersect_area;
974static bool TestWeakIntersectedPart(
const TBOX &im_box, ColPartition_LIST *part_list,
975 ColPartition *part) {
978 const TBOX &part_box = part->bounding_box();
979 if (im_box.contains(part_box)) {
980 int area = part_box.area();
981 int intersect_area = IntersectArea(part_box, part_list);
982 if (area < 2 * intersect_area) {
995static void EliminateWeakParts(
const TBOX &im_box, ColPartitionGrid *part_grid,
996 ColPartition_LIST *big_parts, ColPartition_LIST *part_list) {
999 rectsearch.StartRectSearch(im_box);
1000 while ((part = rectsearch.NextRectSearch()) !=
nullptr) {
1001 if (TestWeakIntersectedPart(im_box, part_list, part)) {
1004 rectsearch.RemoveBBox();
1005 DeletePartition(part);
1011 part->SetBlobTypes();
1015 ColPartition_IT big_it(big_parts);
1016 for (big_it.mark_cycle_pt(); !big_it.cycled_list(); big_it.forward()) {
1017 part = big_it.data();
1018 if (TestWeakIntersectedPart(im_box, part_list, part)) {
1020 DeletePartition(big_it.extract());
1029static bool ScanForOverlappingText(ColPartitionGrid *part_grid,
TBOX *box) {
1031 TBOX padded_box(*box);
1033 rectsearch.StartRectSearch(padded_box);
1035 bool any_text_in_padded_rect =
false;
1036 while ((part = rectsearch.NextRectSearch()) !=
nullptr) {
1039 any_text_in_padded_rect =
true;
1040 const TBOX &part_box = part->bounding_box();
1041 if (box->overlap(part_box)) {
1046 if (!any_text_in_padded_rect) {
1056static void MarkAndDeleteImageParts(
const FCOORD &rerotate, ColPartitionGrid *part_grid,
1057 ColPartition_LIST *image_parts, Image image_pix) {
1058 if (image_pix ==
nullptr) {
1061 int imageheight = pixGetHeight(image_pix);
1062 ColPartition_IT part_it(image_parts);
1063 for (; !part_it.empty(); part_it.forward()) {
1064 ColPartition *part = part_it.extract();
1065 TBOX part_box = part->bounding_box();
1071 part_box.rotate(rerotate);
1072 int left = part_box.left();
1073 int top = part_box.top();
1074 pixRasterop(image_pix, left, imageheight - top, part_box.width(), part_box.height(), PIX_SET,
1077 DeletePartition(part);
1091 ColPartition_LIST parts_list;
1092 ColPartition_IT part_it(&parts_list);
1099 part_it.add_after_then_move(part);
1104 MarkAndDeleteImageParts(rerotation, part_grid, &parts_list, image_mask);
1111 if (part_grid !=
nullptr) {
1115 gsearch.StartFullSearch();
1117 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1121 const TBOX &part_box = part->bounding_box();
1124 gsearch.RemoveBBox();
1125 DeletePartition(part);
1144 ColPartition_LIST *big_parts) {
1145 int imageheight = pixGetHeight(image_pix);
1148 ConnCompAndRectangularize(image_pix, pixa_debug, &boxa, &pixa);
1151 if (boxa !=
nullptr && pixa !=
nullptr) {
1152 nboxes = boxaGetCount(boxa);
1154 for (
int i = 0;
i < nboxes; ++
i) {
1155 l_int32
x,
y, width, height;
1156 boxaGetBoxGeometry(boxa,
i, &
x, &
y, &width, &height);
1157 Image pix = pixaGetPix(pixa,
i, L_CLONE);
1158 TBOX im_box(
x, imageheight -
y - height,
x + width, imageheight -
y);
1162 ColPartition_LIST part_list;
1163 DivideImageIntoParts(im_box, rotation, rerotation, pix, &rectsearch, &part_list);
1164 if (textord_tabfind_show_images && pixa_debug !=
nullptr) {
1165 pixa_debug->
AddPix(pix,
"ImageComponent");
1166 tprintf(
"Component has %d parts\n", part_list.length());
1169 if (!part_list.empty()) {
1170 ColPartition_IT part_it(&part_list);
1171 if (part_list.singleton()) {
1176 TBOX text_box(im_box);
1177 MaximalImageBoundingBox(part_grid, &text_box);
1178 while (ExpandImageIntoParts(text_box, &rectsearch, part_grid, &part)) {
1181 part_it.set_to_list(&part_list);
1182 part_it.add_after_then_move(part);
1185 EliminateWeakParts(im_box, part_grid, big_parts, &part_list);
1187 for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
1190 part_grid->
InsertBBox(
true,
true, image_part);
1191 if (!part_it.at_last()) {
1201 DeleteSmallImages(part_grid);
1202#ifndef GRAPHICS_DISABLED
1203 if (textord_tabfind_show_images) {
#define INT_VAR(name, val, comment)
const double kMinRectangularFraction
void tprintf(const char *format,...)
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
LIST search(LIST list, void *key, int_compare is_equal)
const double kMaxRectangularGradient
const int kMinImageFindSize
const double kMaxRectangularFraction
void AddPix(const Image pix, const char *caption)
int y_gap(const TBOX &box) const
TDimension height() const
void rotate(const FCOORD &vec)
int x_gap(const TBOX &box) const
TDimension bottom() const
void SetUniqueMode(bool mode)
void DisplayBoxes(ScrollView *window)
void InsertBBox(bool h_spread, bool v_spread, BBC *bbox)
ScrollView * MakeWindow(int x, int y, const char *window_name)
static ColPartition * FakePartition(const TBOX &box, PolyBlockType block_type, BlobRegionType blob_type, BlobTextFlowType flow)
BlobRegionType blob_type() const
const TBOX & bounding_box() const
void AddPartner(bool upper, ColPartition *partner)
static bool BlankImageInBetween(const TBOX &box1, const TBOX &box2, const TBOX &im_box, const FCOORD &rotation, Image pix)
static bool BoundsWithinRect(Image pix, int *x_start, int *y_start, int *x_end, int *y_end)
static void FindImagePartitions(Image image_pix, const FCOORD &rotation, const FCOORD &rerotation, TO_BLOCK *block, TabFind *tab_grid, DebugPixa *pixa_debug, ColPartitionGrid *part_grid, ColPartition_LIST *big_parts)
static void TransferImagePartsToImageMask(const FCOORD &rerotation, ColPartitionGrid *part_grid, Image image_mask)
static Image FindImages(Image pix, DebugPixa *pixa_debug)
static int CountPixelsInRotatedBox(TBOX box, const TBOX &im_box, const FCOORD &rotation, Image pix)
static double ColorDistanceFromLine(const uint8_t *line1, const uint8_t *line2, const uint8_t *point)