UnsatisfiedLinkError: no opencv_java249 in java.library.path
Look into your OpenCV directory;
For an example this; (installed using brew install opencv3 --with-java --with-python3
)
/usr/local/Cellar/opencv3/XXX/share/OpenCV/java
You will see;
libopencv_javaXXX.so opencv-XXX.jar
Now that you already have OpenCV's native library for Java (libopencv_javaXXX.so
) compiled with you, the only thing left is, mac's dynamic library.
Link libopencv_javaXXX.so
to libopencv_javaXXX.dylib
;
ln -s libopencv_javaXXX.so libopencv_javaXXX.dylib
Now add /usr/local/Cellar/opencv3/XXX/share/OpenCV/java
as Native Library Locations in IntelliJ or something similar in Eclipse.
Or add this to your JVM arguments;
-Djava.library.path=/usr/local/Cellar/opencv3/XXX/share/OpenCV/java
On a mac running OSX Yosemite, I dropped the libopencv_java2412.dylib file into /Library/Java/Extensions
and it worked.
After you build opencv, the libopencv_java2412.dylib is generated in /build/lib.
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.
-
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();
}