tesseract  4.0.0-1-g2a2b
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 ()=default
 
 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 144 of file alignedblob.cpp.

147 }
BlobGrid(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: blobgrid.cpp:24
int gridsize() const
Definition: bbgrid.h:64
const ICOORD & bleft() const
Definition: bbgrid.h:73
const ICOORD & tright() const
Definition: bbgrid.h:76

◆ ~AlignedBlob()

tesseract::AlignedBlob::~AlignedBlob ( )
virtualdefault

Member Function Documentation

◆ DisplayTabs()

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

Definition at line 159 of file alignedblob.cpp.

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

◆ FindVerticalAlignment()

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

Definition at line 226 of file alignedblob.cpp.

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

◆ WithinTestRegion()

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

Definition at line 151 of file alignedblob.cpp.

151  {
152  if (textord_debug_tabfind < detail_level)
153  return false;
155  y <= textord_testregion_top && y >= textord_testregion_bottom;
156 }
int textord_testregion_right
Definition: alignedblob.cpp:32
int textord_debug_tabfind
Definition: alignedblob.cpp:28
int textord_testregion_left
Definition: alignedblob.cpp:30
int textord_testregion_bottom
Definition: alignedblob.cpp:33

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