Ask Your Question
0

opencv 3.0.0 java problem on windows

asked 2015-06-12 07:30:03 -0600

ivanich gravatar image

I am getting the following exception:

 [java] Welcome to OpenCV 3.0.0, lib is: opencv_java300
     [java] Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.imgcodecs.Imgcodecs.imread_0(Ljava/lang/String;I)J
     [java]     at org.opencv.imgcodecs.Imgcodecs.imread_0(Native Method)
     [java]     at org.opencv.imgcodecs.Imgcodecs.imread(Imgcodecs.java:73)
     [java]     at SimpleSample.main(Unknown Source)
     [java] Java Result: 1

while trying to run this sample java code on Windows using opencv300 gold:

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

import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import org.opencv.imgcodecs.Imgcodecs;

class SimpleSample {

  static{
      System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
      //      System.loadLibrary("opencv_java300");
      //      System.loadLibrary("opencv_world300");
  }

  public static void main(String[] args) {
    System.out.println("Welcome to OpenCV " + Core.VERSION + ", lib is: " + Core.NATIVE_LIBRARY_NAME);

    long startTime = System.currentTimeMillis();

    Mat src = Imgcodecs.imread("src.pgm", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
    Mat template = Imgcodecs.imread("template.pgm", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
    Mat map = new Mat();

    System.err.println("Start matching...");

    Imgproc.matchTemplate(src, template, map, Imgproc.TM_CCOEFF_NORMED);
    System.err.println("Duration: " + (System.currentTimeMillis() - startTime));
  }
}

Any ideas why? 10x in advance

edit retag flag offensive close merge delete

Comments

are you running that from ant ? can you show, how you invoke it ?

berak gravatar imageberak ( 2015-06-14 01:06:06 -0600 )edit

Yes, I am using ant to compile and run it. I am calling ant from a cygwin console. It compiles fine, but can not execute. Below is a zip with the compiled project (build.xml included):

https://www.dropbox.com/s/vx17paggv8u...

I am using jdk1.7.0_71 which is set into the JAVA_HOME env variable.

Ant version is apache-ant-1.9.4 for windows

ivanich gravatar imageivanich ( 2015-06-15 02:20:29 -0600 )edit

It may of interest that this code compiles and runs perfectly on Linux ...

ivanich gravatar imageivanich ( 2015-06-15 02:22:54 -0600 )edit

yes, it's not the code. it can't find the opencv_java300.dll at runtime.

i.e, i'm invoking ant like:

ant -DocvJarDir=E:\code\opencv\build\bin -DocvLibDir=E:\code\opencv\build\bin\Release %*

so ocvLibDir has to point to the folder containing the dll

berak gravatar imageberak ( 2015-06-15 03:07:30 -0600 )edit

10x for Your reply. I tried the command line options above. In the standard installation of opencv300 for windows, the paths are slightly different, so the cmd line i had to type was:

"c:\Program Files\Java\jdk1.7.0_71\jre\bin\java" -cp "C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\opencv-300.jar" -DocvLibDir="c:\ocv3\opencv\build\java\x64" -DocvJarDir="c:\ocv3\opencv\build\java" -jar SimpleSample.jar

That gives the same error. In addition I tried adding the opencv_java300.dll dir into the global PATH variable, as well as opencv\build\x64\vc12\bin. Restarted the shell afterwards. Did not help.

I grepped both opencv_java300.dll and opencv_world300.dll for a symbol named imread_0 and did not find it. Any ideas why?

ivanich gravatar imageivanich ( 2015-06-15 05:48:10 -0600 )edit

hmm, above cmdline is calling java directly, not via the ant shell, right ? the ocvLibDir and ocvJarDir vars are for ant, and are not recognized from java

berak gravatar imageberak ( 2015-06-15 10:22:08 -0600 )edit

Ok. I tried this also with ant, no effect. Correct me if I am wrong, but is it not enough to place the required DLLs into the PATH system variable (via Control Panel/System/Environment Variables)? I am sure, opencv_java300.dll and opencv_world300.dll are reachable, since I can call other methods contained in those DLLs.

If I am not using ant, but (for the sake of simplicity) directly call java -jar SimpleSample.jar, what other cmd-line params do I need?

10x in advance ...

ivanich gravatar imageivanich ( 2015-06-16 02:08:06 -0600 )edit

unfortunately, the only way i found to use java directly(without using ant) was

System.load("d:/opencv/bin/release/opencv_java300.dll");

(which ofc. is non-portable)

berak gravatar imageberak ( 2015-06-16 02:10:45 -0600 )edit

Tried that. The code now contains the following two lines at the beginning of the main function:

System.load("c:\\ocv3\\opencv\\build\\java\\x64\\opencv_java300.dll");
System.load("c:\\ocv3\\opencv\\build\\x64\\vc12\\bin\\opencv_world300.dll");

They pass successfully, but the error (imread_0 link error) remains. What next?

ivanich gravatar imageivanich ( 2015-06-16 02:40:45 -0600 )edit

btw. System.loadLibrary would do the same thing as System.load but in a portable way ...

ivanich gravatar imageivanich ( 2015-06-16 02:45:10 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-1

answered 2016-01-03 04:27:01 -0600

let me end this question ,because the location of "template.pgm" is wrong. you should put it on project root Directory

edit flag offensive delete link more

Comments

i'm not sure, if this answers the question

berak gravatar imageberak ( 2016-01-03 04:35:38 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2015-06-12 07:30:03 -0600

Seen: 6,598 times

Last updated: Jun 12 '15