Skip to content

Commit

Permalink
Fixed occurrence of small rotated blocks in loosely spaced text
Browse files Browse the repository at this point in the history
  • Loading branch information
theraysmith committed Jun 12, 2015
1 parent d74c625 commit 78b5e1a
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 67 deletions.
28 changes: 13 additions & 15 deletions ccmain/pagesegmain.cpp
Expand Up @@ -242,12 +242,9 @@ int Tesseract::AutoPageSeg(PageSegMode pageseg_mode, BLOCK_LIST* blocks,
BLOCK_LIST found_blocks;
TO_BLOCK_LIST temp_blocks;

bool single_column = !PSM_COL_FIND_ENABLED(pageseg_mode);
bool osd_enabled = PSM_OSD_ENABLED(pageseg_mode);
bool osd_only = pageseg_mode == PSM_OSD_ONLY;
ColumnFinder* finder = SetupPageSegAndDetectOrientation(
single_column, osd_enabled, osd_only, blocks, osd_tess, osr,
&temp_blocks, &photomask_pix, &musicmask_pix);
pageseg_mode, blocks, osd_tess, osr, &temp_blocks, &photomask_pix,
&musicmask_pix);
int result = 0;
if (finder != NULL) {
TO_BLOCK_IT to_block_it(&temp_blocks);
Expand Down Expand Up @@ -310,9 +307,9 @@ static void AddAllScriptsConverted(const UNICHARSET& sid_set,
* The returned ColumnFinder must be deleted after use.
*/
ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
bool single_column, bool osd, bool only_osd,
BLOCK_LIST* blocks, Tesseract* osd_tess, OSResults* osr,
TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix, Pix** music_mask_pix) {
PageSegMode pageseg_mode, BLOCK_LIST* blocks, Tesseract* osd_tess,
OSResults* osr, TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix,
Pix** music_mask_pix) {
int vertical_x = 0;
int vertical_y = 1;
TabVector_LIST v_lines;
Expand All @@ -334,8 +331,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
*photo_mask_pix = ImageFind::FindImages(pix_binary_);
if (tessedit_dump_pageseg_images)
pixWrite("tessnoimages.png", pix_binary_, IFF_PNG);
if (single_column)
v_lines.clear();
if (!PSM_COL_FIND_ENABLED(pageseg_mode)) v_lines.clear();

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

finder->SetupAndFilterNoise(*photo_mask_pix, to_block);
finder->SetupAndFilterNoise(pageseg_mode, *photo_mask_pix, to_block);

if (equ_detect_) {
equ_detect_->LabelSpecialText(to_block);
Expand All @@ -367,13 +363,15 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
// We want the text lines horizontal, (vertical text indicates vertical
// textlines) which may conflict (eg vertically written CJK).
int osd_orientation = 0;
bool vertical_text = textord_tabfind_force_vertical_text;
if (!vertical_text && textord_tabfind_vertical_text) {
bool vertical_text = textord_tabfind_force_vertical_text ||
pageseg_mode == PSM_SINGLE_BLOCK_VERT_TEXT;
if (!vertical_text && textord_tabfind_vertical_text &&
PSM_ORIENTATION_ENABLED(pageseg_mode)) {
vertical_text =
finder->IsVerticallyAlignedText(textord_tabfind_vertical_text_ratio,
to_block, &osd_blobs);
}
if (osd && osd_tess != NULL && osr != NULL) {
if (PSM_OSD_ENABLED(pageseg_mode) && osd_tess != NULL && osr != NULL) {
GenericVector<int> osd_scripts;
if (osd_tess != this) {
// We are running osd as part of layout analysis, so constrain the
Expand All @@ -385,7 +383,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
}
}
os_detect_blobs(&osd_scripts, &osd_blobs, osr, osd_tess);
if (only_osd) {
if (pageseg_mode == PSM_OSD_ONLY) {
delete finder;
return NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions ccmain/tesseractclass.h
Expand Up @@ -287,9 +287,9 @@ class Tesseract : public Wordrec {
TO_BLOCK_LIST* to_blocks, BLOBNBOX_LIST* diacritic_blobs,
Tesseract* osd_tess, OSResults* osr);
ColumnFinder* SetupPageSegAndDetectOrientation(
bool single_column, bool osd, bool only_osd,
BLOCK_LIST* blocks, Tesseract* osd_tess, OSResults* osr,
TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix, Pix** music_mask_pix);
PageSegMode pageseg_mode, BLOCK_LIST* blocks, Tesseract* osd_tess,
OSResults* osr, TO_BLOCK_LIST* to_blocks, Pix** photo_mask_pix,
Pix** music_mask_pix);
// par_control.cpp
void PrerecAllWordsPar(const GenericVector<WordData>& words);

Expand Down
10 changes: 6 additions & 4 deletions textord/colfind.cpp
Expand Up @@ -150,7 +150,8 @@ ColumnFinder::~ColumnFinder() {
// direction, so the textline projection_ map can be setup.
// On return, IsVerticallyAlignedText may be called (now optionally) to
// determine the gross textline alignment of the page.
void ColumnFinder::SetupAndFilterNoise(Pix* photo_mask_pix,
void ColumnFinder::SetupAndFilterNoise(PageSegMode pageseg_mode,
Pix* photo_mask_pix,
TO_BLOCK* input_block) {
part_grid_.Init(gridsize(), bleft(), tright());
if (stroke_width_ != NULL)
Expand All @@ -172,7 +173,8 @@ void ColumnFinder::SetupAndFilterNoise(Pix* photo_mask_pix,
// Remove obvious noise and make the initial non-text map.
nontext_map_ = nontext_detect.ComputeNonTextMask(textord_debug_tabfind,
photo_mask_pix, input_block);
stroke_width_->FindTextlineDirectionAndFixBrokenCJK(cjk_script_, input_block);
stroke_width_->FindTextlineDirectionAndFixBrokenCJK(pageseg_mode, cjk_script_,
input_block);
// Clear the strokewidth grid ready for rotation or leader finding.
stroke_width_->Clear();
}
Expand Down Expand Up @@ -305,8 +307,8 @@ int ColumnFinder::FindBlocks(PageSegMode pageseg_mode, Pix* scaled_color,
input_block);
SetBlockRuleEdges(input_block);
stroke_width_->GradeBlobsIntoPartitions(
rerotate_, input_block, nontext_map_, denorm_, cjk_script_, &projection_,
diacritic_blobs, &part_grid_, &big_parts_);
pageseg_mode, rerotate_, input_block, nontext_map_, denorm_, cjk_script_,
&projection_, diacritic_blobs, &part_grid_, &big_parts_);
if (!PSM_SPARSE(pageseg_mode)) {
ImageFind::FindImagePartitions(photo_mask_pix, rotation_, rerotate_,
input_block, this, &part_grid_, &big_parts_);
Expand Down
3 changes: 2 additions & 1 deletion textord/colfind.h
Expand Up @@ -110,7 +110,8 @@ class ColumnFinder : public TabFind {
// direction, so the textline projection_ map can be setup.
// On return, IsVerticallyAlignedText may be called (now optionally) to
// determine the gross textline alignment of the page.
void SetupAndFilterNoise(Pix* photo_mask_pix, TO_BLOCK* input_block);
void SetupAndFilterNoise(PageSegMode pageseg_mode, Pix* photo_mask_pix,
TO_BLOCK* input_block);

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

0 comments on commit 78b5e1a

Please sign in to comment.