3

I am trying to use opencv 2.4.9. with maven, i have two files - the first one is a java file which is in a maven project , and the second one is a java file with all the opencv imports but this file is in the same package, am calling a function of second java file from the first one. The two files run fine separately as java project but when I try to run the complete maven project it throws this error - (java.lang.NoClassDefFoundError: org/opencv/core/Core)

and the build fails.

After a lot of research i found out that the problem is mostly because of System.loadLibrary(Core.NATIVE_LIBRARY_NAME); which am using to load opencv libraries. To rectify this, there are solutions to add opencv.dll to the java folder but since am working os x 10.9.5, i dont have dll's as they are found in the build folder under opencv, but build folder will only be there if we have installed opencv, and i cannot find a .dmg file for opencv. What should i do?

PS: This is my first post on SO.

mpratap
  • 59
  • 1
  • 4

5 Answers5

1

After a lot of hit and trials, directly specifying the path of the opencv.dll in the System.loadLibrary("Complete Path to opencv.dll") seems to have done the trick, but in Mac the problem remains as it is as I do not have any .dll or .so or .dylib for opencv in Mac.

mpratap
  • 59
  • 1
  • 4
0

Although I have never used opencv:

There is a Mac OS X download from opencv

I suppose there should be an opencv.dll equivalent native library (opencv.jnilib?) in the opencv package for Mac OS X and loading it with System.loadLibrary could resolve the issue.

There is a article how to load a native library on Mac OS X.


May be relevant:

mon
  • 18,789
  • 22
  • 112
  • 205
  • Quick search showed opencv.jnilib such as https://github.com/Tkres/DC32_MConvo/tree/master/libraries/OpenCV (not sure this is safe one, so please make sure). – mon Jan 23 '15 at 10:09
  • Hey ! thanks for the answer and i followed all the steps given in that tutorial but after finishing each step i got this : (java.lang.UnsatisfiedLinkError: /Library/Java/Extensions/libOpenCV.jnilib: dlopen(/Library/Java/Extensions/libOpenCV.jnilib, 1): no suitable image found. Did find: /Library/Java/Extensions/libOpenCV.jnilib: unknown file type, first eight bytes: 0x0A 0x0A 0x0A 0x0A 0x3C 0x21 0x44 0x4F) It seems .jnilib is not recognisable. I hope you can help. – mpratap Jan 28 '15 at 12:33
  • Apart from it, am not able to understand what the 4th step is for? And how exactly do i use it? – mpratap Jan 29 '15 at 12:34
  • Not sure how the code was written, where the library is placed, from where the library was acquired, so it is a bit difficult to understand the situation… If the code was like System.loadLibrary("libOpenCV.jnilib"), the suffix part .jnlib should not be specified, I suppose. Anyway, needs more details in a way other people may be able to reproduce the issue... – mon Jan 29 '15 at 14:27
0

It's an old question, but without answer yet. For me that solve the problem for System.loadLibrary(Core.NATIVE_LIBRARY_NAME): https://stackoverflow.com/a/35112123

Community
  • 1
  • 1
Elisa FK
  • 11
  • 2
  • I am not sure what you mean? Could you elaborate? Do you mean the linked Stack Overflow question solved a similar problem for you? – Kmeixner May 24 '16 at 19:51
  • On Windows you can specify the path for dll, on MAC you don't have it. So, to fix the error when use System.loadLibrary(Core.NATIVE_LIBRARY_NAME) in MAC I download and compile the opencv using brew install opencv3 --with-java --with-python3. It will be installed in /usr/local/Cellar/opencv3/XXX/share/OpenCV/java 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 – Elisa FK May 25 '16 at 12:36
0

For Ubuntu Linux, I got the similar problem which can't find the native library which actually is the libopencv_javaxxx.so (xxx is the version) which is actually installed under /usr/lib/jni/ not like other native libraries installed under /usr/lib/x86_64-linux-gnu/

My first thought for the native library is the libopencv_core.so and there is no libopencv.so at all.

0

Take a look at Unsupported platform in nu.pattern and my suggested answer to openCV Java on Kotlin which shows how to use the nu.pattern.OpenCV.loadShared(); API.