From 1a5146abc9dbd4ed9d08da186695fbbcb07814a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EB=AC=BC=EA=B2=B0?= Date: Wed, 5 Nov 2025 03:32:41 +0900 Subject: [PATCH] fix(ocr): use PSM integer values directly instead of constructor (#2578) * fix(ocr): use PSM integer values directly instead of constructor - Use integer psm value directly instead of calling tesserocr.PSM() - Fixed in both main_psm and script_readers initialization - tesserocr.PSM is a class with integer constants, not an enum Fixes #2576 * DCO Remediation Commit for mulgyeol I, mulgyeol , hereby add my Signed-off-by to this commit: da63a17a3caeac533837022ca9c110fdb8c14651 Signed-off-by: mulgyeol --------- Signed-off-by: mulgyeol --- docling/models/tesseract_ocr_model.py | 6 ++---- tests/test_e2e_ocr_conversion.py | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docling/models/tesseract_ocr_model.py b/docling/models/tesseract_ocr_model.py index be828c59..e9d919e2 100644 --- a/docling/models/tesseract_ocr_model.py +++ b/docling/models/tesseract_ocr_model.py @@ -97,9 +97,7 @@ class TesseractOcrModel(BaseOcrModel): # Set main OCR reader with configurable PSM main_psm = ( - tesserocr.PSM(self.options.psm) - if self.options.psm is not None - else tesserocr.PSM.AUTO + self.options.psm if self.options.psm is not None else tesserocr.PSM.AUTO ) if lang == "auto": self.reader = tesserocr.PyTessBaseAPI(psm=main_psm, **tesserocr_kwargs) @@ -195,7 +193,7 @@ class TesseractOcrModel(BaseOcrModel): tesserocr.PyTessBaseAPI( path=self.reader.GetDatapath(), lang=lang, - psm=tesserocr.PSM(self.options.psm) + psm=self.options.psm if self.options.psm is not None else tesserocr.PSM.AUTO, init=True, diff --git a/tests/test_e2e_ocr_conversion.py b/tests/test_e2e_ocr_conversion.py index 8a25bf95..22c46738 100644 --- a/tests/test_e2e_ocr_conversion.py +++ b/tests/test_e2e_ocr_conversion.py @@ -63,6 +63,7 @@ def test_e2e_conversions(): (TesseractOcrOptions(), True), (TesseractCliOcrOptions(), True), (EasyOcrOptions(), False), + (TesseractOcrOptions(psm=3), True), (TesseractOcrOptions(force_full_page_ocr=True), True), (TesseractOcrOptions(force_full_page_ocr=True, lang=["auto"]), True), (TesseractCliOcrOptions(force_full_page_ocr=True), True),