tesseract  5.0.0-alpha-619-ge9db
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)
 
 ~AlignedBlob () override
 
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)
 
 ~BlobGrid () override
 
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)
 
 ~BBGrid () override
 
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 143 of file alignedblob.cpp.

146 }

◆ ~AlignedBlob()

tesseract::AlignedBlob::~AlignedBlob ( )
overridedefault

Member Function Documentation

◆ DisplayTabs()

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

Definition at line 158 of file alignedblob.cpp.

159  {
160 #ifndef GRAPHICS_DISABLED
161  if (tab_win == nullptr)
162  tab_win = MakeWindow(0, 50, window_name);
163  // For every tab in the grid, display it.
164  GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(this);
165  gsearch.StartFullSearch();
166  BLOBNBOX* bbox;
167  while ((bbox = gsearch.NextFullSearch()) != nullptr) {
168  const TBOX& box = bbox->bounding_box();
169  int left_x = box.left();
170  int right_x = box.right();
171  int top_y = box.top();
172  int bottom_y = box.bottom();
173  TabType tabtype = bbox->left_tab_type();
174  if (tabtype != TT_NONE) {
175  if (tabtype == TT_MAYBE_ALIGNED)
176  tab_win->Pen(ScrollView::BLUE);
177  else if (tabtype == TT_MAYBE_RAGGED)
178  tab_win->Pen(ScrollView::YELLOW);
179  else if (tabtype == TT_CONFIRMED)
180  tab_win->Pen(ScrollView::GREEN);
181  else
182  tab_win->Pen(ScrollView::GREY);
183  tab_win->Line(left_x, top_y, left_x, bottom_y);
184  }
185  tabtype = bbox->right_tab_type();
186  if (tabtype != TT_NONE) {
187  if (tabtype == TT_MAYBE_ALIGNED)
188  tab_win->Pen(ScrollView::MAGENTA);
189  else if (tabtype == TT_MAYBE_RAGGED)
190  tab_win->Pen(ScrollView::ORANGE);
191  else if (tabtype == TT_CONFIRMED)
192  tab_win->Pen(ScrollView::RED);
193  else
194  tab_win->Pen(ScrollView::GREY);
195  tab_win->Line(right_x, top_y, right_x, bottom_y);
196  }
197  }
198  tab_win->Update();
199 #endif
200  return tab_win;
201 }

◆ FindVerticalAlignment()

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

Definition at line 225 of file alignedblob.cpp.

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

◆ WithinTestRegion()

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

Definition at line 150 of file alignedblob.cpp.

150  {
151  if (textord_debug_tabfind < detail_level)
152  return false;
153  return x >= textord_testregion_left && x <= textord_testregion_right &&
154  y <= textord_testregion_top && y >= textord_testregion_bottom;
155 }

The documentation for this class was generated from the following files:
ScrollView::GREY
Definition: scrollview.h:133
TabType
TabType
Definition: blobbox.h:58
BLOBNBOX::set_right_tab_type
void set_right_tab_type(TabType new_type)
Definition: blobbox.h:279
tesseract::TabVector::FitVector
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:176
tesseract::BlobGrid::BlobGrid
BlobGrid(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: blobgrid.cpp:24
tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT >::MakeWindow
ScrollView * MakeWindow(int x, int y, const char *window_name)
Definition: bbgrid.h:589
TT_NONE
Definition: blobbox.h:59
TBOX::print
void print() const
Definition: rect.h:277
TBOX::top
int16_t top() const
Definition: rect.h:57
tesseract::kMinTabGradient
const double kMinTabGradient
Definition: alignedblob.cpp:60
TT_CONFIRMED
Definition: blobbox.h:63
ScrollView::Pen
void Pen(Color color)
Definition: scrollview.cpp:717
TT_MAYBE_ALIGNED
Definition: blobbox.h:62
BLOBNBOX
Definition: blobbox.h:142
ScrollView::BLUE
Definition: scrollview.h:108
BLOBNBOX::set_left_tab_type
void set_left_tab_type(TabType new_type)
Definition: blobbox.h:273
tesseract::GridBase::tright
const ICOORD & tright() const
Definition: bbgrid.h:75
ScrollView::ORANGE
Definition: scrollview.h:136
tesseract::AlignedBlob::WithinTestRegion
static bool WithinTestRegion(int detail_level, int x, int y)
Definition: alignedblob.cpp:150
ScrollView::MAGENTA
Definition: scrollview.h:109
ScrollView::YELLOW
Definition: scrollview.h:105
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
ScrollView::RED
Definition: scrollview.h:104
BLOBNBOX::bounding_box
const TBOX & bounding_box() const
Definition: blobbox.h:229
TT_MAYBE_RAGGED
Definition: blobbox.h:61
tesseract::GridBase::gridsize
int gridsize() const
Definition: bbgrid.h:63
BLOBNBOX::right_tab_type
TabType right_tab_type() const
Definition: blobbox.h:276
TBOX::left
int16_t left() const
Definition: rect.h:71
ScrollView::GREEN
Definition: scrollview.h:106
TBOX::right
int16_t right() const
Definition: rect.h:78
ScrollView::Line
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:531
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
ScrollView::Update
static void Update()
Definition: scrollview.cpp:708
BLOBNBOX::left_tab_type
TabType left_tab_type() const
Definition: blobbox.h:270
textord_debug_tabfind
int textord_debug_tabfind
Definition: alignedblob.cpp:27
tesseract::GridBase::bleft
const ICOORD & bleft() const
Definition: bbgrid.h:72
TBOX
Definition: rect.h:33