Fix tesseract_ocr.py errors

This commit is contained in:
James R. Barlow
2020-06-01 02:27:27 -07:00
parent aa060db5bc
commit 6528234608
2 changed files with 7 additions and 1 deletions
+1
View File
@@ -36,5 +36,6 @@ from ocrmypdf.exceptions import (
TesseractConfigError,
UnsupportedImageFormatError,
)
from ocrmypdf.pluginspec import OcrEngine, OrientationConfidence
hookimpl = _HookimplMarker('ocrmypdf')
@@ -120,8 +120,11 @@ def check_options(options):
@hookimpl
def validate(pdfinfo, options):
if not options.tesseract_env:
return
# If we are running a Tesseract spoof, ensure it knows what the input file is
if os.environ.get('PYTEST_CURRENT_TEST') and options.tesseract_env:
if os.environ.get('PYTEST_CURRENT_TEST'):
options.tesseract_env['_OCRMYPDF_TEST_INFILE'] = os.fspath(options.input_file)
# Tesseract 4.x can be multithreaded, and we also run multiple workers. We want
@@ -135,6 +138,8 @@ def validate(pdfinfo, options):
if not options.tesseract_env.get('OMP_THREAD_LIMIT', '').isnumeric():
tess_threads = min(3, options.jobs // len(pdfinfo), len(pdfinfo))
options.tesseract_env['OMP_THREAD_LIMIT'] = str(tess_threads)
else:
tess_threads = int(options.tesseract_env['OMP_THREAD_LIMIT'])
if tess_threads > 1:
log.info("Using Tesseract OpenMP thread limit %d", tess_threads)