Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_highgui in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1088) at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711) at com.googlecode.javacpp.Loader.load(Loader.java:586) at com.googlecode.javacpp.Loader.load(Loader.java:540) at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:79) at com.cn.main.ReadImage.main(ReadImage.java:17) Caused by: java.lang.UnsatisfiedLinkError: C:UsersAdministratorAppDataLocalTempjavacpp97080304735100jniopencv_highgui.dll: Can't find dependent libraries at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851) at java.lang.Runtime.load0(Runtime.java:795) at java.lang.System.load(System.java:1062) at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:700) ... 4 more
问题原因:opencv和javacv版本不一致导致的,
opencv版本是2.4.6.0,javacv是0.6
javacv0.7对应的windows版本:opencv2.4.8.exe
版本不一致
opencv download:
http://opencv.org/downloads.html
http://wiki.opencv.org.cn/index.php/Download
经过长时间的学习,本人找到了一个新的版本,能够很好的解决之前版本的问题。
使用更高版本,这样就像使用其他资源库一样。
首先是pom.xml
<!-- https://mvnrepository.com/artifact/org.bytedeco/javacv --> <dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv</artifactId> <version>1.2</version> </dependency>
这里告诉大家一个查询依赖包的方法,屡试不爽。由于国内使用谷歌浏览器不方便,可以使用谷歌镜像,输入 mevan javacv dependency ,即可搜索到。
然后,给出一个demo
//扩张,将目标的边缘的“毛刺”踢除掉 public static void morphology_Dilation(String filename,int dilation_elem) { CvMat src, dilation_dst; src = cvLoadImageM(filename); dilation_dst=src; int dilation_type=CV_SHAPE_RECT; if( dilation_elem == 0 ){ dilation_type = CV_SHAPE_RECT; } else if( dilation_elem == 1 ){ dilation_type = CV_SHAPE_CROSS; } else if( dilation_elem == 2) { dilation_type = CV_SHAPE_ELLIPSE; } // CvMat element = cvGetStructuringElement( dilation_type, // cvSize( 2*1 + 1, 2*1+1 ), // cvPoint( 2, 2 ) ); /// Apply the dilation operation IplConvKernel kernel=//cvCreateStructuringElementEx(3,3,1,1,dilation_type,null); cvCreateStructuringElementEx(3,3,1,1,dilation_type); cvDilate( src, dilation_dst, kernel,1); cvReleaseStructuringElement( kernel ); cvSaveImage("D:/java/pic/pic/ba_morphology_Dilation_"+dilation_type+".JPG", dilation_dst); }
不在赘述!低版本的javacv需要引入的资源太多,使用不方便。