1

I am currently try to develop Java application which will use OpenCV library. I was trying to test my openCV configuration using testNg framework like this:

@Test
public void openCVTest(){
    System.out.println("OpenCV configuration simple test:");
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat m = Mat.eye(3,3, CvType.CV_8UC1);
    System.out.println("OpenCV matrix = " + m.dump());
}

However that produced an error:

java.lang.UnsatisfiedLinkError: no opencv_java300 in java.library.path

I have found multiple answers(even on stackoverflow) and they all suggested bad configuration with some solutions which i tried. In the end I tried to run same code but this time in app like this:

public class App {
    public static void main( String[] args ){
        System.out.println("OpenCV configuration simple test:");
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat m = Mat.eye(3,3, CvType.CV_8UC1);
        System.out.println("OpenCV matrix = " + m.dump());
    }
}

And it is working like it suposed to. So my question is, why isn't this working with testing framework? Perhaps somehow i must also configure openCV library for tests?

pokemzok
  • 1,659
  • 1
  • 19
  • 29
  • 1
    It appears like your top test doesn't have its java.library.path configured correctly to find it's native lib, where it is configured in correctly in your second example. Do a system.out() on the java.library.path property from your second example and see what the value is. – medloh Oct 27 '15 at 18:28
  • Thanks for your interest. I am gonna try it when I return from the job. – pokemzok Oct 28 '15 at 11:47

1 Answers1

2

In the end I solved it using absolute path in my tests like this:

@BeforeClass
public void setUp(){
    System.loadLibrary("lib/x64/opencv_java300");
}

@Test
public void openCVTest(){
    System.out.println("OpenCV configuration simple test:");
    Mat m = Mat.eye(3,3, CvType.CV_8UC1);
    System.out.println("OpenCV matrix = " + m.dump());
}

And in my application I am loading it normally:

 public class App {

    static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }

    public static void main( String[] args ){
        System.out.println("OpenCV configuration simple test:");
        Mat m = Mat.eye(3,3, CvType.CV_8UC1);
        System.out.println("OpenCV matrix = " + m.dump());
    }

 }
pokemzok
  • 1,659
  • 1
  • 19
  • 29