6

I have an issue in setting native library path for opencv in eclipse-ubuntu.i am using ubuntu 15.04.installed opencv 3.1.0 following this link http://milq.github.io/install-opencv-ubuntu-debian/ and add new library(OpenCV) in eclipse and set it's jar path as

/home/user/opencv-3.1.0/build/bin/opencv-310.jar

and native library path as

/home/user/opencv-3.1.0/build/lib

lib folder contains .so and .a files. But when i try to use Mat object it gives me error:here is Main Method

System.out.println("Welcome to OpenCV hhhh " + Core.VERSION);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat img=new Mat();

and here is screenshot of my code and console enter image description here it gives me error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat()J
        at org.opencv.core.Mat.n_Mat(Native Method)
        at org.opencv.core.Mat.<init>(Mat.java:24)

if i use mat like this

Mat m1 =Imgcodecs.imread("/home/zed/Desktop/img.png");

then it gives me diff error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.imgcodecs.Imgcodecs.imread_1(Ljava/lang/String;)J
    at org.opencv.imgcodecs.Imgcodecs.imread_1(Native Method)
    at org.opencv.imgcodecs.Imgcodecs.imread(Imgcodecs.java:102)

am i giving right path for native library? If not then what is the right path for Native Library to use Opencv3.1.0 in eclipse-ubuntu

Sony Khan
  • 1,330
  • 3
  • 23
  • 40

1 Answers1

1

you should add

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

Main:

public static void main(String[] args) {

  System.out.println("Welcome to OpenCV hhhh " + Core.VERSION);
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  Mat m1 =Imgcodecs.imread("/home/zed/Desktop/img.png");
  Mat m2=new Mat();
}

Hope this helps!

Arijit
  • 1,506
  • 14
  • 23
  • i added this line System.loadLibrary(Core.NATIVE_LIBRARY_NAME); but same error!!! – Sony Khan Jan 29 '16 at 10:39
  • You added the .jar ? as External ? – Arijit Jan 29 '16 at 11:04
  • yes i added opencv_java310.jar as external jar and also added OpenCV library from user library in my project properties – Sony Khan Jan 29 '16 at 11:38
  • Actually Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat()J at org.opencv.core.Mat.n_Mat(Native Method) at org.opencv.core.Mat.(Mat.java:24) This error corresponds to adding the System.loadLibrary(Core.NATIVE_LIBRARY_NAME); did you added it in the first before calling anything of opencv ?? Can you add a screenshot? – Arijit Jan 29 '16 at 13:04
  • i added screenshot in my question – Sony Khan Feb 01 '16 at 06:47
  • The both error you said is the same thing that It is missing the native library ;/ – Arijit Feb 01 '16 at 06:56
  • I'm not sure but probably this can be a bug from opencv's side or you are doing something wrong sonewhere – Arijit Feb 01 '16 at 06:59
  • what type of issue can be? – Sony Khan Feb 01 '16 at 07:28
  • I think you are doing something wrong with your build or anything I just installed it again with the current repo on ubuntu n it works fine :/ – Arijit Feb 01 '16 at 08:24
  • But the error means that you get the jar right but it cant find the native libs :/ or u r not loading the native libs . Can you post a full screenshot of the error and code . I mean the whole eclipse – Arijit Feb 01 '16 at 08:27
  • added full screenshot – Sony Khan Feb 01 '16 at 10:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102224/discussion-between-shoaib-akhtar-and-arijit-mukherjee). – Sony Khan Feb 01 '16 at 10:19
  • I dnt know how to chat zzz – Arijit Feb 01 '16 at 16:41
  • If you run the jar application outside eclipse does it works? I'm having the same problem, but only under Eclipse Ide. I made a link of the library inside my jre/lib to make it work `sudo ln -s /usr/local/share/OpenCV/java/libopencv_java320.dylib /Library/Java/JavaVirtualMachines/jdk1.8.xxx.jdk/Contents/Home/jre/lib/libopencv_java320.dylib` – Paolo Biavati Apr 15 '17 at 11:04