← Back to DAGDA | Support | Source: https://github.com/tesseract-ocr/tesseract/pull/4651
Skip to content

Propagate min_characters_to_try to automatic OSD engine - #4651

Merged
stweil merged 3 commits into
tesseract-ocr:mainfrom
AryanRG:fix/min-characters-to-try-osd
Oct 19, 2026
Merged

stweil merged 3 commits into
tesseract-ocr:mainfrom
AryanRG:fix/min-characters-to-try-osd

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With --psm 1 or --psm 12 and a recognition language such as eng, TessBaseAPI creates a separate OSD engine. User variables are applied to the primary engine, so the OSD engine keeps the default min_characters_to_try=50 and ignores a configured lower value.

Change

  • copy min_characters_to_try into the separate OSD engine before page segmentation;
  • repeat the copy on each FindLines() call so changes made after the OSD engine is created also take effect;
  • add a regression test covering initial propagation and reuse of the same OSD engine on a second page.

Fixes #4212.

Validation

  • The new focused test failed before the production change with OSD values 50/50 instead of 1/2, then passed after the change.
  • A rebuilt CLI preserved the default Too few characters behavior for PSM 1 and 12 and removed that message for both modes with -c min_characters_to_try=1.
  • git diff --check passed.
  • The three existing focused test programs had the same outcomes before and after the change, apart from the new regression changing from failed to passing. A bounded local CTest run with a 20-second per-test timeout completed all 70 programs: 52 passed and 18 failed, crashed, or timed out. Those failures involve unavailable language/model data, local model setup limits, or the short timeout, so the local full suite is not green.

AI assistance

This change was prepared with AI assistance. AI agents assisted with diagnosis, implementation, testing, and automated review at the contributor's direction.

Propagate the configured minimum character count to the separate OSD engine used by automatic page segmentation. Add a regression test that also covers updates after the OSD engine has already been created.

Fixes #4212.

Assisted-by: Codex and Claude Opus 5.5
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity · 0 duplication

Metric Results
Complexity 5
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Comment thread unittest/baseapi_test.cc Resolved
Comment thread unittest/baseapi_test.cc Outdated
Tesseract *osd_tess = api.osd_tesseract();
if (osd_tess == nullptr) {
// osd.traineddata not found.
src_pix.reset();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the unique_ptr already handles cleanup here. Removed the reset.

@stweil stweil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@stweil
stweil merged commit 8d233e7 into tesseract-ocr:main Oct 19, 2026
7 checks passed
stweil pushed a commit that referenced this pull request Oct 19, 2026
* Fix min_characters_to_try for automatic OSD

Propagate the configured minimum character count to the separate OSD engine used by automatic page segmentation. Add a regression test that also covers updates after the OSD engine has already been created.

Fixes #4212.

Assisted-by: Codex and Claude Opus 5.5
stweil pushed a commit that referenced this pull request Oct 19, 2026
* Fix min_characters_to_try for automatic OSD

Propagate the configured minimum character count to the separate OSD engine
used by automatic page segmentation. Add a regression test that also covers
updates after the OSD engine has already been created.

Fixes #4212.

Assisted-by: Codex and Claude Opus 5.5
stweil pushed a commit that referenced this pull request Oct 19, 2026
* Fix min_characters_to_try for automatic OSD

Propagate the configured minimum character count to the separate OSD engine
used by automatic page segmentation. Add a regression test that also covers
updates after the OSD engine has already been created.

Fixes #4212.

Assisted-by: Codex and Claude Opus 5.5
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

Successfully merging this pull request may close these issues.

"min_characters_to_try" parameter does not work

2 participants