0

I have the same problem like this post below. But the answers didn't work for me. I hope linking like this is ok.

How to package opencv +java in a jar

I'm loading my opencv lib like this:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // for opencv

In Eclipse I have linked the nativ lib of opencv. Everything works fine till I try to export a jar file.

Probably because the native lib doesn't get exported. On my mac I have the native lib here: /Java Libraries/opencv/opencv-3.0.0/build/lib

Does anyone know how to change the code from the link above so the native lib gets exported as well?

Thanks

user3077796
  • 192
  • 1
  • 19

1 Answers1

2

Instead of loading the lib with this code:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // for opencv

I'll do it with this function:

    private static void loadOpenCVLibrary() {
        //all opencv libs must be copyed to OpenCV_lib in the project workspace
        File folder = new File("OpenCV_lib/");
        File[] listOfFiles = folder.listFiles(); 

    for (int i = 0; i < listOfFiles.length; i++) {
        if (listOfFiles[i].isFile() && listOfFiles[i].getName().endsWith(".dylib")) {
            File lib = new File("OpenCV_lib/" + listOfFiles[i].getName());
            System.load(lib.getAbsoluteFile().toString());
        }
    }
}

The openCV libs from ".../opencv-3.0.0/build/lib" are copyed to the folder "OpenCV_lib" in the project workspace to get a relativ path to the native libs.

To run the exported jar file. The exported jar file and the folder with the containing libs (OpenCV_lib) have to be in the same directory.

user3077796
  • 192
  • 1
  • 19
  • You may just use following to load OpenCV native libraries `System.load("/usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/java/libopencv_java310.so");` – Halil Jul 13 '16 at 13:48