tesseract
5.0.0-alpha-619-ge9db
|
#include <colpartitiongrid.h>
|
| ColPartitionGrid ()=default |
|
| ColPartitionGrid (int gridsize, const ICOORD &bleft, const ICOORD &tright) |
|
| ~ColPartitionGrid () override=default |
|
void | HandleClick (int x, int y) override |
|
void | Merges (std::function< bool(ColPartition *, TBOX *)> box_cb, std::function< bool(const ColPartition *, const ColPartition *)> confirm_cb) |
|
bool | MergePart (std::function< bool(ColPartition *, TBOX *)> box_cb, std::function< bool(const ColPartition *, const ColPartition *)> confirm_cb, ColPartition *part) |
|
int | ComputeTotalOverlap (ColPartitionGrid **overlap_grid) |
|
void | FindOverlappingPartitions (const TBOX &box, const ColPartition *not_this, ColPartition_CLIST *parts) |
|
ColPartition * | BestMergeCandidate (const ColPartition *part, ColPartition_CLIST *candidates, bool debug, std::function< bool(const ColPartition *, const ColPartition *)> confirm_cb, int *overlap_increase) |
|
void | SplitOverlappingPartitions (ColPartition_LIST *big_parts) |
|
bool | GridSmoothNeighbours (BlobTextFlowType source_type, Pix *nontext_map, const TBOX &im_box, const FCOORD &rerotation) |
|
void | ReflectInYAxis () |
|
void | Deskew (const FCOORD &deskew) |
|
void | ExtractPartitionsAsBlocks (BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks) |
|
void | SetTabStops (TabFind *tabgrid) |
|
bool | MakeColPartSets (PartSetVector *part_sets) |
|
ColPartitionSet * | MakeSingleColumnSet (WidthCallback cb) |
|
void | ClaimBoxes () |
|
void | ReTypeBlobs (BLOBNBOX_LIST *im_blobs) |
|
void | RecomputeBounds (int gridsize, const ICOORD &bleft, const ICOORD &tright, const ICOORD &vertical) |
|
void | GridFindMargins (ColPartitionSet **best_columns) |
|
void | ListFindMargins (ColPartitionSet **best_columns, ColPartition_LIST *parts) |
|
void | DeleteParts () |
|
void | DeleteUnknownParts (TO_BLOCK *block) |
|
void | DeleteNonLeaderParts () |
|
void | FindFigureCaptions () |
|
void | FindPartitionPartners () |
|
void | FindPartitionPartners (bool upper, ColPartition *part) |
|
void | FindVPartitionPartners (bool to_the_left, ColPartition *part) |
|
void | RefinePartitionPartners (bool get_desperate) |
|
| BBGrid () |
|
| BBGrid (int gridsize, const ICOORD &bleft, const ICOORD &tright) |
|
| ~BBGrid () override |
|
void | Init (int gridsize, const ICOORD &bleft, const ICOORD &tright) |
|
void | Clear () |
|
void | ClearGridData (void(*free_method)(ColPartition *)) |
|
void | InsertBBox (bool h_spread, bool v_spread, ColPartition *bbox) |
|
void | InsertPixPtBBox (int left, int bottom, Pix *pix, ColPartition *bbox) |
|
void | RemoveBBox (ColPartition *bbox) |
|
bool | RectangleEmpty (const TBOX &rect) |
|
IntGrid * | CountCellElements () |
|
ScrollView * | MakeWindow (int x, int y, const char *window_name) |
|
void | DisplayBoxes (ScrollView *window) |
|
void | AssertNoDuplicates () |
|
| GridBase ()=default |
|
| GridBase (int gridsize, const ICOORD &bleft, const ICOORD &tright) |
|
virtual | ~GridBase () |
|
void | Init (int gridsize, const ICOORD &bleft, const ICOORD &tright) |
|
int | gridsize () const |
|
int | gridwidth () const |
|
int | gridheight () const |
|
const ICOORD & | bleft () const |
|
const ICOORD & | tright () const |
|
void | GridCoords (int x, int y, int *grid_x, int *grid_y) const |
|
void | ClipGridCoords (int *x, int *y) const |
|
Definition at line 32 of file colpartitiongrid.h.
◆ ColPartitionGrid() [1/2]
tesseract::ColPartitionGrid::ColPartitionGrid |
( |
| ) |
|
|
default |
◆ ColPartitionGrid() [2/2]
tesseract::ColPartitionGrid::ColPartitionGrid |
( |
int |
gridsize, |
|
|
const ICOORD & |
bleft, |
|
|
const ICOORD & |
tright |
|
) |
| |
◆ ~ColPartitionGrid()
tesseract::ColPartitionGrid::~ColPartitionGrid |
( |
| ) |
|
|
overridedefault |
◆ BestMergeCandidate()
Definition at line 399 of file colpartitiongrid.cpp.
403 if (overlap_increase !=
nullptr)
404 *overlap_increase = 0;
405 if (candidates->empty())
413 const TBOX& part_box = part->bounding_box();
414 ColPartition_C_IT it(candidates);
415 ColPartition* best_candidate =
nullptr;
417 TBOX full_box(part_box);
418 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
419 ColPartition* candidate = it.data();
420 full_box += candidate->bounding_box();
423 ColPartition_CLIST neighbours;
428 tprintf(
"Finding best merge candidate from %d, %d neighbours for box:",
429 candidates->length(), neighbours.length());
437 ColPartition_CLIST non_candidate_neighbours;
438 non_candidate_neighbours.set_subtract(SortByBoxLeft<ColPartition>,
true,
439 &neighbours, candidates);
440 int worst_nc_increase = 0;
441 int best_increase = INT32_MAX;
443 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
444 ColPartition* candidate = it.data();
445 if (confirm_cb !=
nullptr && !confirm_cb(part, candidate)) {
447 tprintf(
"Candidate not confirmed:");
448 candidate->bounding_box().print();
452 int increase = IncreaseInOverlap(part, candidate, ok_overlap, &neighbours);
453 const TBOX& cand_box = candidate->bounding_box();
454 if (best_candidate ==
nullptr || increase < best_increase) {
455 best_candidate = candidate;
456 best_increase = increase;
459 tprintf(
"New best merge candidate has increase %d, area %d, over box:",
460 increase, best_area);
464 }
else if (increase == best_increase) {
466 if (area < best_area) {
468 best_candidate = candidate;
471 increase = IncreaseInOverlap(part, candidate, ok_overlap,
472 &non_candidate_neighbours);
473 if (increase > worst_nc_increase)
474 worst_nc_increase = increase;
476 if (best_increase > 0) {
483 if (worst_nc_increase < best_increase &&
484 TestCompatibleCandidates(*part, debug, candidates)) {
485 best_increase = worst_nc_increase;
488 if (overlap_increase !=
nullptr)
489 *overlap_increase = best_increase;
490 return best_candidate;
◆ ClaimBoxes()
void tesseract::ColPartitionGrid::ClaimBoxes |
( |
| ) |
|
Definition at line 857 of file colpartitiongrid.cpp.
860 gsearch.StartFullSearch();
862 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
◆ ComputeTotalOverlap()
int tesseract::ColPartitionGrid::ComputeTotalOverlap |
( |
ColPartitionGrid ** |
overlap_grid | ) |
|
Definition at line 312 of file colpartitiongrid.cpp.
313 int total_overlap = 0;
316 gsearch.StartFullSearch();
318 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
319 ColPartition_CLIST neighbors;
320 const TBOX& part_box = part->bounding_box();
322 ColPartition_C_IT n_it(&neighbors);
323 bool any_part_overlap =
false;
324 for (n_it.mark_cycle_pt(); !n_it.cycled_list(); n_it.forward()) {
325 const TBOX& n_box = n_it.data()->bounding_box();
327 if (overlap > 0 && overlap_grid !=
nullptr) {
328 if (*overlap_grid ==
nullptr) {
331 (*overlap_grid)->InsertBBox(
true,
true, n_it.data()->ShallowCopy());
332 if (!any_part_overlap) {
333 (*overlap_grid)->InsertBBox(
true,
true, part->ShallowCopy());
336 any_part_overlap =
true;
337 total_overlap += overlap;
340 return total_overlap;
◆ DeleteNonLeaderParts()
void tesseract::ColPartitionGrid::DeleteNonLeaderParts |
( |
| ) |
|
Definition at line 1036 of file colpartitiongrid.cpp.
1038 gsearch.StartFullSearch();
1040 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1042 gsearch.RemoveBBox();
1043 if (part->ReleaseNonLeaderBoxes()) {
1045 gsearch.RepositionIterator();
◆ DeleteParts()
void tesseract::ColPartitionGrid::DeleteParts |
( |
| ) |
|
Definition at line 1002 of file colpartitiongrid.cpp.
1003 ColPartition_LIST dead_parts;
1004 ColPartition_IT dead_it(&dead_parts);
1006 gsearch.StartFullSearch();
1008 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1009 part->DisownBoxes();
1010 dead_it.add_to_end(part);
◆ DeleteUnknownParts()
void tesseract::ColPartitionGrid::DeleteUnknownParts |
( |
TO_BLOCK * |
block | ) |
|
Definition at line 1017 of file colpartitiongrid.cpp.
1019 gsearch.StartFullSearch();
1021 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1023 gsearch.RemoveBBox();
1027 part->SetBlobTypes();
1028 part->DisownBoxes();
◆ Deskew()
void tesseract::ColPartitionGrid::Deskew |
( |
const FCOORD & |
deskew | ) |
|
Definition at line 729 of file colpartitiongrid.cpp.
730 ColPartition_LIST parts;
731 ColPartition_IT part_it(&parts);
734 gsearch.StartFullSearch();
736 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
737 part_it.add_after_then_move(part);
741 grid_box.rotate_large(deskew);
742 Init(
gridsize(), grid_box.botleft(), grid_box.topright());
745 for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
746 part = part_it.extract();
747 part->ComputeLimits();
◆ ExtractPartitionsAsBlocks()
void tesseract::ColPartitionGrid::ExtractPartitionsAsBlocks |
( |
BLOCK_LIST * |
blocks, |
|
|
TO_BLOCK_LIST * |
to_blocks |
|
) |
| |
Definition at line 668 of file colpartitiongrid.cpp.
670 TO_BLOCK_IT to_block_it(to_blocks);
671 BLOCK_IT block_it(blocks);
673 ColPartition_LIST parts;
674 ColPartition_IT part_it(&parts);
677 gsearch.StartFullSearch();
679 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
680 part_it.add_after_then_move(part);
684 (blob_type ==
BRT_UNKNOWN && part->boxes_count() > 1)) {
688 TBOX box = part->bounding_box();
689 int median_width = part->median_width();
690 int median_height = part->median_height();
692 TO_ROW* row = part->MakeToRow();
693 if (row ==
nullptr) {
701 auto* to_block =
new TO_BLOCK(block);
702 TO_ROW_IT row_it(to_block->get_rows());
703 row_it.add_after_then_move(row);
707 to_block->line_size = static_cast<float>(median_width);
708 to_block->line_spacing = static_cast<float>(box.
width());
709 to_block->max_blob_size = static_cast<float>(box.
width() + 1);
711 to_block->line_size = static_cast<float>(median_height);
712 to_block->line_spacing = static_cast<float>(box.
height());
713 to_block->max_blob_size = static_cast<float>(box.
height() + 1);
715 if (to_block->line_size == 0) to_block->line_size = 1;
716 block_it.add_to_end(block);
717 to_block_it.add_to_end(to_block);
◆ FindFigureCaptions()
void tesseract::ColPartitionGrid::FindFigureCaptions |
( |
| ) |
|
Definition at line 1054 of file colpartitiongrid.cpp.
1058 gsearch.StartFullSearch();
1060 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1061 if (part->IsImageType()) {
1062 const TBOX& part_box = part->bounding_box();
1065 ColPartition* best_caption =
nullptr;
1069 for (
int upper = 0; upper < 2; ++upper) {
1070 ColPartition_C_IT partner_it(upper ? part->upper_partners()
1071 : part->lower_partners());
1073 for (partner_it.mark_cycle_pt(); !partner_it.cycled_list();
1074 partner_it.forward()) {
1075 ColPartition* partner = partner_it.data();
1076 if (partner->IsImageType()) {
1080 if (!partner_it.cycled_list())
continue;
1082 for (partner_it.mark_cycle_pt(); !partner_it.cycled_list();
1083 partner_it.forward()) {
1084 ColPartition* partner = partner_it.data();
1085 if (!partner->IsTextType() || partner->type() ==
PT_TABLE)
continue;
1086 const TBOX& partner_box = partner->bounding_box();
1088 tprintf(
"Finding figure captions for image part:");
1090 tprintf(
"Considering partner:");
1091 partner_box.
print();
1093 if (partner_box.
left() >= part_box.
left() &&
1095 int dist = partner_box.
y_gap(part_box);
1096 if (best_caption ==
nullptr || dist < best_dist) {
1098 best_caption = partner;
1104 if (best_caption !=
nullptr) {
1106 tprintf(
"Best caption candidate:");
1107 best_caption->bounding_box().print();
1113 int biggest_gap = 0;
1114 int smallest_gap = INT16_MAX;
1115 int total_height = 0;
1116 int mean_height = 0;
1117 ColPartition* end_partner =
nullptr;
1118 ColPartition* next_partner =
nullptr;
1119 for (ColPartition* partner = best_caption; partner !=
nullptr &&
1121 partner = next_partner) {
1122 if (!partner->IsTextType()) {
1123 end_partner = partner;
1127 total_height += partner->bounding_box().height();
1128 next_partner = partner->SingletonPartner(best_upper);
1129 if (next_partner !=
nullptr) {
1130 int gap = partner->bounding_box().y_gap(
1131 next_partner->bounding_box());
1132 if (gap > biggest_gap) {
1134 end_partner = next_partner;
1135 mean_height = total_height / line_count;
1136 }
else if (gap < smallest_gap) {
1147 tprintf(
"Line count=%d, biggest gap %d, smallest%d, mean height %d\n",
1148 line_count, biggest_gap, smallest_gap, mean_height);
1149 if (end_partner !=
nullptr) {
1151 end_partner->bounding_box().print();
1155 end_partner =
nullptr;
1158 for (ColPartition* partner = best_caption; partner !=
nullptr &&
1159 partner != end_partner;
1160 partner = next_partner) {
1162 partner->SetBlobTypes();
1164 tprintf(
"Set caption type for partition:");
1165 partner->bounding_box().print();
1167 next_partner = partner->SingletonPartner(best_upper);
◆ FindOverlappingPartitions()
void tesseract::ColPartitionGrid::FindOverlappingPartitions |
( |
const TBOX & |
box, |
|
|
const ColPartition * |
not_this, |
|
|
ColPartition_CLIST * |
parts |
|
) |
| |
Definition at line 346 of file colpartitiongrid.cpp.
350 rsearch.StartRectSearch(box);
352 while ((part = rsearch.NextRectSearch()) !=
nullptr) {
353 if (part != not_this)
354 parts->add_sorted(SortByBoxLeft<ColPartition>,
true, part);
◆ FindPartitionPartners() [1/2]
void tesseract::ColPartitionGrid::FindPartitionPartners |
( |
| ) |
|
Definition at line 1179 of file colpartitiongrid.cpp.
1181 gsearch.StartFullSearch();
1183 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1184 if (part->IsVerticalType()) {
◆ FindPartitionPartners() [2/2]
void tesseract::ColPartitionGrid::FindPartitionPartners |
( |
bool |
upper, |
|
|
ColPartition * |
part |
|
) |
| |
Definition at line 1196 of file colpartitiongrid.cpp.
1199 const TBOX& box = part->bounding_box();
1200 int top = part->median_top();
1201 int bottom = part->median_bottom();
1202 int height = top - bottom;
1203 int mid_y = (bottom + top) / 2;
1206 vsearch.StartVerticalSearch(box.
left(), box.
right(), part->MidY());
1207 ColPartition* neighbour;
1208 ColPartition* best_neighbour =
nullptr;
1209 int best_dist = INT32_MAX;
1210 while ((neighbour = vsearch.NextVerticalSearch(!upper)) !=
nullptr) {
1211 if (neighbour == part || neighbour->type() ==
PT_NOISE)
1213 int neighbour_bottom = neighbour->median_bottom();
1214 int neighbour_top = neighbour->median_top();
1215 int neighbour_y = (neighbour_bottom + neighbour_top) / 2;
1216 if (upper != (neighbour_y > mid_y))
1218 if (!part->HOverlaps(*neighbour) && !part->WithinSameMargins(*neighbour))
1220 if (!part->TypesMatch(*neighbour)) {
1221 if (best_neighbour ==
nullptr)
1222 best_neighbour = neighbour;
1225 int dist = upper ? neighbour_bottom - top : bottom - neighbour_top;
1227 if (dist < best_dist) {
1229 best_neighbour = neighbour;
1235 if (best_neighbour !=
nullptr)
1236 part->AddPartner(upper, best_neighbour);
◆ FindVPartitionPartners()
void tesseract::ColPartitionGrid::FindVPartitionPartners |
( |
bool |
to_the_left, |
|
|
ColPartition * |
part |
|
) |
| |
Definition at line 1241 of file colpartitiongrid.cpp.
1245 const TBOX& box = part->bounding_box();
1246 int left = part->median_left();
1247 int right = part->median_right();
1248 int width = right >= left ? right - left : -1;
1249 int mid_x = (left + right) / 2;
1252 hsearch.StartSideSearch(mid_x, box.
bottom(), box.
top());
1253 ColPartition* neighbour;
1254 ColPartition* best_neighbour =
nullptr;
1255 int best_dist = INT32_MAX;
1256 while ((neighbour = hsearch.NextSideSearch(to_the_left)) !=
nullptr) {
1257 if (neighbour == part || neighbour->type() ==
PT_NOISE)
1259 int neighbour_left = neighbour->median_left();
1260 int neighbour_right = neighbour->median_right();
1261 int neighbour_x = (neighbour_left + neighbour_right) / 2;
1262 if (to_the_left != (neighbour_x < mid_x))
1264 if (!part->VOverlaps(*neighbour))
1266 if (!part->TypesMatch(*neighbour))
1268 int dist = to_the_left ? left - neighbour_right : neighbour_left - right;
1270 if (dist < best_dist || best_neighbour ==
nullptr) {
1272 best_neighbour = neighbour;
1280 if (best_neighbour !=
nullptr)
1281 part->AddPartner(to_the_left, best_neighbour);
◆ GridFindMargins()
void tesseract::ColPartitionGrid::GridFindMargins |
( |
ColPartitionSet ** |
best_columns | ) |
|
Definition at line 960 of file colpartitiongrid.cpp.
963 gsearch.StartFullSearch();
965 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
967 ColPartitionSet* columns = best_columns !=
nullptr
968 ? best_columns[gsearch.GridY()]
970 FindPartitionMargins(columns, part);
971 const TBOX& box = part->bounding_box();
973 tprintf(
"Computed margins for part:");
◆ GridSmoothNeighbours()
bool tesseract::ColPartitionGrid::GridSmoothNeighbours |
( |
BlobTextFlowType |
source_type, |
|
|
Pix * |
nontext_map, |
|
|
const TBOX & |
im_box, |
|
|
const FCOORD & |
rerotation |
|
) |
| |
Definition at line 618 of file colpartitiongrid.cpp.
624 gsearch.StartFullSearch();
626 bool any_changed =
false;
627 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
630 const TBOX& box = part->bounding_box();
632 if (SmoothRegionType(nontext_map, im_box, rotation, debug, part))
◆ HandleClick()
void tesseract::ColPartitionGrid::HandleClick |
( |
int |
x, |
|
|
int |
y |
|
) |
| |
|
overridevirtual |
◆ ListFindMargins()
void tesseract::ColPartitionGrid::ListFindMargins |
( |
ColPartitionSet ** |
best_columns, |
|
|
ColPartition_LIST * |
parts |
|
) |
| |
Definition at line 984 of file colpartitiongrid.cpp.
986 ColPartition_IT part_it(parts);
987 for (part_it.mark_cycle_pt(); !part_it.cycled_list(); part_it.forward()) {
988 ColPartition* part = part_it.data();
989 ColPartitionSet* columns =
nullptr;
990 if (best_columns !=
nullptr) {
991 const TBOX& part_box = part->bounding_box();
995 columns = best_columns[grid_y];
997 FindPartitionMargins(columns, part);
◆ MakeColPartSets()
bool tesseract::ColPartitionGrid::MakeColPartSets |
( |
PartSetVector * |
part_sets | ) |
|
Definition at line 777 of file colpartitiongrid.cpp.
778 auto* part_lists =
new ColPartition_LIST[
gridheight()];
783 gsearch.StartFullSearch();
785 bool any_parts_found =
false;
786 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
789 (blob_type !=
BRT_UNKNOWN || !part->boxes()->singleton())) {
791 const TBOX& part_box = part->bounding_box();
793 ColPartition_IT part_it(&part_lists[grid_y]);
794 part_it.add_to_end(part);
795 any_parts_found =
true;
798 if (any_parts_found) {
799 for (
int grid_y = 0; grid_y <
gridheight(); ++grid_y) {
800 ColPartitionSet* line_set =
nullptr;
801 if (!part_lists[grid_y].empty()) {
802 line_set =
new ColPartitionSet(&part_lists[grid_y]);
804 part_sets->push_back(line_set);
807 delete [] part_lists;
808 return any_parts_found;
◆ MakeSingleColumnSet()
Definition at line 815 of file colpartitiongrid.cpp.
816 ColPartition* single_column_part =
nullptr;
820 gsearch.StartFullSearch();
822 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
825 (blob_type !=
BRT_UNKNOWN || !part->boxes()->singleton())) {
832 if (single_column_part ==
nullptr) {
833 single_column_part = part->ShallowCopy();
834 single_column_part->set_blob_type(
BRT_TEXT);
836 single_column_part->CopyLeftTab(*single_column_part,
false);
837 single_column_part->CopyRightTab(*single_column_part,
false);
839 if (part->left_key() < single_column_part->left_key())
840 single_column_part->CopyLeftTab(*part,
false);
841 if (part->right_key() > single_column_part->right_key())
842 single_column_part->CopyRightTab(*part,
false);
847 if (single_column_part !=
nullptr) {
850 single_column_part->SetColumnGoodness(cb);
851 return new ColPartitionSet(single_column_part);
◆ MergePart()
Definition at line 117 of file colpartitiongrid.cpp.
121 if (part->IsUnMergeableType())
123 bool any_done =
false;
125 bool merge_done =
false;
128 TBOX box = part->bounding_box();
135 if (!box_cb(part, &box))
138 ColPartition_CLIST merge_candidates;
139 FindMergeCandidates(part, box, debug, &merge_candidates);
141 int overlap_increase;
145 if (neighbour !=
nullptr && overlap_increase <= 0) {
147 tprintf(
"Merging:hoverlap=%d, voverlap=%d, OLI=%d\n",
148 part->HCoreOverlap(*neighbour), part->VCoreOverlap(*neighbour),
156 part->Absorb(neighbour,
nullptr);
160 }
else if (neighbour !=
nullptr) {
162 tprintf(
"Overlapped when merged with increase %d: ", overlap_increase);
163 neighbour->bounding_box().print();
166 tprintf(
"No candidate neighbour returned\n");
168 }
while (merge_done);
◆ Merges()
Definition at line 99 of file colpartitiongrid.cpp.
104 gsearch.StartFullSearch();
106 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
108 gsearch.RepositionIterator();
◆ RecomputeBounds()
void tesseract::ColPartitionGrid::RecomputeBounds |
( |
int |
gridsize, |
|
|
const ICOORD & |
bleft, |
|
|
const ICOORD & |
tright, |
|
|
const ICOORD & |
vertical |
|
) |
| |
Definition at line 931 of file colpartitiongrid.cpp.
935 ColPartition_LIST saved_parts;
936 ColPartition_IT part_it(&saved_parts);
939 gsearch.StartFullSearch();
941 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
942 part_it.add_to_end(part);
947 for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
948 part = part_it.extract();
949 part->set_vertical(vertical);
950 part->ComputeLimits();
◆ RefinePartitionPartners()
void tesseract::ColPartitionGrid::RefinePartitionPartners |
( |
bool |
get_desperate | ) |
|
Definition at line 1287 of file colpartitiongrid.cpp.
1293 gsearch.StartFullSearch();
1295 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1296 part->RefinePartners(static_cast<PolyBlockType>(
type),
1297 get_desperate,
this);
1299 gsearch.RepositionIterator();
◆ ReflectInYAxis()
void tesseract::ColPartitionGrid::ReflectInYAxis |
( |
| ) |
|
Definition at line 640 of file colpartitiongrid.cpp.
641 ColPartition_LIST parts;
642 ColPartition_IT part_it(&parts);
645 gsearch.StartFullSearch();
647 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
648 part_it.add_after_then_move(part);
655 for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
656 part = part_it.extract();
657 part->ReflectInYAxis();
◆ ReTypeBlobs()
void tesseract::ColPartitionGrid::ReTypeBlobs |
( |
BLOBNBOX_LIST * |
im_blobs | ) |
|
Definition at line 870 of file colpartitiongrid.cpp.
871 BLOBNBOX_IT im_blob_it(im_blobs);
872 ColPartition_LIST dead_parts;
873 ColPartition_IT dead_part_it(&dead_parts);
876 gsearch.StartFullSearch();
878 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
881 bool any_blobs_moved =
false;
883 BLOBNBOX_C_IT blob_it(part->boxes());
884 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
886 im_blob_it.add_after_then_move(blob);
890 BLOBNBOX_C_IT blob_it(part->boxes());
891 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
899 any_blobs_moved =
true;
907 if (blob_type ==
BRT_NOISE || part->boxes()->empty()) {
908 BLOBNBOX_C_IT blob_it(part->boxes());
910 dead_part_it.add_to_end(part);
911 gsearch.RemoveBBox();
912 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
916 delete blob->
cblob();
920 }
else if (any_blobs_moved) {
921 gsearch.RemoveBBox();
922 part->ComputeLimits();
924 gsearch.RepositionIterator();
◆ SetTabStops()
void tesseract::ColPartitionGrid::SetTabStops |
( |
TabFind * |
tabgrid | ) |
|
Definition at line 753 of file colpartitiongrid.cpp.
756 gsearch.StartFullSearch();
758 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
759 const TBOX& part_box = part->bounding_box();
760 TabVector* left_line = tabgrid->LeftTabForBox(part_box,
true,
false);
762 if (left_line !=
nullptr && !left_line->IsLeftTab())
763 left_line = tabgrid->LeftTabForBox(part_box,
false,
false);
764 if (left_line !=
nullptr && left_line->IsLeftTab())
765 part->SetLeftTab(left_line);
766 TabVector* right_line = tabgrid->RightTabForBox(part_box,
true,
false);
767 if (right_line !=
nullptr && !right_line->IsRightTab())
768 right_line = tabgrid->RightTabForBox(part_box,
false,
false);
769 if (right_line !=
nullptr && right_line->IsRightTab())
770 part->SetRightTab(right_line);
771 part->SetColumnGoodness(tabgrid->WidthCB());
◆ SplitOverlappingPartitions()
void tesseract::ColPartitionGrid::SplitOverlappingPartitions |
( |
ColPartition_LIST * |
big_parts | ) |
|
Definition at line 508 of file colpartitiongrid.cpp.
514 gsearch.StartFullSearch();
516 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
518 const TBOX& box = part->bounding_box();
520 rsearch.SetUniqueMode(
true);
521 rsearch.StartRectSearch(box);
522 int unresolved_overlaps = 0;
524 ColPartition* neighbour;
525 while ((neighbour = rsearch.NextRectSearch()) !=
nullptr) {
526 if (neighbour == part)
528 const TBOX& neighbour_box = neighbour->bounding_box();
529 if (neighbour->OKMergeOverlap(*part, *part, ok_overlap,
false) &&
530 part->OKMergeOverlap(*neighbour, *neighbour, ok_overlap,
false))
537 if (!part->IsSingleton()) {
538 BLOBNBOX* excluded = part->BiggestBox();
539 TBOX shrunken = part->BoundsWithoutBox(excluded);
540 if (!shrunken.
overlap(neighbour_box) &&
544 gsearch.RemoveBBox();
545 RemoveBadBox(excluded, part, big_parts);
547 gsearch.RepositionIterator();
550 }
else if (box.
contains(neighbour_box)) {
551 ++unresolved_overlaps;
554 if (!neighbour->IsSingleton()) {
555 BLOBNBOX* excluded = neighbour->BiggestBox();
556 TBOX shrunken = neighbour->BoundsWithoutBox(excluded);
561 rsearch.RemoveBBox();
562 RemoveBadBox(excluded, neighbour, big_parts);
564 gsearch.RepositionIterator();
568 int part_overlap_count = part->CountOverlappingBoxes(neighbour_box);
569 int neighbour_overlap_count = neighbour->CountOverlappingBoxes(box);
570 ColPartition* right_part =
nullptr;
571 if (neighbour_overlap_count <= part_overlap_count ||
572 part->IsSingleton()) {
574 BLOBNBOX* split_blob = neighbour->OverlapSplitBlob(box);
575 if (split_blob !=
nullptr) {
576 rsearch.RemoveBBox();
577 right_part = neighbour->SplitAtBlob(split_blob);
583 BLOBNBOX* split_blob = part->OverlapSplitBlob(neighbour_box);
584 if (split_blob !=
nullptr) {
585 gsearch.RemoveBBox();
586 right_part = part->SplitAtBlob(split_blob);
591 if (right_part !=
nullptr) {
593 gsearch.RepositionIterator();
594 rsearch.RepositionIterator();
598 if (unresolved_overlaps > 2 && part->IsSingleton()) {
601 ColPartition_IT big_it(big_parts);
602 part->set_block_owned(
true);
603 big_it.add_to_end(part);
604 gsearch.RepositionIterator();
The documentation for this class was generated from the following files:
TBOX intersection(const TBOX &box) const
void InsertBBox(bool h_spread, bool v_spread, ColPartition *bbox)
ColPartition * BestMergeCandidate(const ColPartition *part, ColPartition_CLIST *candidates, bool debug, std::function< bool(const ColPartition *, const ColPartition *)> confirm_cb, int *overlap_increase)
bool overlap(const TBOX &box) const
void set_flow(BlobTextFlowType value)
void RemoveBBox(ColPartition *bbox)
void DeleteUnownedNoise()
bool contains(const FCOORD pt) const
TBOX bounding_union(const TBOX &box) const
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
const double kMaxPartitionSpacing
const double kTinyEnoughTextlineOverlapFraction
void HandleClick(int x, int y) override
const ICOORD & tright() const
int y_gap(const TBOX &box) const
const double kBigPartSizeRatio
static bool IsLineType(BlobRegionType type)
const int kMaxCaptionLines
PDBLK pdblk
Page Description Block.
void FindOverlappingPartitions(const TBOX &box, const ColPartition *not_this, ColPartition_CLIST *parts)
void set_poly_block(POLY_BLOCK *blk)
set the poly block
static bool WithinTestRegion(int detail_level, int x, int y)
void FindVPartitionPartners(bool to_the_left, ColPartition *part)
void set_owner(tesseract::ColPartition *new_owner)
bool MergePart(std::function< bool(ColPartition *, TBOX *)> box_cb, std::function< bool(const ColPartition *, const ColPartition *)> confirm_cb, ColPartition *part)
void set_region_type(BlobRegionType new_type)
const TBOX & bounding_box() const
const double kMinCaptionGapHeightRatio
void FindPartitionPartners()
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
BlobTextFlowType flow() const
BlobRegionType region_type() const
DLLSYM void tprintf(const char *format,...)
const double kMinCaptionGapRatio
ColPartitionGrid()=default
static bool IsTextType(BlobRegionType type)
const ICOORD & bleft() const
void GridCoords(int x, int y, int *grid_x, int *grid_y) const