20 #include "config_auto.h"
65 gridsize * gridsize)),
66 noise_density_(nullptr) {
73 delete noise_density_;
94 BLOBNBOX_IT blob_it(&blob_block->
blobs);
95 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
98 perimeter_area_ratio *= perimeter_area_ratio / blob->
enclosed_area();
104 noise_density_ = ComputeNoiseDensity(debug, photo_map, &good_grid);
108 pixWrite(
"junknoisemask.png", pix, IFF_PNG);
111 #ifndef GRAPHICS_DISABLED
115 #endif // GRAPHICS_DISABLED
118 MarkAndDeleteNonTextBlobs(&blob_block->
large_blobs,
126 MarkAndDeleteNonTextBlobs(&blob_block->
large_blobs,
131 MarkAndDeleteNonTextBlobs(&blob_block->
noise_blobs, -1,
133 MarkAndDeleteNonTextBlobs(&blob_block->
small_blobs, -1,
135 MarkAndDeleteNonTextBlobs(&blob_block->
blobs, -1,
138 #ifndef GRAPHICS_DISABLED
140 #endif // GRAPHICS_DISABLED
141 pixWrite(
"junkccphotomask.png", pix, IFF_PNG);
142 #ifndef GRAPHICS_DISABLED
145 #endif // GRAPHICS_DISABLED
157 IntGrid* CCNonTextDetect::ComputeNoiseDensity(
bool debug, Pix* photo_map,
166 int height = pixGetHeight(photo_map);
171 if (max_noise_count_ < noise + photo_offset &&
172 noise <= max_noise_count_) {
176 int bottom = height - y *
gridsize();
180 noise_density->
SetGridCell(x, y, noise + photo_offset);
183 if (debug && noise > max_noise_count_ &&
185 tprintf(
"At %d, %d, noise = %d, good=%d, orig=%d, thr=%d\n",
191 if (noise > max_noise_count_ &&
201 return noise_density;
207 static TBOX AttemptBoxExpansion(
const TBOX& box,
const IntGrid& noise_density,
209 TBOX expanded_box(box);
210 expanded_box.set_right(box.
right() + pad);
211 if (!noise_density.AnyZeroInRect(expanded_box))
215 if (!noise_density.AnyZeroInRect(expanded_box))
219 if (!noise_density.AnyZeroInRect(expanded_box))
223 if (!noise_density.AnyZeroInRect(expanded_box))
227 if (!noise_density.AnyZeroInRect(expanded_box))
246 void CCNonTextDetect::MarkAndDeleteNonTextBlobs(BLOBNBOX_LIST* blobs,
247 int max_blob_overlaps,
252 BLOBNBOX_IT blob_it(blobs);
253 BLOBNBOX_LIST dead_blobs;
254 BLOBNBOX_IT dead_it(&dead_blobs);
255 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
259 (max_blob_overlaps < 0 ||
260 !BlobOverlapsTooMuch(blob, max_blob_overlaps))) {
262 #ifndef GRAPHICS_DISABLED
264 blob->
plot(win, ok_color, ok_color);
265 #endif // GRAPHICS_DISABLED
271 pixRasterop(nontext_mask, box.
left(), imageheight - box.
top(),
274 pixDestroy(&blob_pix);
280 box = AttemptBoxExpansion(box, *noise_density_,
gridsize());
283 pixRasterop(nontext_mask, box.
left(), imageheight - box.
top(),
284 box.
width(), box.
height(), PIX_SET,
nullptr, 0, 0);
286 #ifndef GRAPHICS_DISABLED
289 #endif // GRAPHICS_DISABLED
295 delete blob->
cblob();
296 dead_it.add_to_end(blob_it.extract());
303 bool CCNonTextDetect::BlobOverlapsTooMuch(
BLOBNBOX* blob,
int max_overlaps) {
308 rsearch.StartRectSearch(box);
309 rsearch.SetUniqueMode(
true);
311 int overlap_count = 0;
312 while (overlap_count <= max_overlaps &&
313 (neighbour = rsearch.NextRectSearch()) !=
nullptr) {
316 if (overlap_count > max_overlaps)