Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirecting stdout to stderr when loading EasyOCR-Reader to be compliant with ocrmypdf #13

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ocrmypdf_easyocr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import logging
import multiprocessing.managers
import os
import sys
import contextlib
import threading
import traceback
from pathlib import Path
Expand Down Expand Up @@ -111,7 +113,12 @@ def _ocr_process(q: multiprocessing.Queue[Task], options):
if reader is None:
use_gpu = options.gpu
languages = [ISO_639_3_2[lang] for lang in options.languages]
reader = easyocr.Reader(languages, use_gpu)

# Redirect stdout to stderr during Reader initialization to be compliant with ocrmypdf
# otherwise piping a pdf output to stdout gets interfered with the progress bar of loading the model to ram
with contextlib.redirect_stdout(sys.stderr):
reader = easyocr.Reader(languages, use_gpu)

output_dict["output"] = reader.readtext(
gray, batch_size=options.easyocr_batch_size
)
Expand Down
Loading