From ed4c4c6bf5599f8ec42e03dbbb5cde5c5a6f9d14 Mon Sep 17 00:00:00 2001 From: Jeff Breidenbach Date: Wed, 7 Dec 2016 22:03:28 +0100 Subject: [PATCH] Produce warning for invalid resolution. Fix #453 --- api/baseapi.cpp | 2 ++ ccmain/osdetect.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/api/baseapi.cpp b/api/baseapi.cpp index b24742435f..d9bc1f9d9a 100644 --- a/api/baseapi.cpp +++ b/api/baseapi.cpp @@ -2223,6 +2223,8 @@ void TessBaseAPI::Threshold(Pix** pix) { if (y_res < kMinCredibleResolution || y_res > kMaxCredibleResolution) { // 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, kMinCredibleResolution); thresholder_->SetSourceYResolution(kMinCredibleResolution); } PageSegMode pageseg_mode = diff --git a/ccmain/osdetect.cpp b/ccmain/osdetect.cpp index f2fe94a1c3..69e626222f 100644 --- a/ccmain/osdetect.cpp +++ b/ccmain/osdetect.cpp @@ -164,8 +164,14 @@ void remove_nontext_regions(tesseract::Tesseract *tess, BLOCK_LIST *blocks, int vertical_y = 1; tesseract::TabVector_LIST v_lines; tesseract::TabVector_LIST h_lines; - int resolution = (kMinCredibleResolution > pixGetXRes(pix)) ? - kMinCredibleResolution : pixGetXRes(pix); + int resolution; + if (kMinCredibleResolution > pixGetXRes(pix)) { + resolution = kMinCredibleResolution; + tprintf("Warning. Invalid resolution %d dpi. Using %d instead.\n", + pixGetXRes(pix), resolution); + } else { + resolution = pixGetXRes(pix); + } tesseract::LineFinder::FindAndRemoveLines(resolution, false, pix, &vertical_x, &vertical_y,