tesseract  5.0.0-alpha-619-ge9db
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)
 
 ~CCNonTextDetect () override
 
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)
 
 ~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
 

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 61 of file ccnontextdetect.cpp.

64  max_noise_count_(static_cast<int>(kMaxSmallNeighboursPerPix *
65  gridsize * gridsize)),
66  noise_density_(nullptr) {
67  // TODO(rays) break max_noise_count_ out into an area-proportional
68  // value, as now plus an additive constant for the number of text blobs
69  // in the 3x3 neighbourhood - maybe 9.
70 }

◆ ~CCNonTextDetect()

tesseract::CCNonTextDetect::~CCNonTextDetect ( )
override

Definition at line 72 of file ccnontextdetect.cpp.

72  {
73  delete noise_density_;
74 }

Member Function Documentation

◆ ComputeNonTextMask()

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

Definition at line 85 of file ccnontextdetect.cpp.

86  {
87  // Insert the smallest blobs into the grid.
88  InsertBlobList(&blob_block->small_blobs);
89  InsertBlobList(&blob_block->noise_blobs);
90  // Add the medium blobs that don't have a good strokewidth neighbour.
91  // Those that do go into good_grid as an antidote to spreading beyond the
92  // real reaches of a noise region.
93  BlobGrid good_grid(gridsize(), bleft(), tright());
94  BLOBNBOX_IT blob_it(&blob_block->blobs);
95  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
96  BLOBNBOX* blob = blob_it.data();
97  double perimeter_area_ratio = blob->cblob()->perimeter() / 4.0;
98  perimeter_area_ratio *= perimeter_area_ratio / blob->enclosed_area();
99  if (blob->GoodTextBlob() == 0 || perimeter_area_ratio < kMinGoodTextPARatio)
100  InsertBBox(true, true, blob);
101  else
102  good_grid.InsertBBox(true, true, blob);
103  }
104  noise_density_ = ComputeNoiseDensity(debug, photo_map, &good_grid);
105  good_grid.Clear(); // Not needed any more.
106  Pix* pix = noise_density_->ThresholdToPix(max_noise_count_);
107  if (debug) {
108  pixWrite("junknoisemask.png", pix, IFF_PNG);
109  }
110  ScrollView* win = nullptr;
111  #ifndef GRAPHICS_DISABLED
112  if (debug) {
113  win = MakeWindow(0, 400, "Photo Mask Blobs");
114  }
115  #endif // GRAPHICS_DISABLED
116  // Large and medium blobs are not text if they overlap with "a lot" of small
117  // blobs.
118  MarkAndDeleteNonTextBlobs(&blob_block->large_blobs,
120  win, ScrollView::DARK_GREEN, pix);
121  MarkAndDeleteNonTextBlobs(&blob_block->blobs, kMaxMediumOverlapsWithSmall,
122  win, ScrollView::WHITE, pix);
123  // Clear the grid of small blobs and insert the medium blobs.
124  Clear();
125  InsertBlobList(&blob_block->blobs);
126  MarkAndDeleteNonTextBlobs(&blob_block->large_blobs,
128  win, ScrollView::DARK_GREEN, pix);
129  // Clear again before we start deleting the blobs in the grid.
130  Clear();
131  MarkAndDeleteNonTextBlobs(&blob_block->noise_blobs, -1,
132  win, ScrollView::CORAL, pix);
133  MarkAndDeleteNonTextBlobs(&blob_block->small_blobs, -1,
134  win, ScrollView::GOLDENROD, pix);
135  MarkAndDeleteNonTextBlobs(&blob_block->blobs, -1,
136  win, ScrollView::WHITE, pix);
137  if (debug) {
138  #ifndef GRAPHICS_DISABLED
139  win->Update();
140  #endif // GRAPHICS_DISABLED
141  pixWrite("junkccphotomask.png", pix, IFF_PNG);
142  #ifndef GRAPHICS_DISABLED
143  delete win->AwaitEvent(SVET_DESTROY);
144  delete win;
145  #endif // GRAPHICS_DISABLED
146  }
147  return pix;
148 }

The documentation for this class was generated from the following files:
TO_BLOCK::small_blobs
BLOBNBOX_LIST small_blobs
Definition: blobbox.h:774
ScrollView
Definition: scrollview.h:97
SVET_DESTROY
Definition: scrollview.h:45
C_BLOB::perimeter
int32_t perimeter()
Definition: stepblob.cpp:284
ScrollView::DARK_GREEN
Definition: scrollview.h:124
tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT >::InsertBBox
void InsertBBox(bool h_spread, bool v_spread, BLOBNBOX *bbox)
Definition: bbgrid.h:486
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
TO_BLOCK::noise_blobs
BLOBNBOX_LIST noise_blobs
Definition: blobbox.h:773
tesseract::kMaxSmallNeighboursPerPix
const double kMaxSmallNeighboursPerPix
Definition: ccnontextdetect.cpp:31
tesseract::kMaxLargeOverlapsWithMedium
const int kMaxLargeOverlapsWithMedium
Definition: ccnontextdetect.cpp:43
tesseract::BBGrid< BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT >::Clear
void Clear()
Definition: bbgrid.h:455
TO_BLOCK::blobs
BLOBNBOX_LIST blobs
Definition: blobbox.h:771
tesseract::kMaxLargeOverlapsWithSmall
const int kMaxLargeOverlapsWithSmall
Definition: ccnontextdetect.cpp:34
BLOBNBOX
Definition: blobbox.h:142
tesseract::GridBase::tright
const ICOORD & tright() const
Definition: bbgrid.h:75
tesseract::kMinGoodTextPARatio
const double kMinGoodTextPARatio
Definition: ccnontextdetect.cpp:59
BLOBNBOX::GoodTextBlob
int GoodTextBlob() const
Definition: blobbox.cpp:224
TO_BLOCK::large_blobs
BLOBNBOX_LIST large_blobs
Definition: blobbox.h:775
ScrollView::WHITE
Definition: scrollview.h:103
ScrollView::AwaitEvent
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:443
tesseract::GridBase::gridsize
int gridsize() const
Definition: bbgrid.h:63
ScrollView::GOLDENROD
Definition: scrollview.h:123
BLOBNBOX::enclosed_area
int32_t enclosed_area() const
Definition: blobbox.h:252
tesseract::BlobGrid::InsertBlobList
void InsertBlobList(BLOBNBOX_LIST *blobs)
Definition: blobgrid.cpp:36
ScrollView::Update
static void Update()
Definition: scrollview.cpp:708
ScrollView::CORAL
Definition: scrollview.h:119
BLOBNBOX::cblob
C_BLOB * cblob() const
Definition: blobbox.h:267
tesseract::kMaxMediumOverlapsWithSmall
const int kMaxMediumOverlapsWithSmall
Definition: ccnontextdetect.cpp:39
tesseract::GridBase::bleft
const ICOORD & bleft() const
Definition: bbgrid.h:72
tesseract::IntGrid::ThresholdToPix
Pix * ThresholdToPix(int threshold) const
Definition: bbgrid.cpp:190