All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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

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

90  : TabFind(gridsize, bleft, tright, vlines, vertical_x, vertical_y,
91  resolution),
92  cjk_script_(cjk_script),
93  min_gutter_width_(static_cast<int>(kMinGutterWidthGrid * gridsize)),
94  mean_column_gap_(tright.x() - bleft.x()),
95  tabfind_aligned_gap_fraction_(aligned_gap_fraction),
96  reskew_(1.0f, 0.0f), rotation_(1.0f, 0.0f), rerotate_(1.0f, 0.0f),
97  best_columns_(NULL), stroke_width_(NULL),
98  part_grid_(gridsize, bleft, tright), nontext_map_(NULL),
99  projection_(resolution),
100  denorm_(NULL), input_blobs_win_(NULL), equation_detect_(NULL) {
101  TabVector_IT h_it(&horizontal_lines_);
102  h_it.add_list_after(hlines);
103 }
int gridsize() const
Definition: bbgrid.h:63
TabFind(int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVector_LIST *vlines, int vertical_x, int vertical_y, int resolution)
Definition: tabfind.cpp:86
inT16 x() const
access function
Definition: points.h:52
const double kMinGutterWidthGrid
Definition: colfind.cpp:61
#define NULL
Definition: host.h:144
tesseract::ColumnFinder::~ColumnFinder ( )
virtual

Definition at line 105 of file colfind.cpp.

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

Member Function Documentation

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

Definition at line 209 of file colfind.cpp.

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

Definition at line 70 of file colfind.h.

70  {
71  return denorm_;
72  }
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 297 of file colfind.cpp.

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

Definition at line 509 of file colfind.cpp.

509  {
510  *reskew = reskew_;
511  *deskew = reskew_;
512  deskew->set_y(-deskew->y());
513 }
void set_y(float yin)
rewrite function
Definition: points.h:220
float y() const
Definition: points.h:212
bool tesseract::ColumnFinder::IsVerticallyAlignedText ( double  find_vertical_text_ratio,
TO_BLOCK block,
BLOBNBOX_CLIST *  osd_blobs 
)

Definition at line 191 of file colfind.cpp.

193  {
194  return stroke_width_->TestVerticalTextDirection(find_vertical_text_ratio,
195  block, osd_blobs);
196 }
bool TestVerticalTextDirection(double find_vertical_text_ratio, TO_BLOCK *block, BLOBNBOX_CLIST *osd_blobs)
const TextlineProjection* tesseract::ColumnFinder::projection ( ) const
inline

Definition at line 73 of file colfind.h.

73  {
74  return &projection_;
75  }
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  }
void tesseract::ColumnFinder::SetEquationDetect ( EquationDetectBase detect)

Definition at line 515 of file colfind.cpp.

515  {
516  equation_detect_ = detect;
517 }
void tesseract::ColumnFinder::SetupAndFilterNoise ( PageSegMode  pageseg_mode,
Pix *  photo_mask_pix,
TO_BLOCK input_block 
)

Definition at line 153 of file colfind.cpp.

155  {
156  part_grid_.Init(gridsize(), bleft(), tright());
157  if (stroke_width_ != NULL)
158  delete stroke_width_;
159  stroke_width_ = new StrokeWidth(gridsize(), bleft(), tright());
160  min_gutter_width_ = static_cast<int>(kMinGutterWidthGrid * gridsize());
161  input_block->ReSetAndReFilterBlobs();
162  #ifndef GRAPHICS_DISABLED
164  input_blobs_win_ = MakeWindow(0, 0, "Filtered Input Blobs");
165  input_block->plot_graded_blobs(input_blobs_win_);
166  }
167  #endif // GRAPHICS_DISABLED
168  SetBlockRuleEdges(input_block);
169  pixDestroy(&nontext_map_);
170  // Run a preliminary strokewidth neighbour detection on the medium blobs.
171  stroke_width_->SetNeighboursOnMediumBlobs(input_block);
172  CCNonTextDetect nontext_detect(gridsize(), bleft(), tright());
173  // Remove obvious noise and make the initial non-text map.
174  nontext_map_ = nontext_detect.ComputeNonTextMask(textord_debug_tabfind,
175  photo_mask_pix, input_block);
176  stroke_width_->FindTextlineDirectionAndFixBrokenCJK(pageseg_mode, cjk_script_,
177  input_block);
178  // Clear the strokewidth grid ready for rotation or leader finding.
179  stroke_width_->Clear();
180 }
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:447
void SetNeighboursOnMediumBlobs(TO_BLOCK *block)
void ReSetAndReFilterBlobs()
Definition: blobbox.cpp:1005
void Clear()
Definition: bbgrid.h:458
void FindTextlineDirectionAndFixBrokenCJK(PageSegMode pageseg_mode, bool cjk_merge, TO_BLOCK *input_block)
int textord_debug_tabfind
Definition: alignedblob.cpp:27
int gridsize() const
Definition: bbgrid.h:63
const ICOORD & bleft() const
Definition: bbgrid.h:72
void plot_graded_blobs(ScrollView *to_win)
Definition: blobbox.cpp:1065
ScrollView * MakeWindow(int x, int y, const char *window_name)
bool textord_tabfind_show_blocks
Definition: colfind.cpp:73
void SetBlockRuleEdges(TO_BLOCK *block)
Definition: tabfind.cpp:155
const double kMinGutterWidthGrid
Definition: colfind.cpp:61
const ICOORD & tright() const
Definition: bbgrid.h:75
#define NULL
Definition: host.h:144

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