I'm trying to do some template matching with the Java binding of OpenCV 4.3.0 in Eclipse, but attempting to load the template image always results in this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.imgcodecs.Imgcodecs.imread_0(Ljava/lang/String;I)J
The line of code where this exception is thrown is this:
flowerTemplate = Imgcodecs.imread("/templates/flowerpot_white.png", Imgcodecs.IMREAD_COLOR);
I have tried a number of solutions suggested on similar questions on StackOverflow and elsewhere on the internet, including:
- Pointing at the native library folder with the "Native library location" variable in the user library definition in Eclipse.
- Adding the native library folder location to my PATH variable.
- Adding the native library .dll location to my PATH variable.
- Setting up the Eclipse run configuration to add the native library folder & .dll locations to the PATH and CLASSPATH variables.
- Loading the library with the appropriate Java code, in each of the three ways I saw it suggested, in three different places which all run before the code that throws the exception.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.load(<path_to_the_dll>);
File opencvLibrary = new File(System.mapLibraryName(Core.NATIVE_LIBRARY_NAME));
System.load(opencvLibrary.getAbsolutePath());
- Placing the .dll in question into my source folder and every subfolder. I am running it from within Eclipse, so this is also the program's working directory.