Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::StrokeWidth Class Reference

#include <strokewidth.h>

Inheritance diagram for tesseract::StrokeWidth:
tesseract::BlobGrid tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > tesseract::GridBase

Public Member Functions

 StrokeWidth (int gridsize, const ICOORD &bleft, const ICOORD &tright)
 
virtual ~StrokeWidth ()
 
void SetNeighboursOnMediumBlobs (TO_BLOCK *block)
 
void FindTextlineDirectionAndFixBrokenCJK (bool cjk_merge, TO_BLOCK *input_block)
 
bool TestVerticalTextDirection (TO_BLOCK *block, BLOBNBOX_CLIST *osd_blobs)
 
void CorrectForRotation (const FCOORD &rerotation, ColPartitionGrid *part_grid)
 
void FindLeaderPartitions (TO_BLOCK *block, ColPartitionGrid *part_grid)
 
void RemoveLineResidue (ColPartition_LIST *big_part_list)
 
void GradeBlobsIntoPartitions (const FCOORD &rerotation, TO_BLOCK *block, Pix *nontext_pix, const DENORM *denorm, TextlineProjection *projection, ColPartitionGrid *part_grid, ColPartition_LIST *big_parts)
 
virtual void HandleClick (int x, int 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 ()
 
- 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

- 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

The StrokeWidth class holds all the normal and large blobs. It is used to find good large blobs and move them to the normal blobs by virtue of having a reasonable strokewidth compatible neighbour.

Definition at line 49 of file strokewidth.h.

Constructor & Destructor Documentation

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

Definition at line 121 of file strokewidth.cpp.

123  : BlobGrid(gridsize, bleft, tright), nontext_map_(NULL), projection_(NULL),
124  denorm_(NULL), grid_box_(bleft, tright), rerotation_(1.0f, 0.0f) {
125  leaders_win_ = NULL;
126  widths_win_ = NULL;
127  initial_widths_win_ = NULL;
128  chains_win_ = NULL;
129  diacritics_win_ = NULL;
130  textlines_win_ = NULL;
131  smoothed_win_ = NULL;
132 }
BlobGrid(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: blobgrid.cpp:24
int gridsize() const
Definition: bbgrid.h:68
#define NULL
Definition: host.h:144
#define f(xc, yc)
Definition: imgscale.cpp:39
tesseract::StrokeWidth::~StrokeWidth ( )
virtual

Definition at line 134 of file strokewidth.cpp.

134  {
135  if (widths_win_ != NULL) {
136  #ifndef GRAPHICS_DISABLED
137  delete widths_win_->AwaitEvent(SVET_DESTROY);
138  #endif // GRAPHICS_DISABLED
140  exit(0);
141  delete widths_win_;
142  }
143  delete leaders_win_;
144  delete initial_widths_win_;
145  delete chains_win_;
146  delete textlines_win_;
147  delete smoothed_win_;
148  delete diacritics_win_;
149 }
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:444
#define NULL
Definition: host.h:144
bool textord_tabfind_only_strokewidths
Definition: strokewidth.cpp:46

Member Function Documentation

void tesseract::StrokeWidth::CorrectForRotation ( const FCOORD rerotation,
ColPartitionGrid part_grid 
)

Definition at line 263 of file strokewidth.cpp.

264  {
265  Init(part_grid->gridsize(), part_grid->bleft(), part_grid->tright());
266  grid_box_ = TBOX(bleft(), tright());
267  rerotation_.set_x(rotation.x());
268  rerotation_.set_y(-rotation.y());
269 }
void set_x(float xin)
rewrite function
Definition: points.h:216
Definition: rect.h:29
const ICOORD & tright() const
Definition: bbgrid.h:80
void set_y(float yin)
rewrite function
Definition: points.h:220
const ICOORD & bleft() const
Definition: bbgrid.h:77
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
void tesseract::StrokeWidth::FindLeaderPartitions ( TO_BLOCK block,
ColPartitionGrid part_grid 
)

Definition at line 272 of file strokewidth.cpp.

273  {
274  Clear();
275  // Find and isolate leaders in the noise list.
276  ColPartition_LIST leader_parts;
277  FindLeadersAndMarkNoise(block, &leader_parts);
278  // Setup the strokewidth grid with the block's remaining (non-noise) blobs.
279  InsertBlobList(&block->blobs);
280  // Mark blobs that have leader neighbours.
281  for (ColPartition_IT it(&leader_parts); !it.empty(); it.forward()) {
282  ColPartition* part = it.extract();
283  part->ClaimBoxes();
284  MarkLeaderNeighbours(part, LR_LEFT);
285  MarkLeaderNeighbours(part, LR_RIGHT);
286  part_grid->InsertBBox(true, true, part);
287  }
288 }
BLOBNBOX_LIST blobs
Definition: blobbox.h:735
void InsertBlobList(BLOBNBOX_LIST *blobs)
Definition: blobgrid.cpp:34
void tesseract::StrokeWidth::FindTextlineDirectionAndFixBrokenCJK ( bool  cjk_merge,
TO_BLOCK input_block 
)

Definition at line 168 of file strokewidth.cpp.

169  {
170  // Setup the grid with the remaining (non-noise) blobs.
171  InsertBlobs(input_block);
172  // Repair broken CJK characters if needed.
173  while (cjk_merge && FixBrokenCJK(input_block));
174  // Grade blobs by inspection of neighbours.
175  FindTextlineFlowDirection(false);
176  // Clear the grid ready for rotation or leader finding.
177  Clear();
178 }
void tesseract::StrokeWidth::GradeBlobsIntoPartitions ( const FCOORD rerotation,
TO_BLOCK block,
Pix *  nontext_pix,
const DENORM denorm,
TextlineProjection projection,
ColPartitionGrid part_grid,
ColPartition_LIST *  big_parts 
)

Definition at line 356 of file strokewidth.cpp.

362  {
363  nontext_map_ = nontext_pix;
364  projection_ = projection;
365  denorm_ = denorm;
366  // Clear and re Insert to take advantage of the tab stops in the blobs.
367  Clear();
368  // Setup the strokewidth grid with the remaining non-noise, non-leader blobs.
369  InsertBlobs(block);
370 
371  // Run FixBrokenCJK() again if the page is rotated and the blobs
372  // lists are reset and re-flitered, because we may have some new
373  // blobs in the medium blob list.
374  if (rerotation_.x() != 1.0f || rerotation_.y() != 0.0f) {
375  FixBrokenCJK(block);
376  }
377  FindTextlineFlowDirection(true);
378  projection_->ConstructProjection(block, rerotation, nontext_map_);
380  ScrollView* line_blobs_win = MakeWindow(0, 0, "Initial textline Blobs");
381  projection_->PlotGradedBlobs(&block->blobs, line_blobs_win);
382  projection_->PlotGradedBlobs(&block->small_blobs, line_blobs_win);
383  }
384  projection_->MoveNonTextlineBlobs(&block->blobs, &block->noise_blobs);
385  projection_->MoveNonTextlineBlobs(&block->small_blobs, &block->noise_blobs);
386  // Clear and re Insert to take advantage of the removed diacritics.
387  Clear();
388  InsertBlobs(block);
389  FindInitialPartitions(rerotation, block, part_grid, big_parts);
390  nontext_map_ = NULL;
391  projection_ = NULL;
392  denorm_ = NULL;
393 }
BLOBNBOX_LIST noise_blobs
Definition: blobbox.h:737
BLOBNBOX_LIST blobs
Definition: blobbox.h:735
#define NULL
Definition: host.h:144
void ConstructProjection(TO_BLOCK *input_block, const FCOORD &rotation, Pix *nontext_map)
void MoveNonTextlineBlobs(BLOBNBOX_LIST *blobs, BLOBNBOX_LIST *small_blobs) const
int textord_tabfind_show_strokewidths
Definition: strokewidth.cpp:45
BLOBNBOX_LIST small_blobs
Definition: blobbox.h:738
void PlotGradedBlobs(BLOBNBOX_LIST *blobs, ScrollView *win)
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
ScrollView * MakeWindow(int x, int y, const char *window_name)
void tesseract::StrokeWidth::HandleClick ( int  x,
int  y 
)
virtual

Handles a click event in a display window.

Reimplemented from tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT >.

Definition at line 404 of file strokewidth.cpp.

404  {
406  // Run a radial search for blobs that overlap.
407  BlobGridSearch radsearch(this);
408  radsearch.StartRadSearch(x, y, 1);
409  BLOBNBOX* neighbour;
410  FCOORD click(static_cast<float>(x), static_cast<float>(y));
411  while ((neighbour = radsearch.NextRadSearch()) != NULL) {
412  TBOX nbox = neighbour->bounding_box();
413  if (nbox.contains(click) && neighbour->cblob() != NULL) {
414  PrintBoxWidths(neighbour);
415  if (neighbour->neighbour(BND_LEFT) != NULL)
416  PrintBoxWidths(neighbour->neighbour(BND_LEFT));
417  if (neighbour->neighbour(BND_RIGHT) != NULL)
418  PrintBoxWidths(neighbour->neighbour(BND_RIGHT));
419  if (neighbour->neighbour(BND_ABOVE) != NULL)
420  PrintBoxWidths(neighbour->neighbour(BND_ABOVE));
421  if (neighbour->neighbour(BND_BELOW) != NULL)
422  PrintBoxWidths(neighbour->neighbour(BND_BELOW));
423  int gaps[BND_COUNT];
424  neighbour->NeighbourGaps(gaps);
425  tprintf("Left gap=%d, right=%d, above=%d, below=%d, horz=%d, vert=%d\n"
426  "Good= %d %d %d %d\n",
427  gaps[BND_LEFT], gaps[BND_RIGHT],
428  gaps[BND_ABOVE], gaps[BND_BELOW],
429  neighbour->horz_possible(),
430  neighbour->vert_possible(),
431  neighbour->good_stroke_neighbour(BND_LEFT),
432  neighbour->good_stroke_neighbour(BND_RIGHT),
433  neighbour->good_stroke_neighbour(BND_ABOVE),
434  neighbour->good_stroke_neighbour(BND_BELOW));
435  break;
436  }
437  }
438 }
C_BLOB * cblob() const
Definition: blobbox.h:245
const TBOX & bounding_box() const
Definition: blobbox.h:208
bool contains(const FCOORD pt) const
Definition: rect.h:323
void NeighbourGaps(int gaps[BND_COUNT]) const
Definition: blobbox.cpp:172
#define NULL
Definition: host.h:144
GridSearch< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > BlobGridSearch
Definition: blobgrid.h:31
Definition: rect.h:29
virtual void HandleClick(int x, int y)
Definition: bbgrid.h:655
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
Definition: points.h:189
bool good_stroke_neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:350
bool horz_possible() const
Definition: blobbox.h:284
BLOBNBOX * neighbour(BlobNeighbourDir n) const
Definition: blobbox.h:347
bool vert_possible() const
Definition: blobbox.h:278
void tesseract::StrokeWidth::RemoveLineResidue ( ColPartition_LIST *  big_part_list)

Definition at line 292 of file strokewidth.cpp.

292  {
293  BlobGridSearch gsearch(this);
294  BLOBNBOX* bbox;
295  // For every vertical line-like bbox in the grid, search its neighbours
296  // to find the tallest, and if the original box is taller by sufficient
297  // margin, then call it line residue and delete it.
298  gsearch.StartFullSearch();
299  while ((bbox = gsearch.NextFullSearch()) != NULL) {
300  TBOX box = bbox->bounding_box();
301  if (box.height() < box.width() * kLineResidueAspectRatio)
302  continue;
303  // Set up a rectangle search around the blob to find the size of its
304  // neighbours.
305  int padding = box.height() * kLineResiduePadRatio;
306  TBOX search_box = box;
307  search_box.pad(padding, padding);
308  bool debug = AlignedBlob::WithinTestRegion(2, box.left(),
309  box.bottom());
310  // Find the largest object in the search box not equal to bbox.
311  BlobGridSearch rsearch(this);
312  int max_size = 0;
313  BLOBNBOX* n;
314  rsearch.StartRectSearch(search_box);
315  while ((n = rsearch.NextRectSearch()) != NULL) {
316  if (n == bbox) continue;
317  TBOX nbox = n->bounding_box();
318  if (nbox.height() > max_size) {
319  max_size = nbox.height();
320  }
321  }
322  if (debug) {
323  tprintf("Max neighbour size=%d for candidate line box at:", max_size);
324  box.print();
325  }
326  if (max_size * kLineResidueSizeRatio < box.height()) {
327  #ifndef GRAPHICS_DISABLED
328  if (leaders_win_ != NULL) {
329  // We are debugging, so display deleted in pink blobs in the same
330  // window that we use to display leader detection.
331  leaders_win_->Pen(ScrollView::PINK);
332  leaders_win_->Rectangle(box.left(), box.bottom(),
333  box.right(), box.top());
334  }
335  #endif // GRAPHICS_DISABLED
336  ColPartition::MakeBigPartition(bbox, big_part_list);
337  }
338  }
339 }
const int kLineResiduePadRatio
const double kLineResidueSizeRatio
const double kLineResidueAspectRatio
void Pen(Color color)
Definition: scrollview.cpp:721
const TBOX & bounding_box() const
Definition: blobbox.h:208
static ColPartition * MakeBigPartition(BLOBNBOX *box, ColPartition_LIST *big_part_list)
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
GridSearch< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > BlobGridSearch
Definition: blobgrid.h:31
inT16 width() const
Definition: rect.h:104
Definition: rect.h:29
inT16 right() const
Definition: rect.h:74
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:601
inT16 top() const
Definition: rect.h:53
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void pad(int xpad, int ypad)
Definition: rect.h:120
static bool WithinTestRegion(int detail_level, int x, int y)
void print() const
Definition: rect.h:263
inT16 height() const
Definition: rect.h:97
inT16 bottom() const
Definition: rect.h:60
void tesseract::StrokeWidth::SetNeighboursOnMediumBlobs ( TO_BLOCK block)

Definition at line 154 of file strokewidth.cpp.

154  {
155  // Run a preliminary strokewidth neighbour detection on the medium blobs.
156  InsertBlobList(&block->blobs);
157  BLOBNBOX_IT blob_it(&block->blobs);
158  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
159  SetNeighbours(false, false, blob_it.data());
160  }
161  Clear();
162 }
BLOBNBOX_LIST blobs
Definition: blobbox.h:735
void InsertBlobList(BLOBNBOX_LIST *blobs)
Definition: blobgrid.cpp:34
bool tesseract::StrokeWidth::TestVerticalTextDirection ( TO_BLOCK block,
BLOBNBOX_CLIST *  osd_blobs 
)

Definition at line 219 of file strokewidth.cpp.

220  {
221  if (textord_tabfind_force_vertical_text) return true;
222  if (!textord_tabfind_vertical_text) return false;
223 
224  int vertical_boxes = 0;
225  int horizontal_boxes = 0;
226  // Count vertical normal and large blobs.
227  BLOBNBOX_CLIST vertical_blobs;
228  BLOBNBOX_CLIST horizontal_blobs;
229  BLOBNBOX_CLIST nondescript_blobs;
230  CollectHorizVertBlobs(&block->blobs, &vertical_boxes, &horizontal_boxes,
231  &vertical_blobs, &horizontal_blobs, &nondescript_blobs);
232  CollectHorizVertBlobs(&block->large_blobs, &vertical_boxes, &horizontal_boxes,
233  &vertical_blobs, &horizontal_blobs, &nondescript_blobs);
235  tprintf("TextDir hbox=%d vs vbox=%d, %dH, %dV, %dN osd blobs\n",
236  horizontal_boxes, vertical_boxes,
237  horizontal_blobs.length(), vertical_blobs.length(),
238  nondescript_blobs.length());
239  if (osd_blobs != NULL && vertical_boxes == 0 && horizontal_boxes == 0) {
240  // Only nondescript blobs available, so return those.
241  BLOBNBOX_C_IT osd_it(osd_blobs);
242  osd_it.add_list_after(&nondescript_blobs);
243  return false;
244  }
245  int min_vert_boxes = static_cast<int>((vertical_boxes + horizontal_boxes) *
247  if (vertical_boxes >= min_vert_boxes) {
248  if (osd_blobs != NULL) {
249  BLOBNBOX_C_IT osd_it(osd_blobs);
250  osd_it.add_list_after(&vertical_blobs);
251  }
252  return true;
253  } else {
254  if (osd_blobs != NULL) {
255  BLOBNBOX_C_IT osd_it(osd_blobs);
256  osd_it.add_list_after(&horizontal_blobs);
257  }
258  return false;
259  }
260 }
BLOBNBOX_LIST blobs
Definition: blobbox.h:735
#define NULL
Definition: host.h:144
int textord_debug_tabfind
Definition: alignedblob.cpp:28
bool textord_tabfind_force_vertical_text
Definition: strokewidth.cpp:49
bool textord_tabfind_vertical_text
Definition: strokewidth.cpp:47
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
double textord_tabfind_vertical_text_ratio
Definition: strokewidth.cpp:53
BLOBNBOX_LIST large_blobs
Definition: blobbox.h:739

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