tesseract  4.0.0-1-g2a2b
tesseract::ColumnFinder Class Reference

#include <colfind.h>

Inheritance diagram for tesseract::ColumnFinder:
tesseract::TabFind tesseract::AlignedBlob tesseract::BlobGrid tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > tesseract::GridBase

Public Member Functions

 ColumnFinder (int gridsize, const ICOORD &bleft, const ICOORD &tright, int resolution, bool cjk_script, double aligned_gap_fraction, TabVector_LIST *vlines, TabVector_LIST *hlines, int vertical_x, int vertical_y)
 
virtual ~ColumnFinder ()
 
const DENORMdenorm () const
 
const TextlineProjectionprojection () const
 
void set_cjk_script (bool is_cjk)
 
void SetupAndFilterNoise (PageSegMode pageseg_mode, Pix *photo_mask_pix, TO_BLOCK *input_block)
 
bool IsVerticallyAlignedText (double find_vertical_text_ratio, TO_BLOCK *block, BLOBNBOX_CLIST *osd_blobs)
 
void CorrectOrientation (TO_BLOCK *block, bool vertical_text_lines, int recognition_rotation)
 
int FindBlocks (PageSegMode pageseg_mode, Pix *scaled_color, int scaled_factor, TO_BLOCK *block, Pix *photo_mask_pix, Pix *thresholds_pix, Pix *grey_pix, DebugPixa *pixa_debug, BLOCK_LIST *blocks, BLOBNBOX_LIST *diacritic_blobs, TO_BLOCK_LIST *to_blocks)
 
void GetDeskewVectors (FCOORD *deskew, FCOORD *reskew)
 
void SetEquationDetect (EquationDetectBase *detect)
 
- Public Member Functions inherited from tesseract::TabFind
 TabFind (int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVector_LIST *vlines, int vertical_x, int vertical_y, int resolution)
 
virtual ~TabFind ()
 
void InsertBlobsToGrid (bool h_spread, bool v_spread, BLOBNBOX_LIST *blobs, BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > *grid)
 
bool InsertBlob (bool h_spread, bool v_spread, BLOBNBOX *blob, BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > *grid)
 
void SetBlockRuleEdges (TO_BLOCK *block)
 
void SetBlobRuleEdges (BLOBNBOX_LIST *blobs)
 
int GutterWidth (int bottom_y, int top_y, const TabVector &v, bool ignore_unmergeables, int max_gutter_width, int *required_shift)
 
void GutterWidthAndNeighbourGap (int tab_x, int mean_height, int max_gutter, bool left, BLOBNBOX *bbox, int *gutter_width, int *neighbour_gap)
 
int RightEdgeForBox (const TBOX &box, bool crossing, bool extended)
 
int LeftEdgeForBox (const TBOX &box, bool crossing, bool extended)
 
TabVectorRightTabForBox (const TBOX &box, bool crossing, bool extended)
 
TabVectorLeftTabForBox (const TBOX &box, bool crossing, bool extended)
 
bool CommonWidth (int width)
 
WidthCallbackWidthCB ()
 
const ICOORDimage_origin () const
 
- Public Member Functions inherited from tesseract::AlignedBlob
 AlignedBlob (int gridsize, const ICOORD &bleft, const ICOORD &tright)
 
virtual ~AlignedBlob ()
 
ScrollViewDisplayTabs (const char *window_name, ScrollView *tab_win)
 
TabVectorFindVerticalAlignment (AlignedBlobParams align_params, BLOBNBOX *bbox, int *vertical_x, int *vertical_y)
 
- Public Member Functions inherited from tesseract::BlobGrid
 BlobGrid (int gridsize, const ICOORD &bleft, const ICOORD &tright)
 
virtual ~BlobGrid ()
 
void InsertBlobList (BLOBNBOX_LIST *blobs)
 
- Public Member Functions inherited from tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT >
 BBGrid ()
 
 BBGrid (int gridsize, const ICOORD &bleft, const ICOORD &tright)
 
virtual ~BBGrid ()
 
void Init (int gridsize, const ICOORD &bleft, const ICOORD &tright)
 
void Clear ()
 
void ClearGridData (void(*free_method)(BLOBNBOX *))
 
void InsertBBox (bool h_spread, bool v_spread, BLOBNBOX *bbox)
 
void InsertPixPtBBox (int left, int bottom, Pix *pix, BLOBNBOX *bbox)
 
void RemoveBBox (BLOBNBOX *bbox)
 
bool RectangleEmpty (const TBOX &rect)
 
IntGridCountCellElements ()
 
ScrollViewMakeWindow (int x, int y, const char *window_name)
 
void DisplayBoxes (ScrollView *window)
 
void AssertNoDuplicates ()
 
virtual void HandleClick (int x, int y)
 
- 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

- Static Public Member Functions inherited from tesseract::TabFind
static bool DifferentSizes (int size1, int size2)
 
static bool VeryDifferentSizes (int size1, int size2)
 
- Static Public Member Functions inherited from tesseract::AlignedBlob
static bool WithinTestRegion (int detail_level, int x, int y)
 
- Protected Member Functions inherited from tesseract::TabFind
TabVector_LIST * vectors ()
 
TabVector_LIST * dead_vectors ()
 
bool FindTabVectors (TabVector_LIST *hlines, BLOBNBOX_LIST *image_blobs, TO_BLOCK *block, int min_gutter_width, double tabfind_aligned_gap_fraction, ColPartitionGrid *part_grid, FCOORD *deskew, FCOORD *reskew)
 
void DontFindTabVectors (BLOBNBOX_LIST *image_blobs, TO_BLOCK *block, FCOORD *deskew, FCOORD *reskew)
 
void TidyBlobs (TO_BLOCK *block)
 
void SetupTabSearch (int x, int y, int *min_key, int *max_key)
 
ScrollViewDisplayTabVectors (ScrollView *tab_win)
 
ScrollViewFindInitialTabVectors (BLOBNBOX_LIST *image_blobs, int min_gutter_width, double tabfind_aligned_gap_fraction, TO_BLOCK *block)
 
void ResetForVerticalText (const FCOORD &rotate, const FCOORD &rerotate, TabVector_LIST *horizontal_lines, int *min_gutter_width)
 
void Reset ()
 
void ReflectInYAxis ()
 
- Static Protected Member Functions inherited from tesseract::TabFind
static void RotateBlobList (const FCOORD &rotation, BLOBNBOX_LIST *blobs)
 
- Protected Attributes inherited from tesseract::TabFind
ICOORD vertical_skew_
 
int resolution_
 
- Protected Attributes inherited from tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT >
BLOBNBOX_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 53 of file colfind.h.

Constructor & Destructor Documentation

◆ ColumnFinder()

tesseract::ColumnFinder::ColumnFinder ( int  gridsize,
const ICOORD bleft,
const ICOORD tright,
int  resolution,
bool  cjk_script,
double  aligned_gap_fraction,
TabVector_LIST *  vlines,
TabVector_LIST *  hlines,
int  vertical_x,
int  vertical_y 
)

Definition at line 75 of file colfind.cpp.

81  : TabFind(gridsize, bleft, tright, vlines, vertical_x, vertical_y,
82  resolution),
83  cjk_script_(cjk_script),
84  min_gutter_width_(static_cast<int>(kMinGutterWidthGrid * gridsize)),
85  mean_column_gap_(tright.x() - bleft.x()),
86  tabfind_aligned_gap_fraction_(aligned_gap_fraction),
87  deskew_(0.0f, 0.0f),
88  reskew_(1.0f, 0.0f), rotation_(1.0f, 0.0f), rerotate_(1.0f, 0.0f),
89  text_rotation_(0.0f, 0.0f),
90  best_columns_(nullptr), stroke_width_(nullptr),
91  part_grid_(gridsize, bleft, tright), nontext_map_(nullptr),
92  projection_(resolution),
93  denorm_(nullptr), input_blobs_win_(nullptr), equation_detect_(nullptr) {
94  TabVector_IT h_it(&horizontal_lines_);
95  h_it.add_list_after(hlines);
96 }
int gridsize() const
Definition: bbgrid.h:64
const ICOORD & bleft() const
Definition: bbgrid.h:73
int16_t x() const
access function
Definition: points.h:53
TabFind(int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVector_LIST *vlines, int vertical_x, int vertical_y, int resolution)
Definition: tabfind.cpp:66
const double kMinGutterWidthGrid
Definition: colfind.cpp:52
const ICOORD & tright() const
Definition: bbgrid.h:76

◆ ~ColumnFinder()

tesseract::ColumnFinder::~ColumnFinder ( )
virtual

Definition at line 98 of file colfind.cpp.

98  {
99  column_sets_.delete_data_pointers();
100  delete [] best_columns_;
101  delete stroke_width_;
102  delete input_blobs_win_;
103  pixDestroy(&nontext_map_);
104  while (denorm_ != nullptr) {
105  DENORM* dead_denorm = denorm_;
106  denorm_ = const_cast<DENORM*>(denorm_->predecessor());
107  delete dead_denorm;
108  }
109 
110  // The ColPartitions are destroyed automatically, but any boxes in
111  // the noise_parts_ list are owned and need to be deleted explicitly.
112  ColPartition_IT part_it(&noise_parts_);
113  for (part_it.mark_cycle_pt(); !part_it.cycled_list(); part_it.forward()) {
114  ColPartition* part = part_it.data();
115  part->DeleteBoxes();
116  }
117  // Likewise any boxes in the good_parts_ list need to be deleted.
118  // These are just the image parts. Text parts have already given their
119  // boxes on to the TO_BLOCK, and have empty lists.
120  part_it.set_to_list(&good_parts_);
121  for (part_it.mark_cycle_pt(); !part_it.cycled_list(); part_it.forward()) {
122  ColPartition* part = part_it.data();
123  part->DeleteBoxes();
124  }
125  // Also, any blobs on the image_bblobs_ list need to have their cblobs
126  // deleted. This only happens if there has been an early return from
127  // FindColumns, as in a normal return, the blobs go into the grid and
128  // end up in noise_parts_, good_parts_ or the output blocks.
129  BLOBNBOX_IT bb_it(&image_bblobs_);
130  for (bb_it.mark_cycle_pt(); !bb_it.cycled_list(); bb_it.forward()) {
131  BLOBNBOX* bblob = bb_it.data();
132  delete bblob->cblob();
133  }
134 }
const DENORM * predecessor() const
Definition: normalis.h:263
void delete_data_pointers()
C_BLOB * cblob() const
Definition: blobbox.h:269

Member Function Documentation

◆ CorrectOrientation()

void tesseract::ColumnFinder::CorrectOrientation ( TO_BLOCK block,
bool  vertical_text_lines,
int  recognition_rotation 
)

Definition at line 198 of file colfind.cpp.

200  {
201  const FCOORD anticlockwise90(0.0f, 1.0f);
202  const FCOORD clockwise90(0.0f, -1.0f);
203  const FCOORD rotation180(-1.0f, 0.0f);
204  const FCOORD norotation(1.0f, 0.0f);
205 
206  text_rotation_ = norotation;
207  // Rotate the page to make the text upright, as implied by
208  // recognition_rotation.
209  rotation_ = norotation;
210  if (recognition_rotation == 1) {
211  rotation_ = anticlockwise90;
212  } else if (recognition_rotation == 2) {
213  rotation_ = rotation180;
214  } else if (recognition_rotation == 3) {
215  rotation_ = clockwise90;
216  }
217  // We infer text writing direction to be vertical if there are several
218  // vertical text lines detected, and horizontal if not. But if the page
219  // orientation was determined to be 90 or 270 degrees, the true writing
220  // direction is the opposite of what we inferred.
221  if (recognition_rotation & 1) {
222  vertical_text_lines = !vertical_text_lines;
223  }
224  // If we still believe the writing direction is vertical, we use the
225  // convention of rotating the page ccw 90 degrees to make the text lines
226  // horizontal, and mark the blobs for rotation cw 90 degrees for
227  // classification so that the text order is correct after recognition.
228  if (vertical_text_lines) {
229  rotation_.rotate(anticlockwise90);
230  text_rotation_.rotate(clockwise90);
231  }
232  // Set rerotate_ to the inverse of rotation_.
233  rerotate_ = FCOORD(rotation_.x(), -rotation_.y());
234  if (rotation_.x() != 1.0f || rotation_.y() != 0.0f) {
235  // Rotate all the blobs and tab vectors.
236  RotateBlobList(rotation_, &block->large_blobs);
237  RotateBlobList(rotation_, &block->blobs);
238  RotateBlobList(rotation_, &block->small_blobs);
239  RotateBlobList(rotation_, &block->noise_blobs);
240  TabFind::ResetForVerticalText(rotation_, rerotate_, &horizontal_lines_,
241  &min_gutter_width_);
242  part_grid_.Init(gridsize(), bleft(), tright());
243  // Reset all blobs to initial state and filter by size.
244  // Since they have rotated, the list they belong on could have changed.
245  block->ReSetAndReFilterBlobs();
246  SetBlockRuleEdges(block);
247  stroke_width_->CorrectForRotation(rerotate_, &part_grid_);
248  }
249  if (textord_debug_tabfind) {
250  tprintf("Vertical=%d, orientation=%d, final rotation=(%f, %f)+(%f,%f)\n",
251  vertical_text_lines, recognition_rotation,
252  rotation_.x(), rotation_.y(),
253  text_rotation_.x(), text_rotation_.y());
254  }
255  // Setup the denormalization.
256  ASSERT_HOST(denorm_ == nullptr);
257  denorm_ = new DENORM;
258  denorm_->SetupNormalization(nullptr, &rotation_, nullptr,
259  0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f);
260 }
void ReSetAndReFilterBlobs()
Definition: blobbox.cpp:1012
void SetupNormalization(const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift)
Definition: normalis.cpp:96
int gridsize() const
Definition: bbgrid.h:64
const ICOORD & bleft() const
Definition: bbgrid.h:73
void rotate(const FCOORD vec)
Definition: points.h:764
int textord_debug_tabfind
Definition: alignedblob.cpp:28
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:447
void CorrectForRotation(const FCOORD &rerotation, ColPartitionGrid *part_grid)
Definition: points.h:189
float x() const
Definition: points.h:208
BLOBNBOX_LIST blobs
Definition: blobbox.h:785
static void RotateBlobList(const FCOORD &rotation, BLOBNBOX_LIST *blobs)
Definition: tabfind.cpp:1257
BLOBNBOX_LIST large_blobs
Definition: blobbox.h:789
void SetBlockRuleEdges(TO_BLOCK *block)
Definition: tabfind.cpp:134
const ICOORD & tright() const
Definition: bbgrid.h:76
float y() const
Definition: points.h:211
BLOBNBOX_LIST small_blobs
Definition: blobbox.h:788
void ResetForVerticalText(const FCOORD &rotate, const FCOORD &rerotate, TabVector_LIST *horizontal_lines, int *min_gutter_width)
Definition: tabfind.cpp:1301
BLOBNBOX_LIST noise_blobs
Definition: blobbox.h:787
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ denorm()

const DENORM* tesseract::ColumnFinder::denorm ( ) const
inline

Definition at line 71 of file colfind.h.

71  {
72  return denorm_;
73  }

◆ FindBlocks()

int tesseract::ColumnFinder::FindBlocks ( PageSegMode  pageseg_mode,
Pix *  scaled_color,
int  scaled_factor,
TO_BLOCK block,
Pix *  photo_mask_pix,
Pix *  thresholds_pix,
Pix *  grey_pix,
DebugPixa pixa_debug,
BLOCK_LIST *  blocks,
BLOBNBOX_LIST *  diacritic_blobs,
TO_BLOCK_LIST *  to_blocks 
)

Definition at line 286 of file colfind.cpp.

291  {
292  pixOr(photo_mask_pix, photo_mask_pix, nontext_map_);
293  stroke_width_->FindLeaderPartitions(input_block, &part_grid_);
294  stroke_width_->RemoveLineResidue(&big_parts_);
295  FindInitialTabVectors(nullptr, min_gutter_width_, tabfind_aligned_gap_fraction_,
296  input_block);
297  SetBlockRuleEdges(input_block);
298  stroke_width_->GradeBlobsIntoPartitions(
299  pageseg_mode, rerotate_, input_block, nontext_map_, denorm_, cjk_script_,
300  &projection_, diacritic_blobs, &part_grid_, &big_parts_);
301  if (!PSM_SPARSE(pageseg_mode)) {
302  ImageFind::FindImagePartitions(photo_mask_pix, rotation_, rerotate_,
303  input_block, this, pixa_debug, &part_grid_,
304  &big_parts_);
305  ImageFind::TransferImagePartsToImageMask(rerotate_, &part_grid_,
306  photo_mask_pix);
307  ImageFind::FindImagePartitions(photo_mask_pix, rotation_, rerotate_,
308  input_block, this, pixa_debug, &part_grid_,
309  &big_parts_);
310  }
311  part_grid_.ReTypeBlobs(&image_bblobs_);
312  TidyBlobs(input_block);
313  Reset();
314  // TODO(rays) need to properly handle big_parts_.
315  ColPartition_IT p_it(&big_parts_);
316  for (p_it.mark_cycle_pt(); !p_it.cycled_list(); p_it.forward())
317  p_it.data()->DisownBoxesNoAssert();
318  big_parts_.clear();
319  delete stroke_width_;
320  stroke_width_ = nullptr;
321  // Compute the edge offsets whether or not there is a grey_pix. It is done
322  // here as the c_blobs haven't been touched by rotation or anything yet,
323  // so no denorm is required, yet the text has been separated from image, so
324  // no time is wasted running it on image blobs.
325  input_block->ComputeEdgeOffsets(thresholds_pix, grey_pix);
326 
327  // A note about handling right-to-left scripts (Hebrew/Arabic):
328  // The columns must be reversed and come out in right-to-left instead of
329  // the normal left-to-right order. Because the left-to-right ordering
330  // is implicit in many data structures, it is simpler to fool the algorithms
331  // into thinking they are dealing with left-to-right text.
332  // To do this, we reflect the needed data in the y-axis and then reflect
333  // the blocks back after they have been created. This is a temporary
334  // arrangement that is confined to this function only, so the reflection
335  // is completely invisible in the output blocks.
336  // The only objects reflected are:
337  // The vertical separator lines that have already been found;
338  // The bounding boxes of all BLOBNBOXES on all lists on the input_block
339  // plus the image_bblobs. The outlines are not touched, since they are
340  // not looked at.
341  bool input_is_rtl = input_block->block->right_to_left();
342  if (input_is_rtl) {
343  // Reflect the vertical separator lines (member of TabFind).
344  ReflectInYAxis();
345  // Reflect the blob boxes.
346  ReflectForRtl(input_block, &image_bblobs_);
347  part_grid_.ReflectInYAxis();
348  }
349 
350  if (!PSM_SPARSE(pageseg_mode)) {
351  if (!PSM_COL_FIND_ENABLED(pageseg_mode)) {
352  // No tab stops needed. Just the grid that FindTabVectors makes.
353  DontFindTabVectors(&image_bblobs_, input_block, &deskew_, &reskew_);
354  } else {
355  SetBlockRuleEdges(input_block);
356  // Find the tab stops, estimate skew, and deskew the tabs, blobs and
357  // part_grid_.
358  FindTabVectors(&horizontal_lines_, &image_bblobs_, input_block,
359  min_gutter_width_, tabfind_aligned_gap_fraction_,
360  &part_grid_, &deskew_, &reskew_);
361  // Add the deskew to the denorm_.
362  DENORM* new_denorm = new DENORM;
363  new_denorm->SetupNormalization(nullptr, &deskew_, denorm_,
364  0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f);
365  denorm_ = new_denorm;
366  }
367  SetBlockRuleEdges(input_block);
368  part_grid_.SetTabStops(this);
369 
370  // Make the column_sets_.
371  if (!MakeColumns(false)) {
372  tprintf("Empty page!!\n");
373  part_grid_.DeleteParts();
374  return 0; // This is an empty page.
375  }
376 
377  // Refill the grid using rectangular spreading, and get the benefit
378  // of the completed tab vectors marking the rule edges of each blob.
379  Clear();
380  #ifndef GRAPHICS_DISABLED
382  ScrollView* rej_win = MakeWindow(500, 300, "Rejected blobs");
383  input_block->plot_graded_blobs(rej_win);
384  }
385  #endif // GRAPHICS_DISABLED
386  InsertBlobsToGrid(false, false, &image_bblobs_, this);
387  InsertBlobsToGrid(true, true, &input_block->blobs, this);
388 
389  part_grid_.GridFindMargins(best_columns_);
390  // Split and merge the partitions by looking at local neighbours.
391  GridSplitPartitions();
392  // Resolve unknown partitions by adding to an existing partition, fixing
393  // the type, or declaring them noise.
394  part_grid_.GridFindMargins(best_columns_);
395  GridMergePartitions();
396  // Insert any unused noise blobs that are close enough to an appropriate
397  // partition.
398  InsertRemainingNoise(input_block);
399  // Add horizontal line separators as partitions.
400  GridInsertHLinePartitions();
401  GridInsertVLinePartitions();
402  // Recompute margins based on a local neighbourhood search.
403  part_grid_.GridFindMargins(best_columns_);
404  SetPartitionTypes();
405  }
407  ScrollView* part_win = MakeWindow(100, 300, "InitialPartitions");
408  part_grid_.DisplayBoxes(part_win);
409  DisplayTabVectors(part_win);
410  }
411 
412  if (!PSM_SPARSE(pageseg_mode)) {
413  if (equation_detect_) {
414  equation_detect_->FindEquationParts(&part_grid_, best_columns_);
415  }
417  TableFinder table_finder;
418  table_finder.Init(gridsize(), bleft(), tright());
419  table_finder.set_resolution(resolution_);
420  table_finder.set_left_to_right_language(
421  !input_block->block->right_to_left());
422  // Copy cleaned partitions from part_grid_ to clean_part_grid_ and
423  // insert dot-like noise into period_grid_
424  table_finder.InsertCleanPartitions(&part_grid_, input_block);
425  // Get Table Regions
426  table_finder.LocateTables(&part_grid_, best_columns_, WidthCB(), reskew_);
427  }
428  GridRemoveUnderlinePartitions();
429  part_grid_.DeleteUnknownParts(input_block);
430 
431  // Build the partitions into chains that belong in the same block and
432  // refine into one-to-one links, then smooth the types within each chain.
433  part_grid_.FindPartitionPartners();
434  part_grid_.FindFigureCaptions();
435  part_grid_.RefinePartitionPartners(true);
436  SmoothPartnerRuns();
437 
438  #ifndef GRAPHICS_DISABLED
440  ScrollView* window = MakeWindow(400, 300, "Partitions");
441  if (window != nullptr) {
442  part_grid_.DisplayBoxes(window);
444  DisplayTabVectors(window);
445  if (window != nullptr && textord_tabfind_show_partitions > 1) {
446  delete window->AwaitEvent(SVET_DESTROY);
447  }
448  }
449  }
450  #endif // GRAPHICS_DISABLED
451  part_grid_.AssertNoDuplicates();
452  }
453  // Ownership of the ColPartitions moves from part_sets_ to part_grid_ here,
454  // and ownership of the BLOBNBOXes moves to the ColPartitions.
455  // (They were previously owned by the block or the image_bblobs list.)
456  ReleaseBlobsAndCleanupUnused(input_block);
457  // Ownership of the ColPartitions moves from part_grid_ to good_parts_ and
458  // noise_parts_ here. In text blocks, ownership of the BLOBNBOXes moves
459  // from the ColPartitions to the output TO_BLOCK. In non-text, the
460  // BLOBNBOXes stay with the ColPartitions and get deleted in the destructor.
461  if (PSM_SPARSE(pageseg_mode))
462  part_grid_.ExtractPartitionsAsBlocks(blocks, to_blocks);
463  else
464  TransformToBlocks(blocks, to_blocks);
465  if (textord_debug_tabfind) {
466  tprintf("Found %d blocks, %d to_blocks\n",
467  blocks->length(), to_blocks->length());
468  }
469 
470  DisplayBlocks(blocks);
471  RotateAndReskewBlocks(input_is_rtl, to_blocks);
472  int result = 0;
473  #ifndef GRAPHICS_DISABLED
474  if (blocks_win_ != nullptr) {
475  bool waiting = false;
476  do {
477  waiting = false;
478  SVEvent* event = blocks_win_->AwaitEvent(SVET_ANY);
479  if (event->type == SVET_INPUT && event->parameter != nullptr) {
480  if (*event->parameter == 'd')
481  result = -1;
482  else
483  blocks->clear();
484  } else if (event->type == SVET_DESTROY) {
485  blocks_win_ = nullptr;
486  } else {
487  waiting = true;
488  }
489  delete event;
490  } while (waiting);
491  }
492  #endif // GRAPHICS_DISABLED
493  return result;
494 }
void ReTypeBlobs(BLOBNBOX_LIST *im_blobs)
void AssertNoDuplicates()
Definition: bbgrid.h:640
static void FindImagePartitions(Pix *image_pix, const FCOORD &rotation, const FCOORD &rerotation, TO_BLOCK *block, TabFind *tab_grid, DebugPixa *pixa_debug, ColPartitionGrid *part_grid, ColPartition_LIST *big_parts)
Definition: imagefind.cpp:1299
static void TransferImagePartsToImageMask(const FCOORD &rerotation, ColPartitionGrid *part_grid, Pix *image_mask)
Definition: imagefind.cpp:1246
bool textord_tabfind_find_tables
Definition: colfind.cpp:65
void SetupNormalization(const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift)
Definition: normalis.cpp:96
ScrollView * MakeWindow(int x, int y, const char *window_name)
Definition: bbgrid.h:591
void DeleteUnknownParts(TO_BLOCK *block)
void GridFindMargins(ColPartitionSet **best_columns)
bool PSM_SPARSE(int pageseg_mode)
Definition: publictypes.h:200
int gridsize() const
Definition: bbgrid.h:64
bool FindTabVectors(TabVector_LIST *hlines, BLOBNBOX_LIST *image_blobs, TO_BLOCK *block, int min_gutter_width, double tabfind_aligned_gap_fraction, ColPartitionGrid *part_grid, FCOORD *deskew, FCOORD *reskew)
Definition: tabfind.cpp:423
const ICOORD & bleft() const
Definition: bbgrid.h:73
void TidyBlobs(TO_BLOCK *block)
Definition: tabfind.cpp:466
ScrollView * DisplayTabVectors(ScrollView *tab_win)
Definition: tabfind.cpp:498
void RemoveLineResidue(ColPartition_LIST *big_part_list)
void SetTabStops(TabFind *tabgrid)
bool textord_tabfind_show_reject_blobs
Definition: colfind.cpp:60
bool PSM_COL_FIND_ENABLED(int pageseg_mode)
Definition: publictypes.h:197
bool textord_tabfind_show_initial_partitions
Definition: colfind.cpp:58
bool textord_debug_printable
Definition: alignedblob.cpp:34
void FindLeaderPartitions(TO_BLOCK *block, ColPartitionGrid *part_grid)
int textord_tabfind_show_partitions
Definition: colfind.cpp:62
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:445
int textord_debug_tabfind
Definition: alignedblob.cpp:28
virtual int FindEquationParts(ColPartitionGrid *part_grid, ColPartitionSet **best_columns)=0
WidthCallback * WidthCB()
Definition: tabfind.h:158
ScrollView * FindInitialTabVectors(BLOBNBOX_LIST *image_blobs, int min_gutter_width, double tabfind_aligned_gap_fraction, TO_BLOCK *block)
Definition: tabfind.cpp:515
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
void GradeBlobsIntoPartitions(PageSegMode pageseg_mode, const FCOORD &rerotation, TO_BLOCK *block, Pix *nontext_pix, const DENORM *denorm, bool cjk_script, TextlineProjection *projection, BLOBNBOX_LIST *diacritic_blobs, ColPartitionGrid *part_grid, ColPartition_LIST *big_parts)
void DontFindTabVectors(BLOBNBOX_LIST *image_blobs, TO_BLOCK *block, FCOORD *deskew, FCOORD *reskew)
Definition: tabfind.cpp:453
void InsertBlobsToGrid(bool h_spread, bool v_spread, BLOBNBOX_LIST *blobs, BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > *grid)
Definition: tabfind.cpp:92
void RefinePartitionPartners(bool get_desperate)
void ExtractPartitionsAsBlocks(BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
void DisplayBoxes(ScrollView *window)
Definition: bbgrid.h:615
void SetBlockRuleEdges(TO_BLOCK *block)
Definition: tabfind.cpp:134
const ICOORD & tright() const
Definition: bbgrid.h:76

◆ GetDeskewVectors()

void tesseract::ColumnFinder::GetDeskewVectors ( FCOORD deskew,
FCOORD reskew 
)

Definition at line 497 of file colfind.cpp.

497  {
498  *reskew = reskew_;
499  *deskew = reskew_;
500  deskew->set_y(-deskew->y());
501 }
void set_y(float yin)
rewrite function
Definition: points.h:219
float y() const
Definition: points.h:211

◆ IsVerticallyAlignedText()

bool tesseract::ColumnFinder::IsVerticallyAlignedText ( double  find_vertical_text_ratio,
TO_BLOCK block,
BLOBNBOX_CLIST *  osd_blobs 
)

Definition at line 180 of file colfind.cpp.

182  {
183  return stroke_width_->TestVerticalTextDirection(find_vertical_text_ratio,
184  block, osd_blobs);
185 }
bool TestVerticalTextDirection(double find_vertical_text_ratio, TO_BLOCK *block, BLOBNBOX_CLIST *osd_blobs)

◆ projection()

const TextlineProjection* tesseract::ColumnFinder::projection ( ) const
inline

Definition at line 74 of file colfind.h.

74  {
75  return &projection_;
76  }

◆ set_cjk_script()

void tesseract::ColumnFinder::set_cjk_script ( bool  is_cjk)
inline

Definition at line 77 of file colfind.h.

77  {
78  cjk_script_ = is_cjk;
79  }

◆ SetEquationDetect()

void tesseract::ColumnFinder::SetEquationDetect ( EquationDetectBase detect)

Definition at line 503 of file colfind.cpp.

503  {
504  equation_detect_ = detect;
505 }

◆ SetupAndFilterNoise()

void tesseract::ColumnFinder::SetupAndFilterNoise ( PageSegMode  pageseg_mode,
Pix *  photo_mask_pix,
TO_BLOCK input_block 
)

Definition at line 143 of file colfind.cpp.

145  {
146  part_grid_.Init(gridsize(), bleft(), tright());
147  delete stroke_width_;
148  stroke_width_ = new StrokeWidth(gridsize(), bleft(), tright());
149  min_gutter_width_ = static_cast<int>(kMinGutterWidthGrid * gridsize());
150  input_block->ReSetAndReFilterBlobs();
151  #ifndef GRAPHICS_DISABLED
153  input_blobs_win_ = MakeWindow(0, 0, "Filtered Input Blobs");
154  input_block->plot_graded_blobs(input_blobs_win_);
155  }
156  #endif // GRAPHICS_DISABLED
157  SetBlockRuleEdges(input_block);
158  pixDestroy(&nontext_map_);
159  // Run a preliminary strokewidth neighbour detection on the medium blobs.
160  stroke_width_->SetNeighboursOnMediumBlobs(input_block);
161  CCNonTextDetect nontext_detect(gridsize(), bleft(), tright());
162  // Remove obvious noise and make the initial non-text map.
163  nontext_map_ = nontext_detect.ComputeNonTextMask(textord_debug_tabfind,
164  photo_mask_pix, input_block);
165  stroke_width_->FindTextlineDirectionAndFixBrokenCJK(pageseg_mode, cjk_script_,
166  input_block);
167  // Clear the strokewidth grid ready for rotation or leader finding.
168  stroke_width_->Clear();
169 }
void ReSetAndReFilterBlobs()
Definition: blobbox.cpp:1012
ScrollView * MakeWindow(int x, int y, const char *window_name)
Definition: bbgrid.h:591
void SetNeighboursOnMediumBlobs(TO_BLOCK *block)
int gridsize() const
Definition: bbgrid.h:64
const ICOORD & bleft() const
Definition: bbgrid.h:73
bool textord_tabfind_show_blocks
Definition: colfind.cpp:64
void Clear()
Definition: bbgrid.h:457
void plot_graded_blobs(ScrollView *to_win)
Definition: blobbox.cpp:1072
int textord_debug_tabfind
Definition: alignedblob.cpp:28
void FindTextlineDirectionAndFixBrokenCJK(PageSegMode pageseg_mode, bool cjk_merge, TO_BLOCK *input_block)
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:447
const double kMinGutterWidthGrid
Definition: colfind.cpp:52
void SetBlockRuleEdges(TO_BLOCK *block)
Definition: tabfind.cpp:134
const ICOORD & tright() const
Definition: bbgrid.h:76

The documentation for this class was generated from the following files: