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

Fast switch engines #15

Open
Friskes opened this issue Sep 6, 2024 · 2 comments
Open

Fast switch engines #15

Friskes opened this issue Sep 6, 2024 · 2 comments

Comments

@Friskes
Copy link

Friskes commented Sep 6, 2024

How can I switch back to Tesseract Engine without having to remove this plugin from env?

@Friskes
Copy link
Author

Friskes commented Sep 6, 2024

In general, I solved the problem, it would be cool to add such functionality to the library

if OCR_ENGINE == "TesseractOcrEngine":
    ocrmypdf_easyocr.initialize = None
    ocrmypdf_easyocr.check_options = None
    ocrmypdf_easyocr.optimize_pdf = None
    ocrmypdf_easyocr.add_options = None
    ocrmypdf_easyocr.get_ocr_engine = None

elif OCR_ENGINE == "EasyOCREngine":

    def extend_options(func):
        @hookimpl
        def check_options(options: Namespace):
            result = func(options)
            options.pdf_renderer = "sandwich"
            return result

        return check_options

    ocrmypdf_easyocr.check_options = extend_options(ocrmypdf_easyocr.check_options)

@jbarlow83
Copy link
Contributor

A cleaner approach would be to rewrite class EasyOCREngine to defer to TesseractOCREngine when disabled. If you create a PR with that effect I would accept it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants