Java在eclipse中调用opencv时报错:java.lang.UnsatisfiedLinkError的解决方法

昨天把Java+opencv的环境配置好后,迫不及待的进行测试......

出师不利....

第一个代码就有错误,代码如下:

import org.opencv.core.*;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.*;
public class opencvTest02 {

	public static void main(String[] args){
		String filename = "E:/test01.png";
		Mat imgMat = Highgui.imread(filename);
	}
}
报错如下:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_1(Ljava/lang/String;)J
	at org.opencv.highgui.Highgui.imread_1(Native Method)
	at org.opencv.highgui.Highgui.imread(Highgui.java:362)
	at com.lzw.opencvTest02.main(opencvTest02.java:10)
然后我就各种度,各种歌,各种找......无果!

然后又看了看测试代码:

import org.opencv.core.*;

public class opencvTest{
	
	public static void main(String[] args){

		System.out.println("Welcome to OpenCV" + Core.VERSION);
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
		Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
		System.out.println("m = " + m.dump());
	}
}
可以正常运行,然后我就把下边几行代码加到测试代码里边:

import org.opencv.core.*;
import org.opencv.highgui.Highgui;
public class opencvTest{
	
	public static void main(String[] args){

		System.out.println("Welcome to OpenCV" + Core.VERSION);
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
		Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
		System.out.println("m = " + m.dump());
                String filename = "E:/test01.png";
		Mat imgMat = Highgui.imread(filename);
 }}

 不报错!!! 
  

我又注释掉了

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
报错!!!

所以,你懂的:

程序里必须加

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
原因如下:

Java在eclipse中调用opencv时报错:java.lang.UnsatisfiedLinkError的解决方法_第1张图片


OpenCV API for JAVA的链接:docs.opencv.org/java/2.4.6/


你可能感兴趣的:(JAVA,opencv学习)