From 8a8d515933bf46d2c8b496baf33adc87bf3adf94 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 11 Jun 2026 00:21:39 -0700 Subject: [PATCH] feat: surface raw Tesseract diacritics message at debug level When Tesseract reports a page with many diacritics, OCRmyPDF rewrites the message to "lots of diacritics - possibly poor OCR", which hid the original wording. Keep the interpreted hint but also emit Tesseract's raw line at debug verbosity (-v 1) so users can see exactly what Tesseract reported. Closes #1566. --- docs/releasenotes/version17.md | 4 ++++ src/ocrmypdf/_exec/tesseract.py | 4 ++++ tests/test_tesseract.py | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/docs/releasenotes/version17.md b/docs/releasenotes/version17.md index 546e966d..92ad5b0f 100644 --- a/docs/releasenotes/version17.md +++ b/docs/releasenotes/version17.md @@ -76,6 +76,10 @@ OCRmyPDF now also logs which rasterizer rendered each page at debug verbosity (``-v 1``), and the ``--rasterizer`` help text explains the OCR-quality trade-off, to make such reports easier to diagnose. {issue}`1439` +- When Tesseract reports a page with many diacritics, OCRmyPDF still logs its + interpreted "lots of diacritics - possibly poor OCR" hint, but now also emits + Tesseract's raw message at debug verbosity (``-v 1``) so the original wording + is available for diagnosis. {issue}`1566` ## v17.5.0 diff --git a/src/ocrmypdf/_exec/tesseract.py b/src/ocrmypdf/_exec/tesseract.py index 861f2d50..0ff118b0 100644 --- a/src/ocrmypdf/_exec/tesseract.py +++ b/src/ocrmypdf/_exec/tesseract.py @@ -297,6 +297,10 @@ def tesseract_log_output(stream: bytes) -> None: continue elif 'diacritics' in line: tlog.warning("lots of diacritics - possibly poor OCR") + # Surface the raw Tesseract message at debug level so users can see + # exactly what Tesseract reported (e.g. the affected count) without + # losing the interpreted hint above (#1566). + tlog.debug(line.strip()) elif line.startswith('OSD: Weak margin'): tlog.warning("unsure about page orientation") elif 'Error in pixScanForForeground' in line: diff --git a/tests/test_tesseract.py b/tests/test_tesseract.py index c7cc2bb3..30d3dfef 100644 --- a/tests/test_tesseract.py +++ b/tests/test_tesseract.py @@ -141,6 +141,14 @@ def test_tesseract_log_output(caplog, in_, logged): assert logged in caplog.text +def test_tesseract_log_output_diacritics_raw(caplog): + """Diacritics branch keeps the interpreted hint and surfaces raw (#1566).""" + caplog.set_level(logging.DEBUG) + tesseract.tesseract_log_output(b'lots of diacritics blah blah') + assert 'possibly poor OCR' in caplog.text # interpreted hint retained + assert 'lots of diacritics blah blah' in caplog.text # raw message surfaced + + def test_tesseract_log_output_raises(caplog): with pytest.raises(tesseract.TesseractConfigError): tesseract.tesseract_log_output(b'parameter not found: moo')