All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::AlignedBlob Class Reference

#include <alignedblob.h>

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

Public Member Functions

 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
 

Static Public Member Functions

static bool WithinTestRegion (int detail_level, int x, int y)
 
static void IncrementDebugPix ()
 
static const STRINGtextord_debug_pix ()
 

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

Definition at line 83 of file alignedblob.h.

Constructor & Destructor Documentation

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

Definition at line 163 of file alignedblob.cpp.

165  : BlobGrid(gridsize, bleft, tright) {
166 }
int gridsize() const
Definition: bbgrid.h:63
BlobGrid(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: blobgrid.cpp:24
tesseract::AlignedBlob::~AlignedBlob ( )
virtual

Definition at line 168 of file alignedblob.cpp.

168  {
169 }

Member Function Documentation

ScrollView * tesseract::AlignedBlob::DisplayTabs ( const char *  window_name,
ScrollView tab_win 
)

Definition at line 181 of file alignedblob.cpp.

182  {
183 #ifndef GRAPHICS_DISABLED
184  if (tab_win == NULL)
185  tab_win = MakeWindow(0, 50, window_name);
186  // For every tab in the grid, display it.
187  GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(this);
188  gsearch.StartFullSearch();
189  BLOBNBOX* bbox;
190  while ((bbox = gsearch.NextFullSearch()) != NULL) {
191  TBOX box = bbox->bounding_box();
192  int left_x = box.left();
193  int right_x = box.right();
194  int top_y = box.top();
195  int bottom_y = box.bottom();
196  TabType tabtype = bbox->left_tab_type();
197  if (tabtype != TT_NONE) {
198  if (tabtype == TT_MAYBE_ALIGNED)
199  tab_win->Pen(ScrollView::BLUE);
200  else if (tabtype == TT_MAYBE_RAGGED)
201  tab_win->Pen(ScrollView::YELLOW);
202  else if (tabtype == TT_CONFIRMED)
203  tab_win->Pen(ScrollView::GREEN);
204  else
205  tab_win->Pen(ScrollView::GREY);
206  tab_win->Line(left_x, top_y, left_x, bottom_y);
207  }
208  tabtype = bbox->right_tab_type();
209  if (tabtype != TT_NONE) {
210  if (tabtype == TT_MAYBE_ALIGNED)
211  tab_win->Pen(ScrollView::MAGENTA);
212  else if (tabtype == TT_MAYBE_RAGGED)
213  tab_win->Pen(ScrollView::ORANGE);
214  else if (tabtype == TT_CONFIRMED)
215  tab_win->Pen(ScrollView::RED);
216  else
217  tab_win->Pen(ScrollView::GREY);
218  tab_win->Line(right_x, top_y, right_x, bottom_y);
219  }
220  }
221  tab_win->Update();
222 #endif
223  return tab_win;
224 }
void Pen(Color color)
Definition: scrollview.cpp:726
static void Update()
Definition: scrollview.cpp:715
inT16 right() const
Definition: rect.h:75
TabType left_tab_type() const
Definition: blobbox.h:256
inT16 left() const
Definition: rect.h:68
inT16 bottom() const
Definition: rect.h:61
ScrollView * MakeWindow(int x, int y, const char *window_name)
TabType
Definition: blobbox.h:44
Definition: rect.h:30
#define NULL
Definition: host.h:144
const TBOX & bounding_box() const
Definition: blobbox.h:215
inT16 top() const
Definition: rect.h:54
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:538
TabType right_tab_type() const
Definition: blobbox.h:262
TabVector * tesseract::AlignedBlob::FindVerticalAlignment ( AlignedBlobParams  align_params,
BLOBNBOX bbox,
int *  vertical_x,
int *  vertical_y 
)

Definition at line 243 of file alignedblob.cpp.

246  {
247  int ext_start_y, ext_end_y;
248  BLOBNBOX_CLIST good_points;
249  // Search up and then down from the starting bbox.
250  TBOX box = bbox->bounding_box();
251  bool debug = WithinTestRegion(2, box.left(), box.bottom());
252  int pt_count = AlignTabs(align_params, false, bbox, &good_points, &ext_end_y);
253  pt_count += AlignTabs(align_params, true, bbox, &good_points, &ext_start_y);
254  BLOBNBOX_C_IT it(&good_points);
255  it.move_to_last();
256  box = it.data()->bounding_box();
257  int end_y = box.top();
258  int end_x = align_params.right_tab ? box.right() : box.left();
259  it.move_to_first();
260  box = it.data()->bounding_box();
261  int start_x = align_params.right_tab ? box.right() : box.left();
262  int start_y = box.bottom();
263  // Acceptable tab vectors must have a mininum number of points,
264  // have a minimum acceptable length, and have a minimum gradient.
265  // The gradient corresponds to the skew angle.
266  // Ragged tabs don't need to satisfy the gradient condition, as they
267  // will always end up parallel to the vertical direction.
268  bool at_least_2_crossings = AtLeast2LineCrossings(&good_points);
269  if ((pt_count >= align_params.min_points &&
270  end_y - start_y >= align_params.min_length &&
271  (align_params.ragged ||
272  end_y - start_y >= abs(end_x - start_x) * kMinTabGradient)) ||
273  at_least_2_crossings) {
274  int confirmed_points = 0;
275  // Count existing confirmed points to see if vector is acceptable.
276  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
277  bbox = it.data();
278  if (align_params.right_tab) {
279  if (bbox->right_tab_type() == align_params.confirmed_type)
280  ++confirmed_points;
281  } else {
282  if (bbox->left_tab_type() == align_params.confirmed_type)
283  ++confirmed_points;
284  }
285  }
286  // Ragged vectors are not allowed to use too many already used points.
287  if (!align_params.ragged ||
288  confirmed_points + confirmed_points < pt_count) {
289  const TBOX& box = bbox->bounding_box();
290  if (debug) {
291  tprintf("Confirming tab vector of %d pts starting at %d,%d\n",
292  pt_count, box.left(), box.bottom());
293  }
294  // Flag all the aligned neighbours as confirmed .
295  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
296  bbox = it.data();
297  if (align_params.right_tab) {
298  bbox->set_right_tab_type(align_params.confirmed_type);
299  } else {
300  bbox->set_left_tab_type(align_params.confirmed_type);
301  }
302  if (debug) {
303  bbox->bounding_box().print();
304  }
305  }
306  // Now make the vector and return it.
307  TabVector* result = TabVector::FitVector(align_params.alignment,
308  align_params.vertical,
309  ext_start_y, ext_end_y,
310  &good_points,
311  vertical_x, vertical_y);
312  result->set_intersects_other_lines(at_least_2_crossings);
313  if (debug) {
314  tprintf("Box was %d, %d\n", box.left(), box.bottom());
315  result->Print("After fitting");
316  }
317  return result;
318  } else if (debug) {
319  tprintf("Ragged tab used too many used points: %d out of %d\n",
320  confirmed_points, pt_count);
321  }
322  } else if (debug) {
323  tprintf("Tab vector failed basic tests: pt count %d vs min %d, "
324  "length %d vs min %d, min grad %g\n",
325  pt_count, align_params.min_points, end_y - start_y,
326  align_params.min_length, abs(end_x - start_x) * kMinTabGradient);
327  }
328  return NULL;
329 }
static bool WithinTestRegion(int detail_level, int x, int y)
#define tprintf(...)
Definition: tprintf.h:31
void print() const
Definition: rect.h:270
const double kMinTabGradient
Definition: alignedblob.cpp:61
inT16 right() const
Definition: rect.h:75
TabType left_tab_type() const
Definition: blobbox.h:256
inT16 left() const
Definition: rect.h:68
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
#define NULL
Definition: host.h:144
const TBOX & bounding_box() const
Definition: blobbox.h:215
void set_right_tab_type(TabType new_type)
Definition: blobbox.h:265
static TabVector * FitVector(TabAlignment alignment, ICOORD vertical, int extended_start_y, int extended_end_y, BLOBNBOX_CLIST *good_points, int *vertical_x, int *vertical_y)
Definition: tabvector.cpp:182
inT16 top() const
Definition: rect.h:54
TabType right_tab_type() const
Definition: blobbox.h:262
void set_left_tab_type(TabType new_type)
Definition: blobbox.h:259
void tesseract::AlignedBlob::IncrementDebugPix ( )
static

Definition at line 77 of file alignedblob.cpp.

77  {
78  ++debug_pix_index_;
79  textord_debug_pix_ = kTextordDebugPix;
80  char numbuf[32];
81  snprintf(numbuf, sizeof(numbuf), "%d", debug_pix_index_);
82  textord_debug_pix_ += numbuf;
83  textord_debug_pix_ += ".pix";
84 }
const char * kTextordDebugPix
Definition: alignedblob.cpp:68
static const STRING& tesseract::AlignedBlob::textord_debug_pix ( )
inlinestatic

Definition at line 112 of file alignedblob.h.

112  {
113  return textord_debug_pix_;
114  }
bool tesseract::AlignedBlob::WithinTestRegion ( int  detail_level,
int  x,
int  y 
)
static

Definition at line 173 of file alignedblob.cpp.

173  {
174  if (textord_debug_tabfind < detail_level)
175  return false;
177  y <= textord_testregion_top && y >= textord_testregion_bottom;
178 }
int textord_testregion_right
Definition: alignedblob.cpp:31
int textord_debug_tabfind
Definition: alignedblob.cpp:27
int textord_testregion_left
Definition: alignedblob.cpp:29
int textord_testregion_bottom
Definition: alignedblob.cpp:32

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