UnsatisfiedLinkError: no opencv_java249 in java.library.path

后端 未结 9 1498
旧巷少年郎
旧巷少年郎 2020-11-27 05:38

Running into some problems making a piece of code run on my mac. Had someone write me an image analysis java app but I keep getting this error when trying to run it on netbe

9条回答
  •  伪装坚强ぢ
    2020-11-27 06:02

    After Spending a lots of time , and using different suggestions from StackOverflow I managed to get solution for windows. but I am adding a solution for mac as well. hope it should work.

    1. Load your lib as per your system configuration.

      private static void loadLibraries() {
      
          try {
              InputStream in = null;
              File fileOut = null;
              String osName = System.getProperty("os.name");
              String opencvpath = System.getProperty("user.dir");
              if(osName.startsWith("Windows")) {
                  int bitness = Integer.parseInt(System.getProperty("sun.arch.data.model"));
                  if(bitness == 32) {
                      opencvpath=opencvpath+"\\opencv\\x86\\";
                  }
                  else if (bitness == 64) { 
                      opencvpath=opencvpath+"\\opencv\\x64\\";
                  } else { 
                      opencvpath=opencvpath+"\\opencv\\x86\\"; 
                  }           
              } 
              else if(osName.equals("Mac OS X")){
                  opencvpath = opencvpath+"Your path to .dylib";
              }
              System.out.println(opencvpath);
              System.load(opencvpath + Core.NATIVE_LIBRARY_NAME + ".dll");
          } catch (Exception e) {
              throw new RuntimeException("Failed to load opencv native library", e);
          }
      }
      

    2.now use this method as per your need

    public static void main(String[] args) {
        loadLibraries();
    } 
    

提交回复
热议问题