Skip to content

OCRParser: drop Tesseract 3 support, always use --psm - #2976

Merged
lfcnassif merged 2 commits into
sepinf-inc:masterfrom
edubraqd:fix/ocr-tesseract-version-check
Sep 24, 2026
Merged

lfcnassif merged 2 commits into
sepinf-inc:masterfrom
edubraqd:fix/ocr-tesseract-version-check

Conversation

@edubraqd

@edubraqd edubraqd commented Sep 14, 2026 •

Copy link
Copy Markdown

Problem

OCRParser's constructor decides between the legacy -psm and --psm with:

if (ENABLED && Integer.valueOf(tessVersion.charAt(0)) >= 4)

Integer.valueOf(char) boxes the character code, not the digit: '3' is 51, '5' is 53, so the condition is always true and --psm was already being used for every version.

There is also a crash path: checked.getAndSet(true) runs before checkVersionInfo, so when tesseract fails to run, the first instance throws the RuntimeException("Error running ...") and every later instance skips the version check and hits "".charAt(0) → StringIndexOutOfBoundsException.

Fix

As suggested in the review, drop Tesseract 3 support instead of fixing the check: the command uses --psm directly, the version-dependent block and the tessVersion field are removed. The detected version is still logged.

Test

No new test (code removed). Ran OCRParserTest on Windows with the tesseract 5.3.2 the test downloads: PNG, PDF and TIFF pass. testOCRParserPSD/testOCRParserSVG fail on master too on my machine (ImageMagick setup), unrelated.

🤖 Generated with Claude Code

@wladimirleite

Copy link
Copy Markdown
Member

Hi @edubraqd!
The version test condition is indeed wrong.
While the suggested changes would solve the issue, I would prefer dropping support for Tesseract <= 3. Tesseract 5 is already bundled with IPED (for Windows) and is old enough.
Dropping support for older versions will allow us to remove a few lines of legacy code and keep things simpler.

Integer.valueOf(tessVersion.charAt(0)) boxes the char code ('3' is 51),
so the check meant to keep "-psm" for Tesseract 3 was always true and
"--psm" was used for every version anyway. It also threw
StringIndexOutOfBoundsException from the constructor when tessVersion
was empty, which happens for every instance after the first one when
tesseract failed to run (checked is set before checkVersionInfo).

Tesseract 5 is bundled with IPED, so drop the version-dependent option
and pass "--psm" directly. The version is still logged.

Co-Authored-By: Claude Opus 5 <[email protected]>
@edubraqd
edubraqd force-pushed the fix/ocr-tesseract-version-check branch from 77200ed to 1bd45c2 Compare September 14, 2026 22:34
@edubraqd edubraqd changed the title OCRParser: parse tesseract major version correctly when choosing -psm/--psm OCRParser: drop Tesseract 3 support, always use --psm Sep 14, 2026
@edubraqd

Copy link
Copy Markdown
Author

Done: the branch now just passes --psm and removes the version check and the tessVersion field (the version is still logged). Title and description updated. If there are other Tesseract 3 leftovers you want gone in the same PR (I did not find any in OCRParser or the config files), point me to them.

Tesseract 3 printed the version banner to stderr; 4+ prints it to
stdout. Now that Tesseract <= 3 is not supported the stderr fallback
is dead code.

Co-Authored-By: Claude Opus 5 <[email protected]>
@edubraqd

Copy link
Copy Markdown
Author

One more Tesseract 3 leftover, removed in 66196f7: checkVersionInfo fell back to reading -v from stderr, which is where Tesseract 3 printed the banner (4+ prints it to stdout). Kept the v prefix strip in extractVersion, since some Windows builds still print tesseract v5.x. Nothing else in the repo depends on the version: outside OCRParser, tesseract only appears in config comments, the CI apt lines and the tesseract-zip bundle in iped-app/pom.xml.

@wladimirleite
wladimirleite self-requested a review September 19, 2026 16:47

@wladimirleite wladimirleite 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.

Code review and tests went fine.
Thanks @edubraqd!

@lfcnassif

Copy link
Copy Markdown
Member

Thanks @edubraqd and @wladimirleite!

@lfcnassif
lfcnassif merged commit 407356c into sepinf-inc:master Sep 24, 2026
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.

3 participants