OpenCV Java Ubuntu UnsatisfiedLinkError

asked 2014-02-06 10:55:18 -0600

ryanthejuggler gravatar image

I installed Oracle Java from WebUpd8 and am trying to get OpenCV working according to these instructions.

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install -y oracle-java7-installer oracle-java7-set-default build-essential cmake
$ sudo update-java-alternatives -s java-7-oracle
$ cd opencv/build
$ make
$ scala -cp /home/parallels/opencv/build/bin/opencv-248.jar -Djava.library.path=/home/parallels/opencv/build/lib
scala> import org.opencv.core._
scala> System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
scala> val m:Mat = Mat.eye(3,3,CvType.CV_8UC1)

As far as I can tell, this is correct, but I keep running into the following error:

java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_eye(III)J
    at org.opencv.core.Mat.n_eye(Native Method)
    at org.opencv.core.Mat.eye(
    at .<init>(<console>:10)
    at .<clinit>(<console>)
    at .<init>(<console>:11)
    at .<clinit>(<console>)
    at $print(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(

What could be causing this? How do I remedy this?

edit retag flag offensive close merge delete



I got this error in opencv android also and I discovered that I must create all my instances after I receive some callback from opencv. I used the onCameraPreview(not sure if this is this the correct name). It probably has something to do with multi-threading, meaning it's possible that Opencv lib isn't initialized by the time you are making the call to create the instance (not sure if this is the case, I am just guessing). Hope it helps.

andrei.toader gravatar imageandrei.toader ( 2014-02-10 05:44:56 -0600 )edit

I'm seeing the same thing on with scala 2.11.

I did manage to get compiled code to load it, however:

import org.opencv.core.Core
import org.opencv.core.Mat
import org.opencv.core.CvType
import org.opencv.core.Scalar

object SimpleSample {
  def main(args: Array[String]) {
    val m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));

$ scala -cp /usr/local/Cellar/opencv/2.4.9//share/OpenCV/java/opencv-249.jar:. 
-Djava.library.path=/usr/local/Cellar/opencv/2.4.9//share/OpenCV/java/ SimpleSample

But not in the repl :(.

riothamus gravatar imageriothamus ( 2014-07-29 13:51:33 -0600 )edit

Hmm - you could try loading the dll/so directly with an absolute path - for tracking down the problem

holger gravatar imageholger ( 2018-05-29 01:45:16 -0600 )edit