tesseract  5.0.0-alpha-619-ge9db
tesseract::ColPartitionGrid Class Reference

#include <colpartitiongrid.h>

Inheritance diagram for tesseract::ColPartitionGrid:
tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT > tesseract::GridBase

Public Member Functions

 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)
 
ColPartitionBestMergeCandidate (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)
 
ColPartitionSetMakeSingleColumnSet (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)
 
- Public Member Functions inherited from tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT >
 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)
 
IntGridCountCellElements ()
 
ScrollViewMakeWindow (int x, int y, const char *window_name)
 
void DisplayBoxes (ScrollView *window)
 
void AssertNoDuplicates ()
 
- Public Member Functions inherited from tesseract::GridBase
 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 ICOORDbleft () const
 
const ICOORDtright () const
 
void GridCoords (int x, int y, int *grid_x, int *grid_y) const
 
void ClipGridCoords (int *x, int *y) const
 

Additional Inherited Members

- Protected Attributes inherited from tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT >
ColPartition_CLIST * grid_
 
- Protected Attributes inherited from tesseract::GridBase
int gridsize_
 
int gridwidth_
 
int gridheight_
 
int gridbuckets_
 
ICOORD bleft_
 
ICOORD tright_
 

Detailed Description

Definition at line 32 of file colpartitiongrid.h.

Constructor & Destructor Documentation

◆ ColPartitionGrid() [1/2]

tesseract::ColPartitionGrid::ColPartitionGrid ( )
default

◆ ColPartitionGrid() [2/2]

tesseract::ColPartitionGrid::ColPartitionGrid ( int  gridsize,
const ICOORD bleft,
const ICOORD tright 
)

Definition at line 66 of file colpartitiongrid.cpp.

68  : BBGrid<ColPartition, ColPartition_CLIST, ColPartition_C_IT>(gridsize,
69  bleft, tright) {
70 }

◆ ~ColPartitionGrid()

tesseract::ColPartitionGrid::~ColPartitionGrid ( )
overridedefault

Member Function Documentation

◆ BestMergeCandidate()

ColPartition * tesseract::ColPartitionGrid::BestMergeCandidate ( const ColPartition part,
ColPartition_CLIST *  candidates,
bool  debug,
std::function< bool(const ColPartition *, const ColPartition *)>  confirm_cb,
int *  overlap_increase 
)

Definition at line 399 of file colpartitiongrid.cpp.

402  {
403  if (overlap_increase != nullptr)
404  *overlap_increase = 0;
405  if (candidates->empty())
406  return nullptr;
407  int ok_overlap =
408  static_cast<int>(kTinyEnoughTextlineOverlapFraction * gridsize() + 0.5);
409  // The best neighbour to merge with is the one that causes least
410  // total pairwise overlap among all the neighbours.
411  // If more than one offers the same total overlap, choose the one
412  // with the least total area.
413  const TBOX& part_box = part->bounding_box();
414  ColPartition_C_IT it(candidates);
415  ColPartition* best_candidate = nullptr;
416  // Find the total combined box of all candidates and the original.
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();
421  }
422  // Keep valid neighbours in a list.
423  ColPartition_CLIST neighbours;
424  // Now run a rect search of the merged box for overlapping neighbours, as
425  // we need anything that might be overlapped by the merged box.
426  FindOverlappingPartitions(full_box, part, &neighbours);
427  if (debug) {
428  tprintf("Finding best merge candidate from %d, %d neighbours for box:",
429  candidates->length(), neighbours.length());
430  part_box.print();
431  }
432  // If the best increase in overlap is positive, then we also check the
433  // worst non-candidate overlap. This catches the case of multiple good
434  // candidates that overlap each other when merged. If the worst
435  // non-candidate overlap is better than the best overlap, then return
436  // the worst non-candidate overlap instead.
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;
442  int best_area = 0;
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)) {
446  if (debug) {
447  tprintf("Candidate not confirmed:");
448  candidate->bounding_box().print();
449  }
450  continue;
451  }
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;
457  best_area = cand_box.bounding_union(part_box).area() - cand_box.area();
458  if (debug) {
459  tprintf("New best merge candidate has increase %d, area %d, over box:",
460  increase, best_area);
461  full_box.print();
462  candidate->Print();
463  }
464  } else if (increase == best_increase) {
465  int area = cand_box.bounding_union(part_box).area() - cand_box.area();
466  if (area < best_area) {
467  best_area = area;
468  best_candidate = candidate;
469  }
470  }
471  increase = IncreaseInOverlap(part, candidate, ok_overlap,
472  &non_candidate_neighbours);
473  if (increase > worst_nc_increase)
474  worst_nc_increase = increase;
475  }
476  if (best_increase > 0) {
477  // If the worst non-candidate increase is less than the best increase
478  // including the candidates, then all the candidates can merge together
479  // and the increase in outside overlap would be less, so use that result,
480  // but only if each candidate is either a good diacritic merge with part,
481  // or an ok merge candidate with all the others.
482  // See TestCompatibleCandidates for more explanation and a picture.
483  if (worst_nc_increase < best_increase &&
484  TestCompatibleCandidates(*part, debug, candidates)) {
485  best_increase = worst_nc_increase;
486  }
487  }
488  if (overlap_increase != nullptr)
489  *overlap_increase = best_increase;
490  return best_candidate;
491 }

◆ ClaimBoxes()

void tesseract::ColPartitionGrid::ClaimBoxes ( )

Definition at line 857 of file colpartitiongrid.cpp.

857  {
858  // Iterate the ColPartitions in the grid.
859  ColPartitionGridSearch gsearch(this);
860  gsearch.StartFullSearch();
861  ColPartition* part;
862  while ((part = gsearch.NextFullSearch()) != nullptr) {
863  part->ClaimBoxes();
864  }
865 }

◆ ComputeTotalOverlap()

int tesseract::ColPartitionGrid::ComputeTotalOverlap ( ColPartitionGrid **  overlap_grid)

Definition at line 312 of file colpartitiongrid.cpp.

312  {
313  int total_overlap = 0;
314  // Iterate the ColPartitions in the grid.
315  ColPartitionGridSearch gsearch(this);
316  gsearch.StartFullSearch();
317  ColPartition* part;
318  while ((part = gsearch.NextFullSearch()) != nullptr) {
319  ColPartition_CLIST neighbors;
320  const TBOX& part_box = part->bounding_box();
321  FindOverlappingPartitions(part_box, part, &neighbors);
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();
326  int overlap = n_box.intersection(part_box).area();
327  if (overlap > 0 && overlap_grid != nullptr) {
328  if (*overlap_grid == nullptr) {
329  *overlap_grid = new ColPartitionGrid(gridsize(), bleft(), tright());
330  }
331  (*overlap_grid)->InsertBBox(true, true, n_it.data()->ShallowCopy());
332  if (!any_part_overlap) {
333  (*overlap_grid)->InsertBBox(true, true, part->ShallowCopy());
334  }
335  }
336  any_part_overlap = true;
337  total_overlap += overlap;
338  }
339  }
340  return total_overlap;
341 }

◆ DeleteNonLeaderParts()

void tesseract::ColPartitionGrid::DeleteNonLeaderParts ( )

Definition at line 1036 of file colpartitiongrid.cpp.

1036  {
1037  ColPartitionGridSearch gsearch(this);
1038  gsearch.StartFullSearch();
1039  ColPartition* part;
1040  while ((part = gsearch.NextFullSearch()) != nullptr) {
1041  if (part->flow() != BTFT_LEADER) {
1042  gsearch.RemoveBBox();
1043  if (part->ReleaseNonLeaderBoxes()) {
1044  InsertBBox(true, true, part);
1045  gsearch.RepositionIterator();
1046  } else {
1047  delete part;
1048  }
1049  }
1050  }
1051 }

◆ DeleteParts()

void tesseract::ColPartitionGrid::DeleteParts ( )

Definition at line 1002 of file colpartitiongrid.cpp.

1002  {
1003  ColPartition_LIST dead_parts;
1004  ColPartition_IT dead_it(&dead_parts);
1005  ColPartitionGridSearch gsearch(this);
1006  gsearch.StartFullSearch();
1007  ColPartition* part;
1008  while ((part = gsearch.NextFullSearch()) != nullptr) {
1009  part->DisownBoxes();
1010  dead_it.add_to_end(part); // Parts will be deleted on return.
1011  }
1012  Clear();
1013 }

◆ DeleteUnknownParts()

void tesseract::ColPartitionGrid::DeleteUnknownParts ( TO_BLOCK block)

Definition at line 1017 of file colpartitiongrid.cpp.

1017  {
1018  ColPartitionGridSearch gsearch(this);
1019  gsearch.StartFullSearch();
1020  ColPartition* part;
1021  while ((part = gsearch.NextFullSearch()) != nullptr) {
1022  if (part->blob_type() == BRT_UNKNOWN) {
1023  gsearch.RemoveBBox();
1024  // Once marked, the blobs will be swept up by DeleteUnownedNoise.
1025  part->set_flow(BTFT_NONTEXT);
1026  part->set_blob_type(BRT_NOISE);
1027  part->SetBlobTypes();
1028  part->DisownBoxes();
1029  delete part;
1030  }
1031  }
1032  block->DeleteUnownedNoise();
1033 }

◆ Deskew()

void tesseract::ColPartitionGrid::Deskew ( const FCOORD deskew)

Definition at line 729 of file colpartitiongrid.cpp.

729  {
730  ColPartition_LIST parts;
731  ColPartition_IT part_it(&parts);
732  // Iterate the ColPartitions in the grid to extract them.
733  ColPartitionGridSearch gsearch(this);
734  gsearch.StartFullSearch();
735  ColPartition* part;
736  while ((part = gsearch.NextFullSearch()) != nullptr) {
737  part_it.add_after_then_move(part);
738  }
739  // Rebuild the grid to the new size.
740  TBOX grid_box(bleft_, tright_);
741  grid_box.rotate_large(deskew);
742  Init(gridsize(), grid_box.botleft(), grid_box.topright());
743  // Reinitializing the grid with rotated coords also clears all the
744  // pointers, so parts will now own the ColPartitions. (Briefly).
745  for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
746  part = part_it.extract();
747  part->ComputeLimits();
748  InsertBBox(true, true, part);
749  }
750 }

◆ ExtractPartitionsAsBlocks()

void tesseract::ColPartitionGrid::ExtractPartitionsAsBlocks ( BLOCK_LIST *  blocks,
TO_BLOCK_LIST *  to_blocks 
)

Definition at line 668 of file colpartitiongrid.cpp.

669  {
670  TO_BLOCK_IT to_block_it(to_blocks);
671  BLOCK_IT block_it(blocks);
672  // All partitions will be put on this list and deleted on return.
673  ColPartition_LIST parts;
674  ColPartition_IT part_it(&parts);
675  // Iterate the ColPartitions in the grid to extract them.
676  ColPartitionGridSearch gsearch(this);
677  gsearch.StartFullSearch();
678  ColPartition* part;
679  while ((part = gsearch.NextFullSearch()) != nullptr) {
680  part_it.add_after_then_move(part);
681  // The partition has to be at least vaguely like text.
682  BlobRegionType blob_type = part->blob_type();
683  if (BLOBNBOX::IsTextType(blob_type) ||
684  (blob_type == BRT_UNKNOWN && part->boxes_count() > 1)) {
686  : PT_FLOWING_TEXT;
687  // Get metrics from the row that will be used for the block.
688  TBOX box = part->bounding_box();
689  int median_width = part->median_width();
690  int median_height = part->median_height();
691  // Turn the partition into a TO_ROW.
692  TO_ROW* row = part->MakeToRow();
693  if (row == nullptr) {
694  // This partition is dead.
695  part->DeleteBoxes();
696  continue;
697  }
698  auto* block = new BLOCK("", true, 0, 0, box.left(), box.bottom(),
699  box.right(), box.top());
700  block->pdblk.set_poly_block(new POLY_BLOCK(box, type));
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);
704  // We haven't differentially rotated vertical and horizontal text at
705  // this point, so use width or height as appropriate.
706  if (blob_type == BRT_VERT_TEXT) {
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);
710  } else {
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);
714  }
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);
718  } else {
719  // This partition is dead.
720  part->DeleteBoxes();
721  }
722  }
723  Clear();
724  // Now it is safe to delete the ColPartitions as parts goes out of scope.
725 }

◆ FindFigureCaptions()

void tesseract::ColPartitionGrid::FindFigureCaptions ( )

Definition at line 1054 of file colpartitiongrid.cpp.

1054  {
1055  // For each image region find its best candidate text caption region,
1056  // if any and mark it as such.
1057  ColPartitionGridSearch gsearch(this);
1058  gsearch.StartFullSearch();
1059  ColPartition* part;
1060  while ((part = gsearch.NextFullSearch()) != nullptr) {
1061  if (part->IsImageType()) {
1062  const TBOX& part_box = part->bounding_box();
1063  bool debug = AlignedBlob::WithinTestRegion(2, part_box.left(),
1064  part_box.bottom());
1065  ColPartition* best_caption = nullptr;
1066  int best_dist = 0; // Distance to best_caption.
1067  int best_upper = 0; // Direction of best_caption.
1068  // Handle both lower and upper directions.
1069  for (int upper = 0; upper < 2; ++upper) {
1070  ColPartition_C_IT partner_it(upper ? part->upper_partners()
1071  : part->lower_partners());
1072  // If there are no image partners, then this direction is ok.
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()) {
1077  break;
1078  }
1079  }
1080  if (!partner_it.cycled_list()) continue;
1081  // Find the nearest totally overlapping text partner.
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();
1087  if (debug) {
1088  tprintf("Finding figure captions for image part:");
1089  part_box.print();
1090  tprintf("Considering partner:");
1091  partner_box.print();
1092  }
1093  if (partner_box.left() >= part_box.left() &&
1094  partner_box.right() <= part_box.right()) {
1095  int dist = partner_box.y_gap(part_box);
1096  if (best_caption == nullptr || dist < best_dist) {
1097  best_dist = dist;
1098  best_caption = partner;
1099  best_upper = upper;
1100  }
1101  }
1102  }
1103  }
1104  if (best_caption != nullptr) {
1105  if (debug) {
1106  tprintf("Best caption candidate:");
1107  best_caption->bounding_box().print();
1108  }
1109  // We have a candidate caption. Qualify it as being separable from
1110  // any body text. We are looking for either a small number of lines
1111  // or a big gap that indicates a separation from the body text.
1112  int line_count = 0;
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 &&
1120  line_count <= kMaxCaptionLines;
1121  partner = next_partner) {
1122  if (!partner->IsTextType()) {
1123  end_partner = partner;
1124  break;
1125  }
1126  ++line_count;
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) {
1133  biggest_gap = gap;
1134  end_partner = next_partner;
1135  mean_height = total_height / line_count;
1136  } else if (gap < smallest_gap) {
1137  smallest_gap = gap;
1138  }
1139  // If the gap looks big compared to the text size and the smallest
1140  // gap seen so far, then we can stop.
1141  if (biggest_gap > mean_height * kMinCaptionGapHeightRatio &&
1142  biggest_gap > smallest_gap * kMinCaptionGapRatio)
1143  break;
1144  }
1145  }
1146  if (debug) {
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) {
1150  tprintf("End partner:");
1151  end_partner->bounding_box().print();
1152  }
1153  }
1154  if (next_partner == nullptr && line_count <= kMaxCaptionLines)
1155  end_partner = nullptr; // No gap, but line count is small.
1156  if (line_count <= kMaxCaptionLines) {
1157  // This is a qualified caption. Mark the text as caption.
1158  for (ColPartition* partner = best_caption; partner != nullptr &&
1159  partner != end_partner;
1160  partner = next_partner) {
1161  partner->set_type(PT_CAPTION_TEXT);
1162  partner->SetBlobTypes();
1163  if (debug) {
1164  tprintf("Set caption type for partition:");
1165  partner->bounding_box().print();
1166  }
1167  next_partner = partner->SingletonPartner(best_upper);
1168  }
1169  }
1170  }
1171  }
1172  }
1173 }

◆ FindOverlappingPartitions()

void tesseract::ColPartitionGrid::FindOverlappingPartitions ( const TBOX box,
const ColPartition not_this,
ColPartition_CLIST *  parts 
)

Definition at line 346 of file colpartitiongrid.cpp.

348  {
349  ColPartitionGridSearch rsearch(this);
350  rsearch.StartRectSearch(box);
351  ColPartition* part;
352  while ((part = rsearch.NextRectSearch()) != nullptr) {
353  if (part != not_this)
354  parts->add_sorted(SortByBoxLeft<ColPartition>, true, part);
355  }
356 }

◆ FindPartitionPartners() [1/2]

void tesseract::ColPartitionGrid::FindPartitionPartners ( )

Definition at line 1179 of file colpartitiongrid.cpp.

1179  {
1180  ColPartitionGridSearch gsearch(this);
1181  gsearch.StartFullSearch();
1182  ColPartition* part;
1183  while ((part = gsearch.NextFullSearch()) != nullptr) {
1184  if (part->IsVerticalType()) {
1185  FindVPartitionPartners(true, part);
1186  FindVPartitionPartners(false, part);
1187  } else {
1188  FindPartitionPartners(true, part);
1189  FindPartitionPartners(false, part);
1190  }
1191  }
1192 }

◆ FindPartitionPartners() [2/2]

void tesseract::ColPartitionGrid::FindPartitionPartners ( bool  upper,
ColPartition part 
)

Definition at line 1196 of file colpartitiongrid.cpp.

1196  {
1197  if (part->type() == PT_NOISE)
1198  return; // Noise is not allowed to partner anything.
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;
1204  ColPartitionGridSearch vsearch(this);
1205  // Search down for neighbour below
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)
1212  continue; // Noise is not allowed to partner anything.
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))
1217  continue;
1218  if (!part->HOverlaps(*neighbour) && !part->WithinSameMargins(*neighbour))
1219  continue;
1220  if (!part->TypesMatch(*neighbour)) {
1221  if (best_neighbour == nullptr)
1222  best_neighbour = neighbour;
1223  continue;
1224  }
1225  int dist = upper ? neighbour_bottom - top : bottom - neighbour_top;
1226  if (dist <= kMaxPartitionSpacing * height) {
1227  if (dist < best_dist) {
1228  best_dist = dist;
1229  best_neighbour = neighbour;
1230  }
1231  } else {
1232  break;
1233  }
1234  }
1235  if (best_neighbour != nullptr)
1236  part->AddPartner(upper, best_neighbour);
1237 }

◆ FindVPartitionPartners()

void tesseract::ColPartitionGrid::FindVPartitionPartners ( bool  to_the_left,
ColPartition part 
)

Definition at line 1241 of file colpartitiongrid.cpp.

1242  {
1243  if (part->type() == PT_NOISE)
1244  return; // Noise is not allowed to partner anything.
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;
1250  ColPartitionGridSearch hsearch(this);
1251  // Search left for neighbour to_the_left
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)
1258  continue; // Noise is not allowed to partner anything.
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))
1263  continue;
1264  if (!part->VOverlaps(*neighbour))
1265  continue;
1266  if (!part->TypesMatch(*neighbour))
1267  continue; // Only match to other vertical text.
1268  int dist = to_the_left ? left - neighbour_right : neighbour_left - right;
1269  if (dist <= kMaxPartitionSpacing * width) {
1270  if (dist < best_dist || best_neighbour == nullptr) {
1271  best_dist = dist;
1272  best_neighbour = neighbour;
1273  }
1274  } else {
1275  break;
1276  }
1277  }
1278  // For vertical partitions, the upper partner is to the left, and lower is
1279  // to the right.
1280  if (best_neighbour != nullptr)
1281  part->AddPartner(to_the_left, best_neighbour);
1282 }

◆ GridFindMargins()

void tesseract::ColPartitionGrid::GridFindMargins ( ColPartitionSet **  best_columns)

Definition at line 960 of file colpartitiongrid.cpp.

960  {
961  // Iterate the ColPartitions in the grid.
962  ColPartitionGridSearch gsearch(this);
963  gsearch.StartFullSearch();
964  ColPartition* part;
965  while ((part = gsearch.NextFullSearch()) != nullptr) {
966  // Set up a rectangle search x-bounded by the column and y by the part.
967  ColPartitionSet* columns = best_columns != nullptr
968  ? best_columns[gsearch.GridY()]
969  : nullptr;
970  FindPartitionMargins(columns, part);
971  const TBOX& box = part->bounding_box();
972  if (AlignedBlob::WithinTestRegion(2, box.left(), box.bottom())) {
973  tprintf("Computed margins for part:");
974  part->Print();
975  }
976  }
977 }

◆ 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.

621  {
622  // Iterate the ColPartitions in the grid.
623  ColPartitionGridSearch gsearch(this);
624  gsearch.StartFullSearch();
625  ColPartition* part;
626  bool any_changed = false;
627  while ((part = gsearch.NextFullSearch()) != nullptr) {
628  if (part->flow() != source_type || BLOBNBOX::IsLineType(part->blob_type()))
629  continue;
630  const TBOX& box = part->bounding_box();
631  bool debug = AlignedBlob::WithinTestRegion(2, box.left(), box.bottom());
632  if (SmoothRegionType(nontext_map, im_box, rotation, debug, part))
633  any_changed = true;
634  }
635  return any_changed;
636 }

◆ HandleClick()

void tesseract::ColPartitionGrid::HandleClick ( int  x,
int  y 
)
overridevirtual

Reimplemented from tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT >.

Definition at line 73 of file colpartitiongrid.cpp.

73  {
74  BBGrid<ColPartition,
75  ColPartition_CLIST, ColPartition_C_IT>::HandleClick(x, y);
76  // Run a radial search for partitions that overlap.
77  ColPartitionGridSearch radsearch(this);
78  radsearch.SetUniqueMode(true);
79  radsearch.StartRadSearch(x, y, 1);
80  ColPartition* neighbour;
81  FCOORD click(x, y);
82  while ((neighbour = radsearch.NextRadSearch()) != nullptr) {
83  const TBOX& nbox = neighbour->bounding_box();
84  if (nbox.contains(click)) {
85  tprintf("Block box:");
86  neighbour->bounding_box().print();
87  neighbour->Print();
88  }
89  }
90 }

◆ ListFindMargins()

void tesseract::ColPartitionGrid::ListFindMargins ( ColPartitionSet **  best_columns,
ColPartition_LIST *  parts 
)

Definition at line 984 of file colpartitiongrid.cpp.

985  {
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();
992  // Get the columns from the y grid coord.
993  int grid_x, grid_y;
994  GridCoords(part_box.left(), part_box.bottom(), &grid_x, &grid_y);
995  columns = best_columns[grid_y];
996  }
997  FindPartitionMargins(columns, part);
998  }
999 }

◆ MakeColPartSets()

bool tesseract::ColPartitionGrid::MakeColPartSets ( PartSetVector part_sets)

Definition at line 777 of file colpartitiongrid.cpp.

777  {
778  auto* part_lists = new ColPartition_LIST[gridheight()];
779  part_sets->reserve(gridheight());
780  // Iterate the ColPartitions in the grid to get parts onto lists for the
781  // y bottom of each.
782  ColPartitionGridSearch gsearch(this);
783  gsearch.StartFullSearch();
784  ColPartition* part;
785  bool any_parts_found = false;
786  while ((part = gsearch.NextFullSearch()) != nullptr) {
787  BlobRegionType blob_type = part->blob_type();
788  if (blob_type != BRT_NOISE &&
789  (blob_type != BRT_UNKNOWN || !part->boxes()->singleton())) {
790  int grid_x, grid_y;
791  const TBOX& part_box = part->bounding_box();
792  GridCoords(part_box.left(), part_box.bottom(), &grid_x, &grid_y);
793  ColPartition_IT part_it(&part_lists[grid_y]);
794  part_it.add_to_end(part);
795  any_parts_found = true;
796  }
797  }
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]);
803  }
804  part_sets->push_back(line_set);
805  }
806  }
807  delete [] part_lists;
808  return any_parts_found;
809 }

◆ MakeSingleColumnSet()

ColPartitionSet * tesseract::ColPartitionGrid::MakeSingleColumnSet ( WidthCallback  cb)

Definition at line 815 of file colpartitiongrid.cpp.

815  {
816  ColPartition* single_column_part = nullptr;
817  // Iterate the ColPartitions in the grid to get parts onto lists for the
818  // y bottom of each.
819  ColPartitionGridSearch gsearch(this);
820  gsearch.StartFullSearch();
821  ColPartition* part;
822  while ((part = gsearch.NextFullSearch()) != nullptr) {
823  BlobRegionType blob_type = part->blob_type();
824  if (blob_type != BRT_NOISE &&
825  (blob_type != BRT_UNKNOWN || !part->boxes()->singleton())) {
826  // Consider for single column.
827  BlobTextFlowType flow = part->flow();
828  if ((blob_type == BRT_TEXT &&
829  (flow == BTFT_STRONG_CHAIN || flow == BTFT_CHAIN ||
830  flow == BTFT_LEADER || flow == BTFT_TEXT_ON_IMAGE)) ||
831  blob_type == BRT_RECTIMAGE || blob_type == BRT_POLYIMAGE) {
832  if (single_column_part == nullptr) {
833  single_column_part = part->ShallowCopy();
834  single_column_part->set_blob_type(BRT_TEXT);
835  // Copy the tabs from itself to properly setup the margins.
836  single_column_part->CopyLeftTab(*single_column_part, false);
837  single_column_part->CopyRightTab(*single_column_part, false);
838  } else {
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);
843  }
844  }
845  }
846  }
847  if (single_column_part != nullptr) {
848  // Make a ColPartitionSet out of the single_column_part as a candidate
849  // for the single column case.
850  single_column_part->SetColumnGoodness(cb);
851  return new ColPartitionSet(single_column_part);
852  }
853  return nullptr;
854 }

◆ MergePart()

bool tesseract::ColPartitionGrid::MergePart ( std::function< bool(ColPartition *, TBOX *)>  box_cb,
std::function< bool(const ColPartition *, const ColPartition *)>  confirm_cb,
ColPartition part 
)

Definition at line 117 of file colpartitiongrid.cpp.

120  {
121  if (part->IsUnMergeableType())
122  return false;
123  bool any_done = false;
124  // Repeatedly merge part while we find a best merge candidate that works.
125  bool merge_done = false;
126  do {
127  merge_done = false;
128  TBOX box = part->bounding_box();
129  bool debug = AlignedBlob::WithinTestRegion(2, box.left(), box.bottom());
130  if (debug) {
131  tprintf("Merge candidate:");
132  box.print();
133  }
134  // Set up a rectangle search bounded by the part.
135  if (!box_cb(part, &box))
136  continue;
137  // Create a list of merge candidates.
138  ColPartition_CLIST merge_candidates;
139  FindMergeCandidates(part, box, debug, &merge_candidates);
140  // Find the best merge candidate based on minimal overlap increase.
141  int overlap_increase;
142  ColPartition* neighbour = BestMergeCandidate(part, &merge_candidates, debug,
143  confirm_cb,
144  &overlap_increase);
145  if (neighbour != nullptr && overlap_increase <= 0) {
146  if (debug) {
147  tprintf("Merging:hoverlap=%d, voverlap=%d, OLI=%d\n",
148  part->HCoreOverlap(*neighbour), part->VCoreOverlap(*neighbour),
149  overlap_increase);
150  }
151  // Looks like a good candidate so merge it.
152  RemoveBBox(neighbour);
153  // We will modify the box of part, so remove it from the grid, merge
154  // it and then re-insert it into the grid.
155  RemoveBBox(part);
156  part->Absorb(neighbour, nullptr);
157  InsertBBox(true, true, part);
158  merge_done = true;
159  any_done = true;
160  } else if (neighbour != nullptr) {
161  if (debug) {
162  tprintf("Overlapped when merged with increase %d: ", overlap_increase);
163  neighbour->bounding_box().print();
164  }
165  } else if (debug) {
166  tprintf("No candidate neighbour returned\n");
167  }
168  } while (merge_done);
169  return any_done;
170 }

◆ Merges()

void tesseract::ColPartitionGrid::Merges ( std::function< bool(ColPartition *, TBOX *)>  box_cb,
std::function< bool(const ColPartition *, const ColPartition *)>  confirm_cb 
)

Definition at line 99 of file colpartitiongrid.cpp.

101  {
102  // Iterate the ColPartitions in the grid.
103  ColPartitionGridSearch gsearch(this);
104  gsearch.StartFullSearch();
105  ColPartition* part;
106  while ((part = gsearch.NextFullSearch()) != nullptr) {
107  if (MergePart(box_cb, confirm_cb, part))
108  gsearch.RepositionIterator();
109  }
110 }

◆ RecomputeBounds()

void tesseract::ColPartitionGrid::RecomputeBounds ( int  gridsize,
const ICOORD bleft,
const ICOORD tright,
const ICOORD vertical 
)

Definition at line 931 of file colpartitiongrid.cpp.

934  {
935  ColPartition_LIST saved_parts;
936  ColPartition_IT part_it(&saved_parts);
937  // Iterate the ColPartitions in the grid to get parts onto a list.
938  ColPartitionGridSearch gsearch(this);
939  gsearch.StartFullSearch();
940  ColPartition* part;
941  while ((part = gsearch.NextFullSearch()) != nullptr) {
942  part_it.add_to_end(part);
943  }
944  // Reinitialize grid to the new size.
946  // Recompute the bounds of the parts and put them back in the new grid.
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();
951  InsertBBox(true, true, part);
952  }
953 }

◆ RefinePartitionPartners()

void tesseract::ColPartitionGrid::RefinePartitionPartners ( bool  get_desperate)

Definition at line 1287 of file colpartitiongrid.cpp.

1287  {
1288  ColPartitionGridSearch gsearch(this);
1289  // Refine in type order so that chasing multiple partners can be done
1290  // before eliminating type mis-matching partners.
1291  for (int type = PT_UNKNOWN + 1; type <= PT_COUNT; type++) {
1292  // Iterate the ColPartitions in the grid.
1293  gsearch.StartFullSearch();
1294  ColPartition* part;
1295  while ((part = gsearch.NextFullSearch()) != nullptr) {
1296  part->RefinePartners(static_cast<PolyBlockType>(type),
1297  get_desperate, this);
1298  // Iterator may have been messed up by a merge.
1299  gsearch.RepositionIterator();
1300  }
1301  }
1302 }

◆ ReflectInYAxis()

void tesseract::ColPartitionGrid::ReflectInYAxis ( )

Definition at line 640 of file colpartitiongrid.cpp.

640  {
641  ColPartition_LIST parts;
642  ColPartition_IT part_it(&parts);
643  // Iterate the ColPartitions in the grid to extract them.
644  ColPartitionGridSearch gsearch(this);
645  gsearch.StartFullSearch();
646  ColPartition* part;
647  while ((part = gsearch.NextFullSearch()) != nullptr) {
648  part_it.add_after_then_move(part);
649  }
650  ICOORD bot_left(-tright().x(), bleft().y());
651  ICOORD top_right(-bleft().x(), tright().y());
652  // Reinitializing the grid with reflected coords also clears all the
653  // pointers, so parts will now own the ColPartitions. (Briefly).
654  Init(gridsize(), bot_left, top_right);
655  for (part_it.move_to_first(); !part_it.empty(); part_it.forward()) {
656  part = part_it.extract();
657  part->ReflectInYAxis();
658  InsertBBox(true, true, part);
659  }
660 }

◆ ReTypeBlobs()

void tesseract::ColPartitionGrid::ReTypeBlobs ( BLOBNBOX_LIST *  im_blobs)

Definition at line 870 of file colpartitiongrid.cpp.

870  {
871  BLOBNBOX_IT im_blob_it(im_blobs);
872  ColPartition_LIST dead_parts;
873  ColPartition_IT dead_part_it(&dead_parts);
874  // Iterate the ColPartitions in the grid.
875  ColPartitionGridSearch gsearch(this);
876  gsearch.StartFullSearch();
877  ColPartition* part;
878  while ((part = gsearch.NextFullSearch()) != nullptr) {
879  BlobRegionType blob_type = part->blob_type();
880  BlobTextFlowType flow = part->flow();
881  bool any_blobs_moved = false;
882  if (blob_type == BRT_POLYIMAGE || blob_type == BRT_RECTIMAGE) {
883  BLOBNBOX_C_IT blob_it(part->boxes());
884  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
885  BLOBNBOX* blob = blob_it.data();
886  im_blob_it.add_after_then_move(blob);
887  }
888  } else if (blob_type != BRT_NOISE) {
889  // Make sure the blobs are marked with the correct type and flow.
890  BLOBNBOX_C_IT blob_it(part->boxes());
891  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
892  BLOBNBOX* blob = blob_it.data();
893  if (blob->region_type() == BRT_NOISE) {
894  // TODO(rays) Deprecated. Change this section to an assert to verify
895  // and then delete.
896  ASSERT_HOST(blob->cblob()->area() != 0);
897  blob->set_owner(nullptr);
898  blob_it.extract();
899  any_blobs_moved = true;
900  } else {
901  blob->set_region_type(blob_type);
902  if (blob->flow() != BTFT_LEADER)
903  blob->set_flow(flow);
904  }
905  }
906  }
907  if (blob_type == BRT_NOISE || part->boxes()->empty()) {
908  BLOBNBOX_C_IT blob_it(part->boxes());
909  part->DisownBoxes();
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()) {
913  BLOBNBOX* blob = blob_it.data();
914  if (blob->cblob()->area() == 0) {
915  // Any blob with zero area is a fake image blob and should be deleted.
916  delete blob->cblob();
917  delete blob;
918  }
919  }
920  } else if (any_blobs_moved) {
921  gsearch.RemoveBBox();
922  part->ComputeLimits();
923  InsertBBox(true, true, part);
924  gsearch.RepositionIterator();
925  }
926  }
927 }

◆ SetTabStops()

void tesseract::ColPartitionGrid::SetTabStops ( TabFind tabgrid)

Definition at line 753 of file colpartitiongrid.cpp.

753  {
754  // Iterate the ColPartitions in the grid.
755  ColPartitionGridSearch gsearch(this);
756  gsearch.StartFullSearch();
757  ColPartition* part;
758  while ((part = gsearch.NextFullSearch()) != nullptr) {
759  const TBOX& part_box = part->bounding_box();
760  TabVector* left_line = tabgrid->LeftTabForBox(part_box, true, false);
761  // If the overlapping line is not a left tab, try for non-overlapping.
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());
772  }
773 }

◆ SplitOverlappingPartitions()

void tesseract::ColPartitionGrid::SplitOverlappingPartitions ( ColPartition_LIST *  big_parts)

Definition at line 508 of file colpartitiongrid.cpp.

509  {
510  int ok_overlap =
511  static_cast<int>(kTinyEnoughTextlineOverlapFraction * gridsize() + 0.5);
512  // Iterate the ColPartitions in the grid.
513  ColPartitionGridSearch gsearch(this);
514  gsearch.StartFullSearch();
515  ColPartition* part;
516  while ((part = gsearch.NextFullSearch()) != nullptr) {
517  // Set up a rectangle search bounded by the part.
518  const TBOX& box = part->bounding_box();
519  ColPartitionGridSearch rsearch(this);
520  rsearch.SetUniqueMode(true);
521  rsearch.StartRectSearch(box);
522  int unresolved_overlaps = 0;
523 
524  ColPartition* neighbour;
525  while ((neighbour = rsearch.NextRectSearch()) != nullptr) {
526  if (neighbour == part)
527  continue;
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))
531  continue; // The overlap is OK both ways.
532 
533  // If removal of the biggest box from either partition eliminates the
534  // overlap, and it is much bigger than the box left behind, then
535  // it is either a drop-cap, an inter-line join, or some junk that
536  // we don't want anyway, so put it in the big_parts list.
537  if (!part->IsSingleton()) {
538  BLOBNBOX* excluded = part->BiggestBox();
539  TBOX shrunken = part->BoundsWithoutBox(excluded);
540  if (!shrunken.overlap(neighbour_box) &&
541  excluded->bounding_box().height() >
542  kBigPartSizeRatio * shrunken.height()) {
543  // Removing the biggest box fixes the overlap, so do it!
544  gsearch.RemoveBBox();
545  RemoveBadBox(excluded, part, big_parts);
546  InsertBBox(true, true, part);
547  gsearch.RepositionIterator();
548  break;
549  }
550  } else if (box.contains(neighbour_box)) {
551  ++unresolved_overlaps;
552  continue; // No amount of splitting will fix it.
553  }
554  if (!neighbour->IsSingleton()) {
555  BLOBNBOX* excluded = neighbour->BiggestBox();
556  TBOX shrunken = neighbour->BoundsWithoutBox(excluded);
557  if (!shrunken.overlap(box) &&
558  excluded->bounding_box().height() >
559  kBigPartSizeRatio * shrunken.height()) {
560  // Removing the biggest box fixes the overlap, so do it!
561  rsearch.RemoveBBox();
562  RemoveBadBox(excluded, neighbour, big_parts);
563  InsertBBox(true, true, neighbour);
564  gsearch.RepositionIterator();
565  break;
566  }
567  }
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()) {
573  // Try to split the neighbour to reduce overlap.
574  BLOBNBOX* split_blob = neighbour->OverlapSplitBlob(box);
575  if (split_blob != nullptr) {
576  rsearch.RemoveBBox();
577  right_part = neighbour->SplitAtBlob(split_blob);
578  InsertBBox(true, true, neighbour);
579  ASSERT_HOST(right_part != nullptr);
580  }
581  } else {
582  // Try to split part to reduce overlap.
583  BLOBNBOX* split_blob = part->OverlapSplitBlob(neighbour_box);
584  if (split_blob != nullptr) {
585  gsearch.RemoveBBox();
586  right_part = part->SplitAtBlob(split_blob);
587  InsertBBox(true, true, part);
588  ASSERT_HOST(right_part != nullptr);
589  }
590  }
591  if (right_part != nullptr) {
592  InsertBBox(true, true, right_part);
593  gsearch.RepositionIterator();
594  rsearch.RepositionIterator();
595  break;
596  }
597  }
598  if (unresolved_overlaps > 2 && part->IsSingleton()) {
599  // This part is no good so just add to big_parts.
600  RemoveBBox(part);
601  ColPartition_IT big_it(big_parts);
602  part->set_block_owned(true);
603  big_it.add_to_end(part);
604  gsearch.RepositionIterator();
605  }
606  }
607 }

The documentation for this class was generated from the following files:
BlobTextFlowType
BlobTextFlowType
Definition: blobbox.h:113
TBOX::intersection
TBOX intersection(const TBOX &box) const
Definition: rect.cpp:83
BTFT_STRONG_CHAIN
Definition: blobbox.h:118
tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT >::InsertBBox
void InsertBBox(bool h_spread, bool v_spread, ColPartition *bbox)
Definition: bbgrid.h:486
tesseract::ColPartitionGrid::BestMergeCandidate
ColPartition * BestMergeCandidate(const ColPartition *part, ColPartition_CLIST *candidates, bool debug, std::function< bool(const ColPartition *, const ColPartition *)> confirm_cb, int *overlap_increase)
Definition: colpartitiongrid.cpp:399
BRT_NOISE
Definition: blobbox.h:72
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
tesseract::GridBase::tright_
ICOORD tright_
Definition: bbgrid.h:91
TBOX::overlap
bool overlap(const TBOX &box) const
Definition: rect.h:350
BRT_UNKNOWN
Definition: blobbox.h:77
ICOORD
integer coordinate
Definition: points.h:30
BLOBNBOX::set_flow
void set_flow(BlobTextFlowType value)
Definition: blobbox.h:297
tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT >::RemoveBBox
void RemoveBBox(ColPartition *bbox)
Definition: bbgrid.h:533
TBOX::print
void print() const
Definition: rect.h:277
TO_BLOCK::DeleteUnownedNoise
void DeleteUnownedNoise()
Definition: blobbox.cpp:1020
TBOX::top
int16_t top() const
Definition: rect.h:57
TBOX::contains
bool contains(const FCOORD pt) const
Definition: rect.h:330
tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT >::Clear
void Clear()
Definition: bbgrid.h:455
TBOX::bounding_union
TBOX bounding_union(const TBOX &box) const
Definition: rect.cpp:124
PT_NOISE
Definition: capi.h:122
TBOX::area
int32_t area() const
Definition: rect.h:121
TO_BLOCK
Definition: blobbox.h:691
BRT_VERT_TEXT
Definition: blobbox.h:78
PT_TABLE
Definition: capi.h:114
PT_CAPTION_TEXT
Definition: capi.h:116
tesseract::ColPartitionGridSearch
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
Definition: colpartition.h:935
BRT_RECTIMAGE
Definition: blobbox.h:75
tesseract::kMaxPartitionSpacing
const double kMaxPartitionSpacing
Definition: colpartitiongrid.cpp:61
tesseract::kTinyEnoughTextlineOverlapFraction
const double kTinyEnoughTextlineOverlapFraction
Definition: colpartitiongrid.cpp:48
FCOORD
Definition: points.h:187
BLOBNBOX
Definition: blobbox.h:142
BTFT_CHAIN
Definition: blobbox.h:117
BTFT_LEADER
Definition: blobbox.h:120
BRT_POLYIMAGE
Definition: blobbox.h:76
PT_VERTICAL_TEXT
Definition: capi.h:115
C_BLOB::area
int32_t area()
Definition: stepblob.cpp:266
PT_COUNT
Definition: capi.h:123
tesseract::ColPartitionGrid::HandleClick
void HandleClick(int x, int y) override
Definition: colpartitiongrid.cpp:73
tesseract::GridBase::tright
const ICOORD & tright() const
Definition: bbgrid.h:75
TBOX::height
int16_t height() const
Definition: rect.h:107
TBOX::y_gap
int y_gap(const TBOX &box) const
Definition: rect.h:232
BTFT_NONTEXT
Definition: blobbox.h:115
tesseract::kBigPartSizeRatio
const double kBigPartSizeRatio
Definition: colpartitiongrid.cpp:46
BLOBNBOX::IsLineType
static bool IsLineType(BlobRegionType type)
Definition: blobbox.h:425
tesseract::kMaxCaptionLines
const int kMaxCaptionLines
Definition: colpartitiongrid.cpp:38
BLOCK
Definition: ocrblock.h:28
BLOCK::pdblk
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:189
tesseract::ColPartitionGrid::FindOverlappingPartitions
void FindOverlappingPartitions(const TBOX &box, const ColPartition *not_this, ColPartition_CLIST *parts)
Definition: colpartitiongrid.cpp:346
PDBLK::set_poly_block
void set_poly_block(POLY_BLOCK *blk)
set the poly block
Definition: pdblock.h:56
BTFT_TEXT_ON_IMAGE
Definition: blobbox.h:119
BlobRegionType
BlobRegionType
Definition: blobbox.h:71
tesseract::AlignedBlob::WithinTestRegion
static bool WithinTestRegion(int detail_level, int x, int y)
Definition: alignedblob.cpp:150
BRT_TEXT
Definition: blobbox.h:79
tesseract::ColPartitionGrid::FindVPartitionPartners
void FindVPartitionPartners(bool to_the_left, ColPartition *part)
Definition: colpartitiongrid.cpp:1241
TBOX::width
int16_t width() const
Definition: rect.h:114
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
BLOBNBOX::set_owner
void set_owner(tesseract::ColPartition *new_owner)
Definition: blobbox.h:354
tesseract::GridBase::bleft_
ICOORD bleft_
Definition: bbgrid.h:90
tesseract::ColPartitionGrid::MergePart
bool MergePart(std::function< bool(ColPartition *, TBOX *)> box_cb, std::function< bool(const ColPartition *, const ColPartition *)> confirm_cb, ColPartition *part)
Definition: colpartitiongrid.cpp:117
BLOBNBOX::set_region_type
void set_region_type(BlobRegionType new_type)
Definition: blobbox.h:285
PT_UNKNOWN
Definition: capi.h:108
BLOBNBOX::bounding_box
const TBOX & bounding_box() const
Definition: blobbox.h:229
tesseract::GridBase::gridsize
int gridsize() const
Definition: bbgrid.h:63
tesseract::kMinCaptionGapHeightRatio
const double kMinCaptionGapHeightRatio
Definition: colpartitiongrid.cpp:42
tesseract::ColPartitionGrid::FindPartitionPartners
void FindPartitionPartners()
Definition: colpartitiongrid.cpp:1179
tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT >::Init
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:445
BLOBNBOX::flow
BlobTextFlowType flow() const
Definition: blobbox.h:294
TBOX::left
int16_t left() const
Definition: rect.h:71
PT_FLOWING_TEXT
Definition: capi.h:109
BLOBNBOX::region_type
BlobRegionType region_type() const
Definition: blobbox.h:282
TBOX::right
int16_t right() const
Definition: rect.h:78
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
tesstrain_utils.type
type
Definition: tesstrain_utils.py:141
POLY_BLOCK
Definition: polyblk.h:26
TO_ROW
Definition: blobbox.h:543
tesseract::kMinCaptionGapRatio
const double kMinCaptionGapRatio
Definition: colpartitiongrid.cpp:40
tesseract::BBGrid< ColPartition, ColPartition_CLIST, ColPartition_C_IT >::BBGrid
BBGrid()
Definition: bbgrid.h:427
BLOBNBOX::cblob
C_BLOB * cblob() const
Definition: blobbox.h:267
PolyBlockType
PolyBlockType
Definition: publictypes.h:52
tesseract::ColPartitionGrid::ColPartitionGrid
ColPartitionGrid()=default
BLOBNBOX::IsTextType
static bool IsTextType(BlobRegionType type)
Definition: blobbox.h:417
tesseract::GridBase::gridheight
int gridheight() const
Definition: bbgrid.h:69
tesseract::GridBase::bleft
const ICOORD & bleft() const
Definition: bbgrid.h:72
tesseract::GridBase::GridCoords
void GridCoords(int x, int y, int *grid_x, int *grid_y) const
Definition: bbgrid.cpp:52
TBOX
Definition: rect.h:33