Skip to content

Commit 78b5e1a

Browse files
committed
Fixed occurrence of small rotated blocks in loosely spaced text
1 parent d74c625 commit 78b5e1a

File tree

6 files changed

+125
-67
lines changed

6 files changed

+125
-67
lines changed

ccmain/pagesegmain.cpp

+13-15
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,9 @@ int Tesseract::AutoPageSeg(PageSegMode pageseg_mode, BLOCK_LIST* blocks,
242242
BLOCK_LIST found_blocks;
243243
TO_BLOCK_LIST temp_blocks;
244244

245-
bool single_column = !PSM_COL_FIND_ENABLED(pageseg_mode);
246-
bool osd_enabled = PSM_OSD_ENABLED(pageseg_mode);
247-
bool osd_only = pageseg_mode == PSM_OSD_ONLY;
248245
ColumnFinder* finder = SetupPageSegAndDetectOrientation(
249-
single_column, osd_enabled, osd_only, blocks, osd_tess, osr,
250-
&temp_blocks, &photomask_pix, &musicmask_pix);
246+
pageseg_mode, blocks, osd_tess, osr, &temp_blocks, &photomask_pix,
247+
&musicmask_pix);
251248
int result = 0;
252249
if (finder != NULL) {
253250
TO_BLOCK_IT to_block_it(&temp_blocks);
@@ -310,9 +307,9 @@ static void AddAllScriptsConverted(const UNICHARSET& sid_set,
310307
* The returned ColumnFinder must be deleted after use.
311308
*/
312309
ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
313-
bool single_column, bool osd, bool only_osd,
314-
BLOCK_LIST* blocks, Tesseract* osd_tess, OSResults* osr,
315-
TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix, Pix** music_mask_pix) {
310+
PageSegMode pageseg_mode, BLOCK_LIST* blocks, Tesseract* osd_tess,
311+
OSResults* osr, TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix,
312+
Pix** music_mask_pix) {
316313
int vertical_x = 0;
317314
int vertical_y = 1;
318315
TabVector_LIST v_lines;
@@ -334,8 +331,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
334331
*photo_mask_pix = ImageFind::FindImages(pix_binary_);
335332
if (tessedit_dump_pageseg_images)
336333
pixWrite("tessnoimages.png", pix_binary_, IFF_PNG);
337-
if (single_column)
338-
v_lines.clear();
334+
if (!PSM_COL_FIND_ENABLED(pageseg_mode)) v_lines.clear();
339335

340336
// The rest of the algorithm uses the usual connected components.
341337
textord_.find_components(pix_binary_, blocks, to_blocks);
@@ -355,7 +351,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
355351
textord_tabfind_aligned_gap_fraction,
356352
&v_lines, &h_lines, vertical_x, vertical_y);
357353

358-
finder->SetupAndFilterNoise(*photo_mask_pix, to_block);
354+
finder->SetupAndFilterNoise(pageseg_mode, *photo_mask_pix, to_block);
359355

360356
if (equ_detect_) {
361357
equ_detect_->LabelSpecialText(to_block);
@@ -367,13 +363,15 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
367363
// We want the text lines horizontal, (vertical text indicates vertical
368364
// textlines) which may conflict (eg vertically written CJK).
369365
int osd_orientation = 0;
370-
bool vertical_text = textord_tabfind_force_vertical_text;
371-
if (!vertical_text && textord_tabfind_vertical_text) {
366+
bool vertical_text = textord_tabfind_force_vertical_text ||
367+
pageseg_mode == PSM_SINGLE_BLOCK_VERT_TEXT;
368+
if (!vertical_text && textord_tabfind_vertical_text &&
369+
PSM_ORIENTATION_ENABLED(pageseg_mode)) {
372370
vertical_text =
373371
finder->IsVerticallyAlignedText(textord_tabfind_vertical_text_ratio,
374372
to_block, &osd_blobs);
375373
}
376-
if (osd && osd_tess != NULL && osr != NULL) {
374+
if (PSM_OSD_ENABLED(pageseg_mode) && osd_tess != NULL && osr != NULL) {
377375
GenericVector<int> osd_scripts;
378376
if (osd_tess != this) {
379377
// We are running osd as part of layout analysis, so constrain the
@@ -385,7 +383,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
385383
}
386384
}
387385
os_detect_blobs(&osd_scripts, &osd_blobs, osr, osd_tess);
388-
if (only_osd) {
386+
if (pageseg_mode == PSM_OSD_ONLY) {
389387
delete finder;
390388
return NULL;
391389
}

ccmain/tesseractclass.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ class Tesseract : public Wordrec {
287287
TO_BLOCK_LIST* to_blocks, BLOBNBOX_LIST* diacritic_blobs,
288288
Tesseract* osd_tess, OSResults* osr);
289289
ColumnFinder* SetupPageSegAndDetectOrientation(
290-
bool single_column, bool osd, bool only_osd,
291-
BLOCK_LIST* blocks, Tesseract* osd_tess, OSResults* osr,
292-
TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix, Pix** music_mask_pix);
290+
PageSegMode pageseg_mode, BLOCK_LIST* blocks, Tesseract* osd_tess,
291+
OSResults* osr, TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix,
292+
Pix** music_mask_pix);
293293
// par_control.cpp
294294
void PrerecAllWordsPar(const GenericVector<WordData>& words);
295295

textord/colfind.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ ColumnFinder::~ColumnFinder() {
150150
// direction, so the textline projection_ map can be setup.
151151
// On return, IsVerticallyAlignedText may be called (now optionally) to
152152
// determine the gross textline alignment of the page.
153-
void ColumnFinder::SetupAndFilterNoise(Pix* photo_mask_pix,
153+
void ColumnFinder::SetupAndFilterNoise(PageSegMode pageseg_mode,
154+
Pix* photo_mask_pix,
154155
TO_BLOCK* input_block) {
155156
part_grid_.Init(gridsize(), bleft(), tright());
156157
if (stroke_width_ != NULL)
@@ -172,7 +173,8 @@ void ColumnFinder::SetupAndFilterNoise(Pix* photo_mask_pix,
172173
// Remove obvious noise and make the initial non-text map.
173174
nontext_map_ = nontext_detect.ComputeNonTextMask(textord_debug_tabfind,
174175
photo_mask_pix, input_block);
175-
stroke_width_->FindTextlineDirectionAndFixBrokenCJK(cjk_script_, input_block);
176+
stroke_width_->FindTextlineDirectionAndFixBrokenCJK(pageseg_mode, cjk_script_,
177+
input_block);
176178
// Clear the strokewidth grid ready for rotation or leader finding.
177179
stroke_width_->Clear();
178180
}
@@ -305,8 +307,8 @@ int ColumnFinder::FindBlocks(PageSegMode pageseg_mode, Pix* scaled_color,
305307
input_block);
306308
SetBlockRuleEdges(input_block);
307309
stroke_width_->GradeBlobsIntoPartitions(
308-
rerotate_, input_block, nontext_map_, denorm_, cjk_script_, &projection_,
309-
diacritic_blobs, &part_grid_, &big_parts_);
310+
pageseg_mode, rerotate_, input_block, nontext_map_, denorm_, cjk_script_,
311+
&projection_, diacritic_blobs, &part_grid_, &big_parts_);
310312
if (!PSM_SPARSE(pageseg_mode)) {
311313
ImageFind::FindImagePartitions(photo_mask_pix, rotation_, rerotate_,
312314
input_block, this, &part_grid_, &big_parts_);

textord/colfind.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ class ColumnFinder : public TabFind {
110110
// direction, so the textline projection_ map can be setup.
111111
// On return, IsVerticallyAlignedText may be called (now optionally) to
112112
// determine the gross textline alignment of the page.
113-
void SetupAndFilterNoise(Pix* photo_mask_pix, TO_BLOCK* input_block);
113+
void SetupAndFilterNoise(PageSegMode pageseg_mode, Pix* photo_mask_pix,
114+
TO_BLOCK* input_block);
114115

115116
// Tests for vertical alignment of text (returning true if so), and generates
116117
// a list of blobs (in osd_blobs) for orientation and script detection.

0 commit comments

Comments
 (0)