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:
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user