Win7: Could not initialize class net.sourceforge.tess4j.Tesseract1?

Asked by Simon Plivav on 2020-05-20

Hi! I am new with Sikuli and Tesseract OCR; I like to recognise text using Sikuli OCR and Jython as
'strLast = OCR.readWord(regLastFallenNumber)', or
'strLast = regLastFallenNumber.text()'

I am running Sikuli 2.0.4-2020-03-14_08:01 / WINDOWS 6.1 (=Win7) 64bit / java version "1.8.0_251"; Sikuli automation works.

It fails with this for the OCR class call:
) raised: Traceback (most recent call last):
  File "<string>", line 14, in <module>
 at org.sikuli.script.TextRecognizer.getTesseractAPI(
 at org.sikuli.script.TextRecognizer.doRead(
 at org.sikuli.script.TextRecognizer.readText(
 at org.sikuli.script.OCR.readText(
 at org.sikuli.script.OCR.readWord(
 at org.sikuli.script.OCR.readWord(OCR
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.tess4j.Tesseract1"

So, I researched int internet and found about Tesseract that it "Windows: Works out of the box". So, why then the above message?

By the way, here the Jython I was using in the Sikuli IDE - also not sure that I am not mixing up concepts there...
    # OCR configuration
    import org.sikuli.script.TextRecognizer as STR # switch on the OCR feature
    optMySet = OCR.Options()
    optMySet.variable("user_defined_dpi", "112")
    #print optMySet

    Settings.OcrTextRead = True

    regLastFallenNumber = Region(425,292,48,21)
    strLast = OCR.readWord(regLastFallenNumber)
    #strLast = regLastFallenNumber.text()
    print strLast

Thanks a lot for your help :)


Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Simon Plivav (simpliv742) said : #1

Hi Raimund, I see that your are answering other usess' posts these days - is anything odd or unclear with my question? Should I rephrase it? I'm really stuck here since internet search does not yield anything on 'Could not initialize class net.sourceforge.tess4j.Tesseract1'.
I have 'C:\Users\User\AppData\Local\Temp\tess4j\win32-x86-64\libtesseract410.dll' present but it looks that the tess4j.jar is missing - there is no 'tess4j.jar' on C:\*. (Die Frage nochmal abstrakt formuliert: "Warum laeuft die Sch... nich'???")


Best RaiMan (raimund-hocke) said : #2

Sorry for the delay. Due to lack of time I concentrated on "easy" questions.

Es heißt übrigen "das SikuliX" und nicht "die SchikuliX" ;-)

Everything needed for Windows to run the OCR stuff in SikuliX is included in the jar.
That the class Tesseract1 cannot be initialised can only happen if there are problems with the libtesseract dll (e.g. needed libraries missing on your system).

So try to purge everything related to SikuliX besides the sikulix...jar (temp, app-data, ...).
Check the system path, that there is nothing that might irritate.

Try again.
As a test the one line
is sufficient.

I do not have access to a Win7 system, so I cannot help in detail.
But I will check, to see, wether more diagnostics might be possible to reveal.

Simon Plivav (simpliv742) said : #3

Hi & thanks for the suggestion on how it is supposed to work. I has success now by looking hard, instead of hardly as before, at the web page that opens with the error message, <>. Inferring another possible solution, I went then to install the 'Microsoft Visual C++ 2015 Redistributable' (vc_redist.x64.exe (v14.0.24212)) which did the trick!

regTest = Region(616,167,43,14)
strTest = OCR.readWord(regTest)
print strTest


Thanks a lot for your help!



Simon Plivav (simpliv742) said : #4

Thanks RaiMan, that solved my question.