[2.0.4]sikulixapi with java 11 on maxOS M1: problems using OCR features (Tesseract lib missing)

Asked by Juliana XIAO

I have 7 maxOS test machines, 6 of them are macOS Big Sur and they all working well with sikulixapi 2.0.4 OCR feature. But 1 machine is macOS Monterey which uses Apple M1 Chip and all the libraries are under different location. I can find "/usr/local/opt/leptonica/lib/liblept.5.dylib" on the other 6 test machines, but on this machine I find it is located under "/opt/homebrew/Cellar/leptonica/1.82.0/lib/liblept.5.dylib". Basically, I found all the brew installed libraries under "/usr/local/Cellar" on those 6 machines are under "/opt/homebrew/Cellar" on this one special machine. So that when I run test on that special machine from eclipse it gives me the following error:
************************************************************************
org.sikuli.script.SikuliXception: OCR: start: Tesseract library problems: dlopen(/Users/rr_admin/Library/Caches/JNA/temp/jna12082671447273670762.tmp, 0x0009): Library not loaded: /usr/local/opt/leptonica/lib/liblept.5.dylib
  Referenced from: /Users/rr_admin/Library/Caches/JNA/temp/jna12082671447273670762.tmp
  Reason: tried: '/usr/local/opt/leptonica/lib/liblept.5.dylib' (no such file), '/usr/lib/liblept.5.dylib' (no such file)
 at org.sikuli.script.TextRecognizer.getTesseractAPI(TextRecognizer.java:111)
 at org.sikuli.script.TextRecognizer.doRead(TextRecognizer.java:350)
 at org.sikuli.script.TextRecognizer.readText(TextRecognizer.java:309)
 at org.sikuli.script.OCR.readText(OCR.java:691)
 at org.sikuli.script.OCR.readText(OCR.java:679)
 at org.sikuli.script.Element.text(Element.java:147)
 at com.pyrsoftware.av.client.desktop.mac.SikuliScreen.grabTextOnRight(SikuliScreen.java:203)
 at com.pyrsoftware.av.client.desktop.helpers.SikulixHelper.parseVersion(SikulixHelper.java:106)
**************************************************************************
Is there any workaround for this?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
RaiMan (raimund-hocke) said (last edit ):
#1

You have to understand the Homebrew concept for macOS M1 machines (see Home-brew docs).

In 2.0.6 (only snapshots available at the moment) I try to reflect all specific aspects of macOS M1 with respect to SikuliX

The snippets from 2.0.6 are only to give you some insights about what you would have to do in your wrapper.
Setting the jna-path correctly is the key feature.

     if (Commons.runningMac()) {
        String libPath = "/usr/local/lib";
        if (Commons.runningMacM1()) {
          libPath = "/opt/homebrew/lib";
        }
        File libTess = new File(libPath, "libtesseract.dylib");
        if (libTess.exists()) {
          Commons.jnaPathAdd(libPath); //----------------------------- add the path
        } else {
          throw new SikuliXception(String.format("OCR: validate: libtesseract.dylib not in %s", libPath));
        }
      }

// the respective method from Commons:

  public static String jnaPathAdd(String sFolder) {
    String jnaPath = System.getProperty("jna.library.path");
    if (null == jnaPath) {
      jnaPath = "";
    }
    File folder = new File(sFolder);
    if (!folder.exists()) {
      return null;
    }
    if (!jnaPath.isEmpty()) {
      jnaPath = File.pathSeparator + jnaPath;
    }
    jnaPath = folder.getAbsolutePath() + jnaPath;
    System.setProperty("jna.library.path", jnaPath);
    return jnaPath;
  }

Revision history for this message
Juliana XIAO (juliana-x) said :
#2

Hi! Raiman,

Thanks for this quick reply. What I understand is that I'd better wait for 2.0.6 in order to use this machine, right?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

It would be helpful if you try with the actual snapshot 2.0.6 from today.

Waiting for the final release does not change your situation:
On macOS M1 you will always need a valid Homebrew setup or a symlink for libtesseract.dylib in a folder /opt/homebrew/lib.

The actual snapshot and hence the final version needs Tesseract 5.0.1

Revision history for this message
Juliana XIAO (juliana-x) said :
#4

Hi! RaiMan,

Could you please let me know where to download actual snapshot 2.0.6 and how to use it?

Thanks,
Juliana

Revision history for this message
RaiMan (raimund-hocke) said :
#5
Revision history for this message
Juliana XIAO (juliana-x) said :
#6
Revision history for this message
Juliana XIAO (juliana-x) said :
#7

Hi! RaiMan,

I found the 2.0.6 jar file but it is sikulixide jar file. Where can I find sikulixapi jar file so that I can run my test case written in java from eclipse?

Revision history for this message
RaiMan (raimund-hocke) said :
#8

Maven coordinates:
com.sikulix::sikulixapi::2.0.6-SNAPSHOT
from
snapshot-repo OSSRH

Revision history for this message
Juliana XIAO (juliana-x) said :
#9

Hi! RaiMan,

I have a Gradle java project and in build.gradle file I put the following line
api "com.sikulix.sikulixapi:2.0.6-SNAPSHOT:2.0.6"
I got the following issue:
Could not resolve: com.sikulix.sikulixapi:2.0.6-SNAPSHOT:2.0.6

If I put
api "com.sikulix:sikulixapi:2.0.6-SNAPSHOT"
I got following issue:
Could not resolve: com.sikulix:sikulixapi:2.0.6-SNAPSHOT

I don't know how to make it work in my Gradle java project. Could you please help?

Revision history for this message
RaiMan (raimund-hocke) said :
#10

Sorry, no Gradle experience.

Correct should be:
com.sikulix:sikulixapi:2.0.6-SNAPSHOT

But I guess (as with Maven) you have to tell Gradle about the snapshot repository on OSSRH:

 <repositories>
    <repository>
      <id>OSSRH</id>
      <snapshots></snapshots>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
  </repositories>

This is for Maven, but there surely is a similar option with Gradle.

Revision history for this message
Juliana XIAO (juliana-x) said :
#11

Hi! RaiMan,

I just tried this yesterday and made it work with following build.gradle configuration. Both options are working fine: Sikuli can find images and do the click.
Option1:
*************************************
repositories {
 maven {
  url = 'https://oss.sonatype.org/content/repositories/snapshots'
 }
}
dependencies {
 api(group: 'com.sikulix', name: 'sikulixapi', version: '2.0.6-SNAPSHOT')
}
*************************************

Option2:
*************************************
repositories {
 maven {
  url = 'https://oss.sonatype.org/content/repositories/snapshots'
 }
}
dependencies {
 compile "com.sikulix:sikulixapi:2.0.6-SNAPSHOT"
}
*************************************

But I encountered a new issue: when I tried to recognize text from an image using the following code:
screen.find(new Pattern(imageFileName).similar((float) similarity).targetOffset(image.getOffsetX(),
          image.getOffsetY())).right(offset).text().trim()
I got the following error:
*************************************
org.sikuli.script.SikuliXception: OCR: validate: libtesseract.dylib not in /usr/local/lib
 at org.sikuli.script.TextRecognizer.get(TextRecognizer.java:87)
 at org.sikuli.script.OCR.readText(OCR.java:722)
 at org.sikuli.script.OCR.readText(OCR.java:707)
 at org.sikuli.script.Element.text(Element.java:1155)
*************************************
I found the actual location is "/opt/homebrew/Cellar/tesseract/5.0.1/lib/libtesseract.dylib". Could you please help?

Thanks,
Juliana

Revision history for this message
RaiMan (raimund-hocke) said :
#12

--- I found the actual location is "/opt/homebrew/Cellar/tesseract/5.0.1/lib/libtesseract.dylib".
This is we're the stuff is built and made ready.
finally there are symlinks created in /opt/homebrew/lib (brew link ...). there should be a libtesseract.dylib as symlink.
See comment #1.

Revision history for this message
John Klein (johnklein94) said :
#13

Szczerze mówiąc, kasyno jest wątpliwym źródłem dochodu, ale ja się z tym nie zgadzam. Według szczerych recenzji Vulkan Vegas logowanie casino (https://kasyno-vulkan-vegas.com/logowanie/) stoi już od dłuższego czasu. Jeśli szukałeś najlepszego kasyna to znak, że je znalazłeś.

Can you help with this problem?

Provide an answer of your own, or ask Juliana XIAO for more information if necessary.

To post a message you must log in.