- 具体错误
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:402)
- 解决办法
使用System.load()手动加载本地(dll/so/dylib)库。
如果使用System.loadLibrary(),则要保证java.library.path中要有包含本地库的目录。
package taishan;
import java.io.File;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class OpenCVTest
{
private final static String KEY_LIB_PATH = "java.library.path";
private final static String NATIVE_DIR="D:\\OpenCVTest\\lib";
static
{
System.out.println(System.getProperty(KEY_LIB_PATH));
String fileName = NATIVE_DIR+"\\"+Core.NATIVE_LIBRARY_NAME+".dll";
File dll = new File(fileName);
System.out.println(Core.NATIVE_LIBRARY_NAME+" exist ? "+dll.exists());
if (dll.exists())
{
System.load(fileName);
//System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
}
public static void main(String[] args)
{
Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("mat = "+mat.dump());
}
}
- 输出结果:
D:\Office-3.5-project\Office-3.5\tsjdk8-bin;.
opencv_java420 exist ? true
mat = [ 1, 0, 0;
0, 1, 0;
0, 0, 1]
- 分析结果很奇怪
出错是在modules/core/misc/java/src/java/core+Mat.java。
搜索n_eye,确实没有这个函数
实际上结果确实是对的。