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
$ cmake -DBUILD_SHARED_LIBS=OFF ..
$ 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(Mat.java:1467)
    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(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
    at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
    at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
    at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
    at java.lang.Thread.run(Thread.java:744)

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

edit retag flag offensive close merge delete

Comments

1

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 2.4.9.0 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]) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    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

System.load("absolutepath/to/dll_or_so")
holger gravatar imageholger ( 2018-05-29 01:45:16 -0600 )edit