opencv 3.0.0 java problem on windows
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
are you running that from ant ? can you show, how you invoke it ?
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
It may of interest that this code compiles and runs perfectly on Linux ...
yes, it's not the code. it can't find the opencv_java300.dll at runtime.
i.e, i'm invoking ant like:
so ocvLibDir has to point to the folder containing the dll
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?
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
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 ...
unfortunately, the only way i found to use java directly(without using ant) was
(which ofc. is non-portable)
Tried that. The code now contains the following two lines at the beginning of the main function:
They pass successfully, but the error (imread_0 link error) remains. What next?
btw. System.loadLibrary would do the same thing as System.load but in a portable way ...