Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 164 of file alignedblob.cpp.

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

Definition at line 169 of file alignedblob.cpp.

169  {
170 }

Member Function Documentation

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

Definition at line 182 of file alignedblob.cpp.

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

Definition at line 244 of file alignedblob.cpp.

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

Definition at line 78 of file alignedblob.cpp.

78  {
79  ++debug_pix_index_;
80  textord_debug_pix_ = kTextordDebugPix;
81  char numbuf[32];
82  snprintf(numbuf, sizeof(numbuf), "%d", debug_pix_index_);
83  textord_debug_pix_ += numbuf;
84  textord_debug_pix_ += ".pix";
85 }
const char * kTextordDebugPix
Definition: alignedblob.cpp:69
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 174 of file alignedblob.cpp.

174  {
175  if (textord_debug_tabfind < detail_level)
176  return false;
178  y <= textord_testregion_top && y >= textord_testregion_bottom;
179 }
int textord_debug_tabfind
Definition: alignedblob.cpp:28
int textord_testregion_bottom
Definition: alignedblob.cpp:33
int textord_testregion_left
Definition: alignedblob.cpp:30
int textord_testregion_right
Definition: alignedblob.cpp:32

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