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 :
1.1.4-SNAPSHOT-#393-2019-10-10_16:07/Windows10.0/Java8(64)1.8.0_221-b27
When I try to run this script (that is used t find the best OCR setting for an image):

textOCR = TextOCR.start()
i=0
img=selectRegion()
while i<14:
    textOCR.setPSM(i)
    print "i="+str(i) +", text=" +"\n" + img.text().encode('utf-8')
    i=i+1
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:
1.1.4-SNAPSHOT-#287-2019-04-18_07:09/Windows10.0/Java8(64)1.8.0_221-b27
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
c:\Users\Myself\AppData\Roaming\Sikulix
folder just to avoid doubts and used Jythonb 2.7.1 standalone

Any hint to overcome this problem?
Thanks in advance!
Matteo
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

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2019-10-11
Last query:
2019-10-11
Last reply:
2019-10-11
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

Hello,
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()
i=0
img=selectRegion()
listOfSetting=[2,3,4,5,6,7,8,9,10,11,13]
iIdx=0
for i in range (0,11):
#while i<14:
    textOCR.setPSM(listOfSetting[i])
    print "Setting="+str(listOfSetting[i]) +", text=" +"\n" + img.text().encode('utf-8')
    i=i+1
textOCR.setPSM(3)#return to default

matteoa (matteoa) said : #3

Thanks RaiMan, that solved my question.