#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 (TessResultCallback2< bool, ColPartition *, TBOX * > *box_cb, TessResultCallback2< bool, const ColPartition *, const ColPartition * > *confirm_cb) |
|
bool | MergePart (TessResultCallback2< bool, ColPartition *, TBOX * > *box_cb, TessResultCallback2< 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, TessResultCallback2< 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 33 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 403 of file colpartitiongrid.cpp.
407 if (overlap_increase !=
nullptr)
408 *overlap_increase = 0;
409 if (candidates->empty())
417 const TBOX& part_box = part->bounding_box();
418 ColPartition_C_IT it(candidates);
419 ColPartition* best_candidate =
nullptr;
421 TBOX full_box(part_box);
422 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
423 ColPartition* candidate = it.data();
424 full_box += candidate->bounding_box();
427 ColPartition_CLIST neighbours;
432 tprintf(
"Finding best merge candidate from %d, %d neighbours for box:",
433 candidates->length(), neighbours.length());
441 ColPartition_CLIST non_candidate_neighbours;
442 non_candidate_neighbours.set_subtract(SortByBoxLeft<ColPartition>,
true,
443 &neighbours, candidates);
444 int worst_nc_increase = 0;
445 int best_increase = INT32_MAX;
447 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
448 ColPartition* candidate = it.data();
449 if (confirm_cb !=
nullptr && !confirm_cb->
Run(part, candidate)) {
451 tprintf(
"Candidate not confirmed:");
452 candidate->bounding_box().print();
456 int increase = IncreaseInOverlap(part, candidate, ok_overlap, &neighbours);
457 const TBOX& cand_box = candidate->bounding_box();
458 if (best_candidate ==
nullptr || increase < best_increase) {
459 best_candidate = candidate;
460 best_increase = increase;
463 tprintf(
"New best merge candidate has increase %d, area %d, over box:",
464 increase, best_area);
468 }
else if (increase == best_increase) {
470 if (area < best_area) {
472 best_candidate = candidate;
475 increase = IncreaseInOverlap(part, candidate, ok_overlap,
476 &non_candidate_neighbours);
477 if (increase > worst_nc_increase)
478 worst_nc_increase = increase;
480 if (best_increase > 0) {
487 if (worst_nc_increase < best_increase &&
488 TestCompatibleCandidates(*part, debug, candidates)) {
489 best_increase = worst_nc_increase;
492 if (overlap_increase !=
nullptr)
493 *overlap_increase = best_increase;
494 return best_candidate;
◆ ClaimBoxes()
void tesseract::ColPartitionGrid::ClaimBoxes |
( |
| ) |
|
Definition at line 861 of file colpartitiongrid.cpp.
864 gsearch.StartFullSearch();
866 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
◆ ComputeTotalOverlap()
int tesseract::ColPartitionGrid::ComputeTotalOverlap |
( |
ColPartitionGrid ** |
overlap_grid | ) |
|
Definition at line 316 of file colpartitiongrid.cpp.
317 int total_overlap = 0;
320 gsearch.StartFullSearch();
322 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
323 ColPartition_CLIST neighbors;
324 const TBOX& part_box = part->bounding_box();
326 ColPartition_C_IT n_it(&neighbors);
327 bool any_part_overlap =
false;
328 for (n_it.mark_cycle_pt(); !n_it.cycled_list(); n_it.forward()) {
329 const TBOX& n_box = n_it.data()->bounding_box();
331 if (overlap > 0 && overlap_grid !=
nullptr) {
332 if (*overlap_grid ==
nullptr) {
335 (*overlap_grid)->InsertBBox(
true,
true, n_it.data()->ShallowCopy());
336 if (!any_part_overlap) {
337 (*overlap_grid)->InsertBBox(
true,
true, part->ShallowCopy());
340 any_part_overlap =
true;
341 total_overlap += overlap;
344 return total_overlap;
◆ DeleteNonLeaderParts()
void tesseract::ColPartitionGrid::DeleteNonLeaderParts |
( |
| ) |
|
Definition at line 1040 of file colpartitiongrid.cpp.
1042 gsearch.StartFullSearch();
1044 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1046 gsearch.RemoveBBox();
1047 if (part->ReleaseNonLeaderBoxes()) {
1049 gsearch.RepositionIterator();
◆ DeleteParts()
void tesseract::ColPartitionGrid::DeleteParts |
( |
| ) |
|
Definition at line 1006 of file colpartitiongrid.cpp.
1007 ColPartition_LIST dead_parts;
1008 ColPartition_IT dead_it(&dead_parts);
1010 gsearch.StartFullSearch();
1012 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1013 part->DisownBoxes();
1014 dead_it.add_to_end(part);
◆ DeleteUnknownParts()
void tesseract::ColPartitionGrid::DeleteUnknownParts |
( |
TO_BLOCK * |
block | ) |
|
Definition at line 1021 of file colpartitiongrid.cpp.
1023 gsearch.StartFullSearch();
1025 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1027 gsearch.RemoveBBox();
1031 part->SetBlobTypes();
1032 part->DisownBoxes();
◆ Deskew()
void tesseract::ColPartitionGrid::Deskew |
( |
const FCOORD & |
deskew | ) |
|
Definition at line 733 of file colpartitiongrid.cpp.
734 ColPartition_LIST parts;
735 ColPartition_IT part_it(&parts);
738 gsearch.StartFullSearch();
740 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
741 part_it.add_after_then_move(part);
745 grid_box.rotate_large(deskew);
746 Init(
gridsize(), grid_box.botleft(), grid_box.topright());
749 for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
750 part = part_it.extract();
751 part->ComputeLimits();
◆ ExtractPartitionsAsBlocks()
void tesseract::ColPartitionGrid::ExtractPartitionsAsBlocks |
( |
BLOCK_LIST * |
blocks, |
|
|
TO_BLOCK_LIST * |
to_blocks |
|
) |
| |
Definition at line 672 of file colpartitiongrid.cpp.
674 TO_BLOCK_IT to_block_it(to_blocks);
675 BLOCK_IT block_it(blocks);
677 ColPartition_LIST parts;
678 ColPartition_IT part_it(&parts);
681 gsearch.StartFullSearch();
683 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
684 part_it.add_after_then_move(part);
688 (blob_type ==
BRT_UNKNOWN && part->boxes_count() > 1)) {
692 TBOX box = part->bounding_box();
693 int median_width = part->median_width();
694 int median_height = part->median_height();
696 TO_ROW* row = part->MakeToRow();
697 if (row ==
nullptr) {
705 auto* to_block =
new TO_BLOCK(block);
706 TO_ROW_IT row_it(to_block->get_rows());
707 row_it.add_after_then_move(row);
711 to_block->line_size =
static_cast<float>(median_width);
712 to_block->line_spacing =
static_cast<float>(box.
width());
713 to_block->max_blob_size =
static_cast<float>(box.
width() + 1);
715 to_block->line_size =
static_cast<float>(median_height);
716 to_block->line_spacing =
static_cast<float>(box.
height());
717 to_block->max_blob_size =
static_cast<float>(box.
height() + 1);
719 if (to_block->line_size == 0) to_block->line_size = 1;
720 block_it.add_to_end(block);
721 to_block_it.add_to_end(to_block);
◆ FindFigureCaptions()
void tesseract::ColPartitionGrid::FindFigureCaptions |
( |
| ) |
|
Definition at line 1058 of file colpartitiongrid.cpp.
1062 gsearch.StartFullSearch();
1064 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1065 if (part->IsImageType()) {
1066 const TBOX& part_box = part->bounding_box();
1069 ColPartition* best_caption =
nullptr;
1073 for (
int upper = 0; upper < 2; ++upper) {
1074 ColPartition_C_IT partner_it(upper ? part->upper_partners()
1075 : part->lower_partners());
1077 for (partner_it.mark_cycle_pt(); !partner_it.cycled_list();
1078 partner_it.forward()) {
1079 ColPartition* partner = partner_it.data();
1080 if (partner->IsImageType()) {
1084 if (!partner_it.cycled_list())
continue;
1086 for (partner_it.mark_cycle_pt(); !partner_it.cycled_list();
1087 partner_it.forward()) {
1088 ColPartition* partner = partner_it.data();
1089 if (!partner->IsTextType() || partner->type() ==
PT_TABLE)
continue;
1090 const TBOX& partner_box = partner->bounding_box();
1092 tprintf(
"Finding figure captions for image part:");
1094 tprintf(
"Considering partner:");
1095 partner_box.
print();
1097 if (partner_box.
left() >= part_box.
left() &&
1099 int dist = partner_box.
y_gap(part_box);
1100 if (best_caption ==
nullptr || dist < best_dist) {
1102 best_caption = partner;
1108 if (best_caption !=
nullptr) {
1110 tprintf(
"Best caption candidate:");
1111 best_caption->bounding_box().print();
1117 int biggest_gap = 0;
1118 int smallest_gap = INT16_MAX;
1119 int total_height = 0;
1120 int mean_height = 0;
1121 ColPartition* end_partner =
nullptr;
1122 ColPartition* next_partner =
nullptr;
1123 for (ColPartition* partner = best_caption; partner !=
nullptr &&
1125 partner = next_partner) {
1126 if (!partner->IsTextType()) {
1127 end_partner = partner;
1131 total_height += partner->bounding_box().height();
1132 next_partner = partner->SingletonPartner(best_upper);
1133 if (next_partner !=
nullptr) {
1134 int gap = partner->bounding_box().y_gap(
1135 next_partner->bounding_box());
1136 if (gap > biggest_gap) {
1138 end_partner = next_partner;
1139 mean_height = total_height / line_count;
1140 }
else if (gap < smallest_gap) {
1151 tprintf(
"Line count=%d, biggest gap %d, smallest%d, mean height %d\n",
1152 line_count, biggest_gap, smallest_gap, mean_height);
1153 if (end_partner !=
nullptr) {
1155 end_partner->bounding_box().print();
1159 end_partner =
nullptr;
1162 for (ColPartition* partner = best_caption; partner !=
nullptr &&
1163 partner != end_partner;
1164 partner = next_partner) {
1166 partner->SetBlobTypes();
1168 tprintf(
"Set caption type for partition:");
1169 partner->bounding_box().print();
1171 next_partner = partner->SingletonPartner(best_upper);
◆ FindOverlappingPartitions()
void tesseract::ColPartitionGrid::FindOverlappingPartitions |
( |
const TBOX & |
box, |
|
|
const ColPartition * |
not_this, |
|
|
ColPartition_CLIST * |
parts |
|
) |
| |
Definition at line 350 of file colpartitiongrid.cpp.
354 rsearch.StartRectSearch(box);
356 while ((part = rsearch.NextRectSearch()) !=
nullptr) {
357 if (part != not_this)
358 parts->add_sorted(SortByBoxLeft<ColPartition>,
true, part);
◆ FindPartitionPartners() [1/2]
void tesseract::ColPartitionGrid::FindPartitionPartners |
( |
| ) |
|
Definition at line 1183 of file colpartitiongrid.cpp.
1185 gsearch.StartFullSearch();
1187 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1188 if (part->IsVerticalType()) {
◆ FindPartitionPartners() [2/2]
void tesseract::ColPartitionGrid::FindPartitionPartners |
( |
bool |
upper, |
|
|
ColPartition * |
part |
|
) |
| |
Definition at line 1200 of file colpartitiongrid.cpp.
1203 const TBOX& box = part->bounding_box();
1204 int top = part->median_top();
1205 int bottom = part->median_bottom();
1206 int height = top - bottom;
1207 int mid_y = (bottom + top) / 2;
1210 vsearch.StartVerticalSearch(box.
left(), box.
right(), part->MidY());
1211 ColPartition* neighbour;
1212 ColPartition* best_neighbour =
nullptr;
1213 int best_dist = INT32_MAX;
1214 while ((neighbour = vsearch.NextVerticalSearch(!upper)) !=
nullptr) {
1215 if (neighbour == part || neighbour->type() ==
PT_NOISE)
1217 int neighbour_bottom = neighbour->median_bottom();
1218 int neighbour_top = neighbour->median_top();
1219 int neighbour_y = (neighbour_bottom + neighbour_top) / 2;
1220 if (upper != (neighbour_y > mid_y))
1222 if (!part->HOverlaps(*neighbour) && !part->WithinSameMargins(*neighbour))
1224 if (!part->TypesMatch(*neighbour)) {
1225 if (best_neighbour ==
nullptr)
1226 best_neighbour = neighbour;
1229 int dist = upper ? neighbour_bottom - top : bottom - neighbour_top;
1231 if (dist < best_dist) {
1233 best_neighbour = neighbour;
1239 if (best_neighbour !=
nullptr)
1240 part->AddPartner(upper, best_neighbour);
◆ FindVPartitionPartners()
void tesseract::ColPartitionGrid::FindVPartitionPartners |
( |
bool |
to_the_left, |
|
|
ColPartition * |
part |
|
) |
| |
Definition at line 1245 of file colpartitiongrid.cpp.
1249 const TBOX& box = part->bounding_box();
1250 int left = part->median_left();
1251 int right = part->median_right();
1252 int width = right >= left ? right - left : -1;
1253 int mid_x = (left + right) / 2;
1256 hsearch.StartSideSearch(mid_x, box.
bottom(), box.
top());
1257 ColPartition* neighbour;
1258 ColPartition* best_neighbour =
nullptr;
1259 int best_dist = INT32_MAX;
1260 while ((neighbour = hsearch.NextSideSearch(to_the_left)) !=
nullptr) {
1261 if (neighbour == part || neighbour->type() ==
PT_NOISE)
1263 int neighbour_left = neighbour->median_left();
1264 int neighbour_right = neighbour->median_right();
1265 int neighbour_x = (neighbour_left + neighbour_right) / 2;
1266 if (to_the_left != (neighbour_x < mid_x))
1268 if (!part->VOverlaps(*neighbour))
1270 if (!part->TypesMatch(*neighbour))
1272 int dist = to_the_left ? left - neighbour_right : neighbour_left - right;
1274 if (dist < best_dist || best_neighbour ==
nullptr) {
1276 best_neighbour = neighbour;
1284 if (best_neighbour !=
nullptr)
1285 part->AddPartner(to_the_left, best_neighbour);
◆ GridFindMargins()
void tesseract::ColPartitionGrid::GridFindMargins |
( |
ColPartitionSet ** |
best_columns | ) |
|
Definition at line 964 of file colpartitiongrid.cpp.
967 gsearch.StartFullSearch();
969 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
971 ColPartitionSet* columns = best_columns !=
nullptr
972 ? best_columns[gsearch.GridY()]
974 FindPartitionMargins(columns, part);
975 const TBOX& box = part->bounding_box();
977 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 622 of file colpartitiongrid.cpp.
628 gsearch.StartFullSearch();
630 bool any_changed =
false;
631 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
634 const TBOX& box = part->bounding_box();
636 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 988 of file colpartitiongrid.cpp.
990 ColPartition_IT part_it(parts);
991 for (part_it.mark_cycle_pt(); !part_it.cycled_list(); part_it.forward()) {
992 ColPartition* part = part_it.data();
993 ColPartitionSet* columns =
nullptr;
994 if (best_columns !=
nullptr) {
995 const TBOX& part_box = part->bounding_box();
999 columns = best_columns[grid_y];
1001 FindPartitionMargins(columns, part);
◆ MakeColPartSets()
bool tesseract::ColPartitionGrid::MakeColPartSets |
( |
PartSetVector * |
part_sets | ) |
|
Definition at line 781 of file colpartitiongrid.cpp.
782 auto* part_lists =
new ColPartition_LIST[
gridheight()];
787 gsearch.StartFullSearch();
789 bool any_parts_found =
false;
790 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
793 (blob_type !=
BRT_UNKNOWN || !part->boxes()->singleton())) {
795 const TBOX& part_box = part->bounding_box();
797 ColPartition_IT part_it(&part_lists[grid_y]);
798 part_it.add_to_end(part);
799 any_parts_found =
true;
802 if (any_parts_found) {
803 for (
int grid_y = 0; grid_y <
gridheight(); ++grid_y) {
804 ColPartitionSet* line_set =
nullptr;
805 if (!part_lists[grid_y].empty()) {
806 line_set =
new ColPartitionSet(&part_lists[grid_y]);
808 part_sets->push_back(line_set);
811 delete [] part_lists;
812 return any_parts_found;
◆ MakeSingleColumnSet()
Definition at line 819 of file colpartitiongrid.cpp.
820 ColPartition* single_column_part =
nullptr;
824 gsearch.StartFullSearch();
826 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
829 (blob_type !=
BRT_UNKNOWN || !part->boxes()->singleton())) {
836 if (single_column_part ==
nullptr) {
837 single_column_part = part->ShallowCopy();
838 single_column_part->set_blob_type(
BRT_TEXT);
840 single_column_part->CopyLeftTab(*single_column_part,
false);
841 single_column_part->CopyRightTab(*single_column_part,
false);
843 if (part->left_key() < single_column_part->left_key())
844 single_column_part->CopyLeftTab(*part,
false);
845 if (part->right_key() > single_column_part->right_key())
846 single_column_part->CopyRightTab(*part,
false);
851 if (single_column_part !=
nullptr) {
854 single_column_part->SetColumnGoodness(cb);
855 return new ColPartitionSet(single_column_part);
◆ MergePart()
Definition at line 120 of file colpartitiongrid.cpp.
125 if (part->IsUnMergeableType())
127 bool any_done =
false;
129 bool merge_done =
false;
132 TBOX box = part->bounding_box();
139 if (!box_cb->
Run(part, &box))
142 ColPartition_CLIST merge_candidates;
143 FindMergeCandidates(part, box, debug, &merge_candidates);
145 int overlap_increase;
149 if (neighbour !=
nullptr && overlap_increase <= 0) {
151 tprintf(
"Merging:hoverlap=%d, voverlap=%d, OLI=%d\n",
152 part->HCoreOverlap(*neighbour), part->VCoreOverlap(*neighbour),
160 part->Absorb(neighbour,
nullptr);
164 }
else if (neighbour !=
nullptr) {
166 tprintf(
"Overlapped when merged with increase %d: ", overlap_increase);
167 neighbour->bounding_box().print();
170 tprintf(
"No candidate neighbour returned\n");
172 }
while (merge_done);
◆ Merges()
Definition at line 99 of file colpartitiongrid.cpp.
105 gsearch.StartFullSearch();
107 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
109 gsearch.RepositionIterator();
◆ RecomputeBounds()
void tesseract::ColPartitionGrid::RecomputeBounds |
( |
int |
gridsize, |
|
|
const ICOORD & |
bleft, |
|
|
const ICOORD & |
tright, |
|
|
const ICOORD & |
vertical |
|
) |
| |
Definition at line 935 of file colpartitiongrid.cpp.
939 ColPartition_LIST saved_parts;
940 ColPartition_IT part_it(&saved_parts);
943 gsearch.StartFullSearch();
945 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
946 part_it.add_to_end(part);
951 for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
952 part = part_it.extract();
953 part->set_vertical(vertical);
954 part->ComputeLimits();
◆ RefinePartitionPartners()
void tesseract::ColPartitionGrid::RefinePartitionPartners |
( |
bool |
get_desperate | ) |
|
Definition at line 1291 of file colpartitiongrid.cpp.
1297 gsearch.StartFullSearch();
1299 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
1301 get_desperate,
this);
1303 gsearch.RepositionIterator();
◆ ReflectInYAxis()
void tesseract::ColPartitionGrid::ReflectInYAxis |
( |
| ) |
|
Definition at line 644 of file colpartitiongrid.cpp.
645 ColPartition_LIST parts;
646 ColPartition_IT part_it(&parts);
649 gsearch.StartFullSearch();
651 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
652 part_it.add_after_then_move(part);
659 for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
660 part = part_it.extract();
661 part->ReflectInYAxis();
◆ ReTypeBlobs()
void tesseract::ColPartitionGrid::ReTypeBlobs |
( |
BLOBNBOX_LIST * |
im_blobs | ) |
|
Definition at line 874 of file colpartitiongrid.cpp.
875 BLOBNBOX_IT im_blob_it(im_blobs);
876 ColPartition_LIST dead_parts;
877 ColPartition_IT dead_part_it(&dead_parts);
880 gsearch.StartFullSearch();
882 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
885 bool any_blobs_moved =
false;
887 BLOBNBOX_C_IT blob_it(part->boxes());
888 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
890 im_blob_it.add_after_then_move(blob);
894 BLOBNBOX_C_IT blob_it(part->boxes());
895 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
903 any_blobs_moved =
true;
911 if (blob_type ==
BRT_NOISE || part->boxes()->empty()) {
912 BLOBNBOX_C_IT blob_it(part->boxes());
914 dead_part_it.add_to_end(part);
915 gsearch.RemoveBBox();
916 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
920 delete blob->
cblob();
924 }
else if (any_blobs_moved) {
925 gsearch.RemoveBBox();
926 part->ComputeLimits();
928 gsearch.RepositionIterator();
◆ SetTabStops()
void tesseract::ColPartitionGrid::SetTabStops |
( |
TabFind * |
tabgrid | ) |
|
Definition at line 757 of file colpartitiongrid.cpp.
760 gsearch.StartFullSearch();
762 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
763 const TBOX& part_box = part->bounding_box();
764 TabVector* left_line = tabgrid->LeftTabForBox(part_box,
true,
false);
766 if (left_line !=
nullptr && !left_line->IsLeftTab())
767 left_line = tabgrid->LeftTabForBox(part_box,
false,
false);
768 if (left_line !=
nullptr && left_line->IsLeftTab())
769 part->SetLeftTab(left_line);
770 TabVector* right_line = tabgrid->RightTabForBox(part_box,
true,
false);
771 if (right_line !=
nullptr && !right_line->IsRightTab())
772 right_line = tabgrid->RightTabForBox(part_box,
false,
false);
773 if (right_line !=
nullptr && right_line->IsRightTab())
774 part->SetRightTab(right_line);
775 part->SetColumnGoodness(tabgrid->WidthCB());
◆ SplitOverlappingPartitions()
void tesseract::ColPartitionGrid::SplitOverlappingPartitions |
( |
ColPartition_LIST * |
big_parts | ) |
|
Definition at line 512 of file colpartitiongrid.cpp.
518 gsearch.StartFullSearch();
520 while ((part = gsearch.NextFullSearch()) !=
nullptr) {
522 const TBOX& box = part->bounding_box();
524 rsearch.SetUniqueMode(
true);
525 rsearch.StartRectSearch(box);
526 int unresolved_overlaps = 0;
528 ColPartition* neighbour;
529 while ((neighbour = rsearch.NextRectSearch()) !=
nullptr) {
530 if (neighbour == part)
532 const TBOX& neighbour_box = neighbour->bounding_box();
533 if (neighbour->OKMergeOverlap(*part, *part, ok_overlap,
false) &&
534 part->OKMergeOverlap(*neighbour, *neighbour, ok_overlap,
false))
541 if (!part->IsSingleton()) {
542 BLOBNBOX* excluded = part->BiggestBox();
543 TBOX shrunken = part->BoundsWithoutBox(excluded);
544 if (!shrunken.
overlap(neighbour_box) &&
548 gsearch.RemoveBBox();
549 RemoveBadBox(excluded, part, big_parts);
551 gsearch.RepositionIterator();
554 }
else if (box.
contains(neighbour_box)) {
555 ++unresolved_overlaps;
558 if (!neighbour->IsSingleton()) {
559 BLOBNBOX* excluded = neighbour->BiggestBox();
560 TBOX shrunken = neighbour->BoundsWithoutBox(excluded);
565 rsearch.RemoveBBox();
566 RemoveBadBox(excluded, neighbour, big_parts);
568 gsearch.RepositionIterator();
572 int part_overlap_count = part->CountOverlappingBoxes(neighbour_box);
573 int neighbour_overlap_count = neighbour->CountOverlappingBoxes(box);
574 ColPartition* right_part =
nullptr;
575 if (neighbour_overlap_count <= part_overlap_count ||
576 part->IsSingleton()) {
578 BLOBNBOX* split_blob = neighbour->OverlapSplitBlob(box);
579 if (split_blob !=
nullptr) {
580 rsearch.RemoveBBox();
581 right_part = neighbour->SplitAtBlob(split_blob);
587 BLOBNBOX* split_blob = part->OverlapSplitBlob(neighbour_box);
588 if (split_blob !=
nullptr) {
589 gsearch.RemoveBBox();
590 right_part = part->SplitAtBlob(split_blob);
595 if (right_part !=
nullptr) {
597 gsearch.RepositionIterator();
598 rsearch.RepositionIterator();
602 if (unresolved_overlaps > 2 && part->IsSingleton()) {
605 ColPartition_IT big_it(big_parts);
606 part->set_block_owned(
true);
607 big_it.add_to_end(part);
608 gsearch.RepositionIterator();
The documentation for this class was generated from the following files:
static bool WithinTestRegion(int detail_level, int x, int y)
void set_flow(BlobTextFlowType value)
BlobRegionType region_type() const
TBOX intersection(const TBOX &box) const
void set_region_type(BlobRegionType new_type)
void FindPartitionPartners()
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
const TBOX & bounding_box() const
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
BlobTextFlowType flow() const
int y_gap(const TBOX &box) const
const double kMaxPartitionSpacing
const double kTinyEnoughTextlineOverlapFraction
static bool IsLineType(BlobRegionType type)
const double kBigPartSizeRatio
DLLSYM void tprintf(const char *format,...)
const ICOORD & bleft() const
const int kMaxCaptionLines
void GridCoords(int x, int y, int *grid_x, int *grid_y) const
bool MergePart(TessResultCallback2< bool, ColPartition *, TBOX * > *box_cb, TessResultCallback2< bool, const ColPartition *, const ColPartition * > *confirm_cb, ColPartition *part)
ColPartitionGrid()=default
void FindOverlappingPartitions(const TBOX &box, const ColPartition *not_this, ColPartition_CLIST *parts)
void InsertBBox(bool h_spread, bool v_spread, ColPartition *bbox)
bool overlap(const TBOX &box) const
void RemoveBBox(ColPartition *bbox)
bool contains(const FCOORD pt) const
const double kMinCaptionGapHeightRatio
static bool IsTextType(BlobRegionType type)
TBOX bounding_union(const TBOX &box) const
ColPartition * BestMergeCandidate(const ColPartition *part, ColPartition_CLIST *candidates, bool debug, TessResultCallback2< bool, const ColPartition *, const ColPartition * > *confirm_cb, int *overlap_increase)
void FindVPartitionPartners(bool to_the_left, ColPartition *part)
void DeleteUnownedNoise()
const double kMinCaptionGapRatio
void set_owner(tesseract::ColPartition *new_owner)
void HandleClick(int x, int y) override
const ICOORD & tright() const