Add different timeout control for non-OCR

This is mainly to permit the use of --tesseract-timeout 0 as a way of
disabling OCR but still allowing deskew and orientation detection to work.

The better solution will be introducing an explicit argument to
"don't ocr my pdf", but that will take more rework.
This commit is contained in:
James R. Barlow
2023-04-13 23:59:58 -07:00
parent 5502fb8d9f
commit 1b2849ec0a
2 changed files with 20 additions and 9 deletions
+17 -4
View File
@@ -69,8 +69,21 @@ def add_options(parser):
default=180.0,
type=numeric(float, 0),
metavar='SECONDS',
help='Give up on OCR after the timeout, but copy the preprocessed page '
'into the final output',
help=(
"Give up on OCR after the timeout, but copy the preprocessed page "
"into the final output."
),
)
tess.add_argument(
'--tesseract-non-ocr-timeout',
default=180.0,
type=numeric(float, 0),
metavar='SECONDS',
help=(
"Give up on non-OCR operations such as deskewing and orientation "
"after timeout. This is a separate timeout from --tesseract-timeout "
"because these operations are not as expensive as OCR."
),
)
tess.add_argument(
'--user-words',
@@ -156,7 +169,7 @@ class TesseractOcrEngine(OcrEngine):
return tesseract.get_orientation(
input_file,
engine_mode=options.tesseract_oem,
timeout=options.tesseract_timeout,
timeout=options.tesseract_non_ocr_timeout,
)
@staticmethod
@@ -165,7 +178,7 @@ class TesseractOcrEngine(OcrEngine):
input_file,
languages=options.languages,
engine_mode=options.tesseract_oem,
timeout=options.tesseract_timeout,
timeout=options.tesseract_non_ocr_timeout,
)
@staticmethod
+3 -5
View File
@@ -11,13 +11,12 @@ from os import fspath
import img2pdf
import pikepdf
import pytest
from PIL import Image, ImageChops
from reportlab.pdfgen.canvas import Canvas
from ocrmypdf._exec import ghostscript
from ocrmypdf._plugin_manager import get_plugin_manager
from ocrmypdf.helpers import IMG2PDF_KWARGS, Resolution
from ocrmypdf.pdfinfo import PdfInfo
from PIL import Image, ImageChops
from reportlab.pdfgen.canvas import Canvas
from .conftest import check_ocrmypdf, run_ocrmypdf
@@ -190,8 +189,7 @@ def test_rotated_skew_timeout(resources, outpdf):
), "Expected page rotation to be baked in"
@pytest.mark.xfail(reason="tesseract timeout blocks tesseract based deskew")
def test_rotate_deskew_timeout(resources, outdir):
def test_rotate_deskew_ocr_timeout(resources, outdir):
check_ocrmypdf(
resources / 'rotated_skew.pdf',
outdir / 'deskewed.pdf',