java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J?

后端 未结 3 657
清酒与你
清酒与你 2021-01-14 12:31

I\'ve been trying to get opencv working inside of our raspberry pi, but I have not been able to get it working at all. I made a new eclipse project, added in the OpenCV libr

相关标签:
3条回答
  • 2021-01-14 12:53

    The error you are getting means that the native OpenCV file has not been linked/loaded.

      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
    

    The line of code above that you are using, will work only if the specified OpenCV native file resides inside the Java library path.

    Are you sure OpenCV files are there? I would suggest trying to load the OpenCV native by giving the full path, just to see where the problem lies.

    System.load("fullPathTo/opencv.dll");
    

    I would also recommend taking a look at this post which explains all these in detail. https://stackoverflow.com/a/47718273/5165833

    0 讨论(0)
  • 2021-01-14 13:00

    You can load the library like this: first of all call this method

    public static void loadOpenCV_Lib() throws Exception {
        // 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);
    }
    

    Note: In code above the OpenCV has extracted in C drive root folder.

    Edit: In Eclipse you are also can do it like this: Right click on the project -> Build Path -> Configure Build Path -> Libraries (Tab) -> Expend the OpenCV jar -> Native library location: -> Eidt -> Put this; C:/opencv/build/java/x64/ -> OK -> Apply...

    0 讨论(0)
  • 2021-01-14 13:08

    I ran into this issue on Linux, and it took a bit to figure it out. First, to answer TheGuyWhoCodes above there is no java folder in the build folder. This java intro opencv document tells how to do a build on Linux, and it says

    will create a jar containing the Java interface (bin/opencv-244.jar) and a native dynamic library containing Java bindings and all the OpenCV stuff (lib/libopencv_java244.so or bin/Release/opencv_java244.dll respectively)

    So after you do cmake and make, the jar is in the bin folder and the native library is in the lib folder.

    Second, I initially followed this opencv Installation in Linux document to do the Linux build, and it suggests (in step 5) to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS when doing a java build. What I found is unsetting these appears to be the cause of my "java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J"

    Once I did the build based on the first link, and only unset the BUILD_SHARED_LIBS option, I no longer got the UnsatisfiedLinkError and the test worked. I'm yet to play with it enough to figure out which of the things I was unsetting was the cause of the problem, but that should be a simple trial-and-error process for anyone so inclined.

    0 讨论(0)
提交回复
热议问题