0

i get this error after running my project with javacv library.

   Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java2411 in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
        at java.lang.Runtime.loadLibrary0(Runtime.java:870)
        at java.lang.System.loadLibrary(System.java:1122)
        at webcam.cam.main(cam.java:181)

1 Answer 1

1

You can use this below way:

public static void loadOpenCVLib(String path) throws Exception {
    File lib_dir = new File(path);
    System.setProperty("java.library.path", lib_dir.getAbsolutePath());
    Field sys_paths = ClassLoader.class.getDeclaredField("sys_paths");
    sys_paths.setAccessible(true);
    sys_paths.set(null, null);
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    // it is for the ffmpeg name
    String[] list = lib_dir.list();
    assert list != null;
    String ffmpeg_dll_file_name = null;
    for (String s : list) {
        if (s.contains("ffmpeg")) {
            ffmpeg_dll_file_name = s.substring(0, s.indexOf("."));
        }
    }
    System.loadLibrary(ffmpeg_dll_file_name);
}

And now create a folder in some place and name it opencv_lib e.g: D:\opencv_lib, and then put the opencv dll and ffmpeg dll files inside this folder, and then when running the program first of all call the method above e.g:

loadOpenCVLib("D:\\opencv_lib");

Now it will be OK.

Note: It will be better to download and use the latest version of OpenCV

Sign up to request clarification or add additional context in comments.

6 Comments

@KurtRuzell It must be working. I am using this for a long time and in many projects, on different machines without any problem, so there can be something wrong in the way you are using. This code just adds the dlls in the Java classpath, and then you load the lib, it can be found by the Java VM.
Oct 20, 2017 8:16:13 PM webcam.cam main SEVERE: null java.lang.NullPointerException at java.lang.Runtime.loadLibrary0(Runtime.java:866) at java.lang.System.loadLibrary(System.java:1122) at webcam.cam.loadOpenCVLib(cam.java:62) at webcam.cam.main(cam.java:220)
@KurtRuzell Hmm, but there is no problem in the code because I am just using.
it is now working sir but my next problem is this "OpenCV Error: Unspecified error (could not find a writer for the specified extension)"
At first, if the above answer (code) solved your problem, so according to of the Smackover Flow regular, accept and vote up the answer, so if anyone else has the same problem know that this is the answer. OK, then what is your next problem, what did you do that you get this Error?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.