tesseract  4.00.00dev
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 ()
 
 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 77 of file colfind.cpp.

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

◆ ~ColumnFinder()

tesseract::ColumnFinder::~ColumnFinder ( )
virtual

Definition at line 98 of file colfind.cpp.

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

Member Function Documentation

◆ CorrectOrientation()

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

Definition at line 202 of file colfind.cpp.

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

◆ 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 290 of file colfind.cpp.

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

◆ GetDeskewVectors()

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

Definition at line 501 of file colfind.cpp.

501  {
502  *reskew = reskew_;
503  *deskew = reskew_;
504  deskew->set_y(-deskew->y());
505 }
void set_y(float yin)
rewrite function
Definition: points.h:220
float y() const
Definition: points.h:212

◆ IsVerticallyAlignedText()

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

Definition at line 184 of file colfind.cpp.

186  {
187  return stroke_width_->TestVerticalTextDirection(find_vertical_text_ratio,
188  block, osd_blobs);
189 }
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 507 of file colfind.cpp.

507  {
508  equation_detect_ = detect;
509 }

◆ SetupAndFilterNoise()

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

Definition at line 146 of file colfind.cpp.

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

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