tesseract  4.00.00dev
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)
 

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 81 of file alignedblob.h.

Constructor & Destructor Documentation

◆ AlignedBlob()

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

Definition at line 143 of file alignedblob.cpp.

145  : BlobGrid(gridsize, bleft, tright) {
146 }
int gridsize() const
Definition: bbgrid.h:64
BlobGrid(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: blobgrid.cpp:24

◆ ~AlignedBlob()

tesseract::AlignedBlob::~AlignedBlob ( )
virtual

Definition at line 148 of file alignedblob.cpp.

148  {
149 }

Member Function Documentation

◆ DisplayTabs()

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

Definition at line 161 of file alignedblob.cpp.

162  {
163 #ifndef GRAPHICS_DISABLED
164  if (tab_win == NULL)
165  tab_win = MakeWindow(0, 50, window_name);
166  // For every tab in the grid, display it.
167  GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(this);
168  gsearch.StartFullSearch();
169  BLOBNBOX* bbox;
170  while ((bbox = gsearch.NextFullSearch()) != NULL) {
171  const TBOX& box = bbox->bounding_box();
172  int left_x = box.left();
173  int right_x = box.right();
174  int top_y = box.top();
175  int bottom_y = box.bottom();
176  TabType tabtype = bbox->left_tab_type();
177  if (tabtype != TT_NONE) {
178  if (tabtype == TT_MAYBE_ALIGNED)
179  tab_win->Pen(ScrollView::BLUE);
180  else if (tabtype == TT_MAYBE_RAGGED)
181  tab_win->Pen(ScrollView::YELLOW);
182  else if (tabtype == TT_CONFIRMED)
183  tab_win->Pen(ScrollView::GREEN);
184  else
185  tab_win->Pen(ScrollView::GREY);
186  tab_win->Line(left_x, top_y, left_x, bottom_y);
187  }
188  tabtype = bbox->right_tab_type();
189  if (tabtype != TT_NONE) {
190  if (tabtype == TT_MAYBE_ALIGNED)
191  tab_win->Pen(ScrollView::MAGENTA);
192  else if (tabtype == TT_MAYBE_RAGGED)
193  tab_win->Pen(ScrollView::ORANGE);
194  else if (tabtype == TT_CONFIRMED)
195  tab_win->Pen(ScrollView::RED);
196  else
197  tab_win->Pen(ScrollView::GREY);
198  tab_win->Line(right_x, top_y, right_x, bottom_y);
199  }
200  }
201  tab_win->Update();
202 #endif
203  return tab_win;
204 }
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:538
ScrollView * MakeWindow(int x, int y, const char *window_name)
Definition: bbgrid.h:593
inT16 left() const
Definition: rect.h:68
TabType
Definition: blobbox.h:44
TabType left_tab_type() const
Definition: blobbox.h:256
TabType right_tab_type() const
Definition: blobbox.h:262
static void Update()
Definition: scrollview.cpp:715
inT16 top() const
Definition: rect.h:54
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
inT16 bottom() const
Definition: rect.h:61
const TBOX & bounding_box() const
Definition: blobbox.h:215
void Pen(Color color)
Definition: scrollview.cpp:726

◆ FindVerticalAlignment()

TabVector * tesseract::AlignedBlob::FindVerticalAlignment ( AlignedBlobParams  align_params,
BLOBNBOX bbox,
int vertical_x,
int vertical_y 
)

Definition at line 223 of file alignedblob.cpp.

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

◆ WithinTestRegion()

bool tesseract::AlignedBlob::WithinTestRegion ( int  detail_level,
int  x,
int  y 
)
static

Definition at line 153 of file alignedblob.cpp.

153  {
154  if (textord_debug_tabfind < detail_level)
155  return false;
157  y <= textord_testregion_top && y >= textord_testregion_bottom;
158 }
int textord_testregion_right
Definition: alignedblob.cpp:31
int textord_testregion_bottom
Definition: alignedblob.cpp:32
int textord_testregion_left
Definition: alignedblob.cpp:29
int textord_debug_tabfind
Definition: alignedblob.cpp:27

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