tesseract  3.05.02
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, 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)
 
static void IncrementDebugPix ()
 
static const STRINGtextord_debug_pix ()
 
- 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 52 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 }
const ICOORD & tright() const
Definition: bbgrid.h:75
const double kMinGutterWidthGrid
Definition: colfind.cpp:54
inT16 x() const
access function
Definition: points.h:52
int gridsize() const
Definition: bbgrid.h:63
const ICOORD & bleft() const
Definition: bbgrid.h:72
TabFind(int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVector_LIST *vlines, int vertical_x, int vertical_y, int resolution)
Definition: tabfind.cpp:65

◆ ~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 }
C_BLOB * cblob() const
Definition: blobbox.h:253
const DENORM * predecessor() const
Definition: normalis.h:265
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 }
void SetBlockRuleEdges(TO_BLOCK *block)
Definition: tabfind.cpp:134
const ICOORD & tright() const
Definition: bbgrid.h:75
void ResetForVerticalText(const FCOORD &rotate, const FCOORD &rerotate, TabVector_LIST *horizontal_lines, int *min_gutter_width)
Definition: tabfind.cpp:1332
BLOBNBOX_LIST blobs
Definition: blobbox.h:768
void ReSetAndReFilterBlobs()
Definition: blobbox.cpp:1007
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
void rotate(const FCOORD vec)
Definition: ipoints.h:471
BLOBNBOX_LIST noise_blobs
Definition: blobbox.h:770
BLOBNBOX_LIST large_blobs
Definition: blobbox.h:772
float y() const
Definition: points.h:212
int textord_debug_tabfind
Definition: alignedblob.cpp:27
int gridsize() const
Definition: bbgrid.h:63
#define tprintf(...)
Definition: tprintf.h:31
Definition: points.h:189
void CorrectForRotation(const FCOORD &rerotation, ColPartitionGrid *part_grid)
BLOBNBOX_LIST small_blobs
Definition: blobbox.h:771
const ICOORD & bleft() const
Definition: bbgrid.h:72
float x() const
Definition: points.h:209
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:447
static void RotateBlobList(const FCOORD &rotation, BLOBNBOX_LIST *blobs)
Definition: tabfind.cpp:1262
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ denorm()

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

Definition at line 70 of file colfind.h.

70  {
71  return denorm_;
72  }

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

◆ GetDeskewVectors()

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

Definition at line 502 of file colfind.cpp.

502  {
503  *reskew = reskew_;
504  *deskew = reskew_;
505  deskew->set_y(-deskew->y());
506 }
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 73 of file colfind.h.

73  {
74  return &projection_;
75  }

◆ set_cjk_script()

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

Definition at line 76 of file colfind.h.

76  {
77  cjk_script_ = is_cjk;
78  }

◆ SetEquationDetect()

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

Definition at line 508 of file colfind.cpp.

508  {
509  equation_detect_ = detect;
510 }

◆ 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 SetBlockRuleEdges(TO_BLOCK *block)
Definition: tabfind.cpp:134
bool textord_tabfind_show_blocks
Definition: colfind.cpp:66
const ICOORD & tright() const
Definition: bbgrid.h:75
void ReSetAndReFilterBlobs()
Definition: blobbox.cpp:1007
const double kMinGutterWidthGrid
Definition: colfind.cpp:54
void SetNeighboursOnMediumBlobs(TO_BLOCK *block)
ScrollView * MakeWindow(int x, int y, const char *window_name)
Definition: bbgrid.h:592
void FindTextlineDirectionAndFixBrokenCJK(PageSegMode pageseg_mode, bool cjk_merge, TO_BLOCK *input_block)
void Clear()
Definition: bbgrid.h:458
int textord_debug_tabfind
Definition: alignedblob.cpp:27
int gridsize() const
Definition: bbgrid.h:63
void plot_graded_blobs(ScrollView *to_win)
Definition: blobbox.cpp:1067
const ICOORD & bleft() const
Definition: bbgrid.h:72
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:447

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