OCR: setPSM with 0, 1, 12 are crashing --- OSD is not supported

Asked by matteoa on 2019-10-11

------------------- so do not use it


Hello all,
with last version of Sikulix :
When I try to run this script (that is used t find the best OCR setting for an image):

textOCR = TextOCR.start()
while i<14:
    print "i="+str(i) +", text=" +"\n" + img.text().encode('utf-8')
textOCR.setPSM(3)#return to default

I have this error:
[error] script [ OcrSettingTEst ] stopped with error in line 6
[error] org.sikuli.script.SikuliXception ( org.sikuli.script.SikuliXception: fatal: TextRecognizer: setPSM(0): needs OSD, but no osd.traineddata found in tessdata folder )
[error] --- Traceback --- error source first
line: module ( function ) statement
6: main ( <module> ) textOCR.setPSM(i)
[error] --- Traceback --- end --------------

I tested with a rather old version:
On the same script and image and the output is as expected (text extracted from the image with all the 13 different settings.

Between switching between the version I deleted the
folder just to avoid doubts and used Jythonb 2.7.1 standalone

Any hint to overcome this problem?
Thanks in advance!
P.s BTW, the current version of tesseract inside Sikulix is 3 or 4?
...I found this in the file versionchanges.txt of the downloaded package:
Version 4.4.0 (13 July 2019)
- Upgrade to Tesseract 4.1.0 (5280bbc)
- Upgrade to Leptonica 1.78.0 (lept4j-1.12.2)
- Update dependencies

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Best RaiMan (raimund-hocke) said : #1

We have removed the OSD support (not relevant in the SikuliX context)

hence the PSM's 0, 1, 12 throw this error now.

On the other hand, it does not make sense, to loop through the PSM's.
You should select what is suitable in your situation or just work with the default 3.

   * Page segmentation modes:
   * 0 Orientation and script detection (OSD) only.
   * 1 Automatic page segmentation with OSD.
   * 2 Automatic page segmentation, but no OSD, or OCR.
   * 3 Fully automatic page segmentation, but no OSD. (Default)
   * 4 Assume a single column of text of variable sizes.
   * 5 Assume a single uniform block of vertically aligned text.
   * 6 Assume a single uniform block of text.
   * 7 Treat the image as a single text line.
   * 8 Treat the image as a single word.
   * 9 Treat the image as a single word in a circle.
   * 10 Treat the image as a single character.
   * 11 Sparse text. Find as much text as possible in no particular order.
   * 12 Sparse text with OSD.
   * 13 Raw line. Treat the image as a single text line, bypassing hacks that are Tesseract-specific.

Sorry, but the docs are a bit behind.

We use Tess4J 4.4.x with Tesseract 4.1.x

matteoa (matteoa) said : #2

the script I've done was because for some image class I had some OCR problem with the default setting and I did not know which was the best PSM setting, this one was a script used to find the best PSM setting and then apply it to the "real" script...
Thanks for information!
Now it works
Thanks for prompt support!

BTW I modified the script, i paste it in case it would be helpful for someone:
textOCR = TextOCR.start()
for i in range (0,11):
#while i<14:
    print "Setting="+str(listOfSetting[i]) +", text=" +"\n" + img.text().encode('utf-8')
textOCR.setPSM(3)#return to default

matteoa (matteoa) said : #3

Thanks RaiMan, that solved my question.