fix(ocr): make the OCR render scale configurable instead of hardcoded#3877
Open
Anai-Guo wants to merge 1 commit into
Open
fix(ocr): make the OCR render scale configurable instead of hardcoded#3877Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
Contributor
|
✅ DCO Check Passed Thanks @Anai-Guo, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Every local OCR engine hardcoded `self.scale = 3`, so pages were always rendered at 216 DPI before OCR. For sources that are already high resolution this upscaling degrades recognition, and there was no way to turn it down short of editing the model class. Add a `scale` field to the shared `OcrOptions` base (default 3.0, so behaviour is unchanged) and have the EasyOCR, RapidOCR, ocrmac, Nemotron and both Tesseract engines read it. This mirrors the existing `KserveV2OcrOptions.scale` and `PictureDescriptionBaseOptions.scale`. Fixes docling-project#3866 Signed-off-by: Anai-Guo <antai12232931@outlook.com> Assisted-by: Claude
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3866
Problem
Every local OCR engine hardcoded its render scale:
so pages are always upscaled to 216 DPI before being handed to the OCR engine. As reported in #3866, that is the wrong default for sources that are already high resolution: the reporter's clean flattened-acroform image OCR'd correctly with
tesseractdirectly, but produced errors through Docling — and the errors disappeared when the temp image was not enlarged. There was no way to change this short of editing the model class.Change
Add a
scalefield to the sharedOcrOptionsbase and have the engines readself.options.scaleinstead of the literal:EasyOcrModelRapidOcrModelOcrMacModelNemotronOcrModelTesseractOcrModel(tesserocr)TesseractOcrCliModelThe default is
3.0, so behaviour is unchanged for anyone who does not set it.gt=0.0rejects a zero/negative scale at validation time.This follows the pattern already used elsewhere in the codebase —
KserveV2OcrOptions.scaleandPictureDescriptionBaseOptions.scaleare both configurable float multipliers.KserveV2OcrOptionskeeps its own2.0default via the existing override.The one non-mechanical edit is
NemotronOcrModel._to_bounding_rect, whosescale: intparameter annotation becomesscale: floatsotystays happy.Verification
ruff@0.15.12 check/format --checkclean on the changed files (pinned pre-commit version).test_ocr_scale_is_configurableintests/test_options.py, which asserts the default stays3.0, that a custom scale reaches the model instance, and thatscale=0is rejected. Run against a local build:A dynamic "figure out the effective resolution automatically" heuristic — the reporter's stretch suggestion — is deliberately left out of scope here; this PR only removes the hardcode.
🤖 Generated with Claude Code