tesseract  4.0.0-1-g2a2b
tesseract::CCNonTextDetect Class Reference

#include <ccnontextdetect.h>

Inheritance diagram for tesseract::CCNonTextDetect:
tesseract::BlobGrid tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT > tesseract::GridBase

Public Member Functions

 CCNonTextDetect (int gridsize, const ICOORD &bleft, const ICOORD &tright)
 
virtual ~CCNonTextDetect ()
 
Pix * ComputeNonTextMask (bool debug, Pix *photo_map, TO_BLOCK *blob_block)
 
- 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
 

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 31 of file ccnontextdetect.h.

Constructor & Destructor Documentation

◆ CCNonTextDetect()

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

Definition at line 62 of file ccnontextdetect.cpp.

65  max_noise_count_(static_cast<int>(kMaxSmallNeighboursPerPix *
66  gridsize * gridsize)),
67  noise_density_(nullptr) {
68  // TODO(rays) break max_noise_count_ out into an area-proportional
69  // value, as now plus an additive constant for the number of text blobs
70  // in the 3x3 neighbourhood - maybe 9.
71 }
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 double kMaxSmallNeighboursPerPix
const ICOORD & tright() const
Definition: bbgrid.h:76

◆ ~CCNonTextDetect()

tesseract::CCNonTextDetect::~CCNonTextDetect ( )
virtual

Definition at line 73 of file ccnontextdetect.cpp.

73  {
74  delete noise_density_;
75 }

Member Function Documentation

◆ ComputeNonTextMask()

Pix * tesseract::CCNonTextDetect::ComputeNonTextMask ( bool  debug,
Pix *  photo_map,
TO_BLOCK blob_block 
)

Definition at line 86 of file ccnontextdetect.cpp.

87  {
88  // Insert the smallest blobs into the grid.
89  InsertBlobList(&blob_block->small_blobs);
90  InsertBlobList(&blob_block->noise_blobs);
91  // Add the medium blobs that don't have a good strokewidth neighbour.
92  // Those that do go into good_grid as an antidote to spreading beyond the
93  // real reaches of a noise region.
94  BlobGrid good_grid(gridsize(), bleft(), tright());
95  BLOBNBOX_IT blob_it(&blob_block->blobs);
96  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
97  BLOBNBOX* blob = blob_it.data();
98  double perimeter_area_ratio = blob->cblob()->perimeter() / 4.0;
99  perimeter_area_ratio *= perimeter_area_ratio / blob->enclosed_area();
100  if (blob->GoodTextBlob() == 0 || perimeter_area_ratio < kMinGoodTextPARatio)
101  InsertBBox(true, true, blob);
102  else
103  good_grid.InsertBBox(true, true, blob);
104  }
105  noise_density_ = ComputeNoiseDensity(debug, photo_map, &good_grid);
106  good_grid.Clear(); // Not needed any more.
107  Pix* pix = noise_density_->ThresholdToPix(max_noise_count_);
108  if (debug) {
109  pixWrite("junknoisemask.png", pix, IFF_PNG);
110  }
111  ScrollView* win = nullptr;
112  #ifndef GRAPHICS_DISABLED
113  if (debug) {
114  win = MakeWindow(0, 400, "Photo Mask Blobs");
115  }
116  #endif // GRAPHICS_DISABLED
117  // Large and medium blobs are not text if they overlap with "a lot" of small
118  // blobs.
119  MarkAndDeleteNonTextBlobs(&blob_block->large_blobs,
121  win, ScrollView::DARK_GREEN, pix);
122  MarkAndDeleteNonTextBlobs(&blob_block->blobs, kMaxMediumOverlapsWithSmall,
123  win, ScrollView::WHITE, pix);
124  // Clear the grid of small blobs and insert the medium blobs.
125  Clear();
126  InsertBlobList(&blob_block->blobs);
127  MarkAndDeleteNonTextBlobs(&blob_block->large_blobs,
129  win, ScrollView::DARK_GREEN, pix);
130  // Clear again before we start deleting the blobs in the grid.
131  Clear();
132  MarkAndDeleteNonTextBlobs(&blob_block->noise_blobs, -1,
133  win, ScrollView::CORAL, pix);
134  MarkAndDeleteNonTextBlobs(&blob_block->small_blobs, -1,
135  win, ScrollView::GOLDENROD, pix);
136  MarkAndDeleteNonTextBlobs(&blob_block->blobs, -1,
137  win, ScrollView::WHITE, pix);
138  if (debug) {
139  #ifndef GRAPHICS_DISABLED
140  win->Update();
141  #endif // GRAPHICS_DISABLED
142  pixWrite("junkccphotomask.png", pix, IFF_PNG);
143  #ifndef GRAPHICS_DISABLED
144  delete win->AwaitEvent(SVET_DESTROY);
145  delete win;
146  #endif // GRAPHICS_DISABLED
147  }
148  return pix;
149 }
const int kMaxLargeOverlapsWithMedium
void InsertBlobList(BLOBNBOX_LIST *blobs)
Definition: blobgrid.cpp:36
int GoodTextBlob() const
Definition: blobbox.cpp:227
ScrollView * MakeWindow(int x, int y, const char *window_name)
Definition: bbgrid.h:591
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 int kMaxMediumOverlapsWithSmall
int32_t enclosed_area() const
Definition: blobbox.h:254
const double kMinGoodTextPARatio
static void Update()
Definition: scrollview.cpp:711
int32_t perimeter()
Definition: stepblob.cpp:294
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:445
const int kMaxLargeOverlapsWithSmall
void InsertBBox(bool h_spread, bool v_spread, BLOBNBOX *bbox)
Definition: bbgrid.h:488
BLOBNBOX_LIST blobs
Definition: blobbox.h:785
BLOBNBOX_LIST large_blobs
Definition: blobbox.h:789
C_BLOB * cblob() const
Definition: blobbox.h:269
Pix * ThresholdToPix(int threshold) const
Definition: bbgrid.cpp:191
const ICOORD & tright() const
Definition: bbgrid.h:76
BLOBNBOX_LIST small_blobs
Definition: blobbox.h:788
BLOBNBOX_LIST noise_blobs
Definition: blobbox.h:787

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