Skip to content

Commit

Permalink
Improved results on images with no resolution. Estimates resolution
Browse files Browse the repository at this point in the history
from the size of the connected components, based on average text size.
  • Loading branch information
Ray Smith committed Sep 8, 2017
1 parent 147a1a5 commit a18620c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
13 changes: 2 additions & 11 deletions api/baseapi.cpp
Expand Up @@ -102,15 +102,6 @@ const char* kInputFile = "noname.tif";
const char* kOldVarsFile = "failed_vars.txt";
/** Max string length of an int. */
const int kMaxIntSize = 22;
/**
* Minimum believable resolution. Used as a default if there is no other
* information, as it is safer to under-estimate than over-estimate.
*/
const int kMinCredibleResolution = 70;
/** Maximum believable resolution. */
const int kMaxCredibleResolution = 2400;
/** Default resolution. */
const int kDefaultResolution = 300;

/* Add all available languages recursively.
*/
Expand Down Expand Up @@ -2225,8 +2216,8 @@ bool TessBaseAPI::Threshold(Pix** pix) {
// Use the minimum default resolution, as it is safer to under-estimate
// than over-estimate resolution.
tprintf("Warning. Invalid resolution %d dpi. Using %d instead.\n", y_res,
kDefaultResolution);
thresholder_->SetSourceYResolution(kDefaultResolution);
kMinCredibleResolution);
thresholder_->SetSourceYResolution(kMinCredibleResolution);
}
PageSegMode pageseg_mode =
static_cast<PageSegMode>(
Expand Down
3 changes: 0 additions & 3 deletions ccmain/osdetect.cpp
Expand Up @@ -58,9 +58,6 @@ const char* ScriptDetector::korean_script_ = "Korean";
const char* ScriptDetector::japanese_script_ = "Japanese";
const char* ScriptDetector::fraktur_script_ = "Fraktur";

// Minimum believable resolution.
const int kMinCredibleResolution = 70;

void OSResults::update_best_orientation() {
float first = orientations[0];
float second = orientations[1];
Expand Down
15 changes: 12 additions & 3 deletions ccmain/pagesegmain.cpp
Expand Up @@ -310,13 +310,22 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
TO_BLOCK* to_block = to_block_it.data();
TBOX blkbox = to_block->block->bounding_box();
ColumnFinder* finder = NULL;
int estimated_resolution = source_resolution_;
if (source_resolution_ == kMinCredibleResolution) {
// Try to estimate resolution from typical body text size.
int res = IntCastRounded(to_block->line_size * kResolutionEstimationFactor);
if (res > estimated_resolution && res < kMaxCredibleResolution) {
estimated_resolution = res;
tprintf("Estimating resolution as %d\n", estimated_resolution);
}
}

if (to_block->line_size >= 2) {
finder = new ColumnFinder(static_cast<int>(to_block->line_size),
blkbox.botleft(), blkbox.topright(),
source_resolution_, textord_use_cjk_fp_model,
textord_tabfind_aligned_gap_fraction,
&v_lines, &h_lines, vertical_x, vertical_y);
estimated_resolution, textord_use_cjk_fp_model,
textord_tabfind_aligned_gap_fraction, &v_lines,
&h_lines, vertical_x, vertical_y);

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

Expand Down
14 changes: 13 additions & 1 deletion ccstruct/publictypes.h
Expand Up @@ -30,7 +30,19 @@
// API-level code should include apitypes.h in preference to this file.

/** Number of printers' points in an inch. The unit of the pointsize return. */
const int kPointsPerInch = 72;
constexpr int kPointsPerInch = 72;
/**
* Minimum believable resolution. Used as a default if there is no other
* information, as it is safer to under-estimate than over-estimate.
*/
constexpr int kMinCredibleResolution = 70;
/** Maximum believable resolution. */
constexpr int kMaxCredibleResolution = 2400;
/**
* Ratio between median blob size and likely resolution. Used to estimate
* resolution when none is provided. This is basically 1/usual text size in
* inches. */
constexpr int kResolutionEstimationFactor = 10;

/**
* Possible types for a POLY_BLOCK or ColPartition.
Expand Down

0 comments on commit a18620c

Please sign in to comment.