2017-04-01 46 views
0

我在windows上使用opencv open cv 2.4.9開發了一個面部檢測項目。現在我必須在ubuntu機器上運行jar。我失敗了。如何爲open cv java項目準備runnable jar?

Caused by: java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path 
     at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889) 
     at java.lang.Runtime.loadLibrary0(Runtime.java:849) 
     at java.lang.System.loadLibrary(System.java:1088) 

我主要關心的是如何準備ubuntu的opencv-249依賴包(runnable jar)?

回答

0

你應該務實地加載OpenCV的LIB如下:

// get the model 
String model = System.getProperty("sun.arch.data.model"); 
// the path the .dll lib location 
String libraryPath = "C:/opencv/build/java/x86/"; 
// check for if system is 64 or 32 
if(model.equals("64")) { 
    libraryPath = "C:/opencv/build/java/x64/"; 
} 
// set the path 
System.setProperty("java.library.path", libraryPath); 
Field sysPath = ClassLoader.class.getDeclaredField("sys_paths"); 
sysPath.setAccessible(true); 
sysPath.set(null, null); 
// load the lib 
System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 

程序啓動時,您可以運行此方法。

+0

和C:/ opencv/build/java/x64/referes到哪個文件? .dll或.so?如果是的話,那麼該怎麼辦? – bajrangi

+0

我已經把路徑'C:/ opencv/build/java/x64 /'它作爲OpenCV的.dll文件的路徑,所以當你提取OpenCV時,.dll文件路徑應該是這樣的'opencv/build/java/x64 /'和'opencv/build/java/x86 /',這樣你就可以把opencv文件夾放在C盤裏,就像這樣:'C:/ opencv/build/java/x64 /' 64位系統,C:/ opencv/build/java/x86/for 32位系統。 –