Skip to content

macOS Linux: Support Libraries for OpenCV 4

Raimund Hocke edited this page Oct 21, 2019 · 9 revisions

This information applies to SikuliX 2.1.0-SNAPSHOT (builds #400+, snapshots from 2019-10-21+)

If you got here automatically, then you have tried to use one of the SikuliX image search or text OCR features and got an error telling you, that the library libopencv is missing or has problems with dependencies.

In the IDE it looks something like this:

[error] RunTime:loadLib: libopencv_java.dylib (failed) probably dependent libs missing:
/Users/raimundhocke/Library/Application Support/Sikulix/SikulixLibs/libopencv_java.dylib: dlopen(/Users/raimundhocke/Library/Application Support/Sikulix/SikulixLibs/libopencv_java.dylib, 1): Library not loaded: @rpath/libopencv_ml.4.1.dylib
  Referenced from: /Users/raimundhocke/Library/Application Support/Sikulix/SikulixLibs/libopencv_java.dylib
  Reason: image not found
[error] Save your work, correct the problem and restart the IDE!
[error] see: https://github.com/RaiMan/SikuliX1/wiki/macOS-Linux:-Support-Libraries-for-OpenCV-4
TERMINATING: problem with native library: libopencv_java.dylib
[error] script [ testText ] stopped with error in line 2
[error] java.lang.ExceptionInInitializerError ( java.lang.ExceptionInInitializerError )
[error] --- Traceback --- error source first
line: module ( function ) statement 
2: main (  <module> )     tr = TextOCR.start()
[error] --- Traceback --- end --------------

The reason behind: The native libraries of the OpenCV package are no longer bundled with SikuliX, but have to be installed on macOS and Linux by the SikuliX user himself.

With SikuliX 2.1.0 you need the libraries OpenCV version 4.1.x


OpenCV for macOS


A little background: Only the library opencv_java.dylib (bridge from Java to the openCV feature libraries) is bundled as a convenience, since currently in the net it is not available ready to install and is a bit complex to create. So only the openCV feature libraries have to be installed by the SikuliX user himself.

Recommendation: install Homebrew as package manager, which should not make any problems on recent macOS versions (tested with success on macOS 10.13+).

Get the OpenCV package installation by just running this in a Terminal window:

brew install opencv

After successful installation of opencv, try again with SikuliX.

This might work as well with other package managers like MacPorts, Finch, ..., but is not tested.

... and of course you can do it by building from the sources.


OpenCV for Linux


You have to check, wether for your Linux flavour a package OpenCV is available, that provides the version 4.1.x libraries. Make sure a link to the libopencv_java.so is available in your loader path.

In doubt you have to provide it by building from the sources.

The following applies to and is tested with Ubuntu 18.04

to be continued ...

You can’t perform that action at this time.