Repository navigation
OCRParser: drop Tesseract 3 support, always use --psm - #2976
Conversation
|
Hi @edubraqd! |
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]>
77200ed to
1bd45c2
Compare
|
Done: the branch now just passes |
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]>
|
One more Tesseract 3 leftover, removed in 66196f7: |
wladimirleite
left a comment
There was a problem hiding this comment.
Code review and tests went fine.
Thanks @edubraqd!
|
Thanks @edubraqd and @wladimirleite! |
Problem
OCRParser's constructor decides between the legacy-psmand--psmwith:Integer.valueOf(char)boxes the character code, not the digit:'3'is 51,'5'is 53, so the condition is always true and--psmwas already being used for every version.There is also a crash path:
checked.getAndSet(true)runs beforecheckVersionInfo, so when tesseract fails to run, the first instance throws theRuntimeException("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
--psmdirectly, the version-dependent block and thetessVersionfield are removed. The detected version is still logged.Test
No new test (code removed). Ran
OCRParserTeston Windows with the tesseract 5.3.2 the test downloads: PNG, PDF and TIFF pass.testOCRParserPSD/testOCRParserSVGfail onmastertoo on my machine (ImageMagick setup), unrelated.🤖 Generated with Claude Code