1

I want to execute a simple OpenCV code to test that the library is well loaded by Maven.

This is the code:

package helloworld;
import org.opencv.core.*;

public class Hello {

    public static void main(String[] args) 
    {
        nu.pattern.OpenCV.loadLibrary();
        System.out.println("Hey World !");
        Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
    }
}

And this is the console output I get, with the two errors, when I try to run it:

java.lang.NoSuchFieldException: sys_paths at java.base/java.lang.Class.getDeclaredField(Class.java:2417) at nu.pattern.OpenCV.loadLibrary(OpenCV.java:207) at helloworld.Hello.main(Hello.java:9)

Hey World !

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_eye(III)J at org.opencv.core.Mat.n_eye(Native Method) at org.opencv.core.Mat.eye(Mat.java:1467) at helloworld.Hello.main(Hello.java:11)

I got the maven repository linking looking at that post.

Would you have any idea about what is causing that?

Thanks!

Community
  • 1
  • 1
Rafutk
  • 196
  • 1
  • 1
  • 15

1 Answers1

2

Try downloading a library from another repository.

<dependency>
    <groupId>org.openpnp</groupId>
    <artifactId>opencv</artifactId>
    <version>3.4.2-1</version>
</dependency>

You can see my answer to the post with a similar problem.

  • Thank you for answering, but I "resolved" my problem changing the dependency as you did, and with nu.pattern.OpenCV.loadLocally(); but every tiime I launch the program the error "You have loaded library /tmp/opencv_openpnp.../libopencv_java342.so which might have disabled stack guard. The VM will try to fix the stack guard now. It's highly recommended that you fix the library with 'execstack -c ', or link it with '-z noexecstack'." – Rafutk Jul 04 '19 at 14:15
  • Run this command: execstack -c /tmp/opencv_openpnp.../libopencv_java342.so. This should help – Maxim Burbelov Jul 05 '19 at 05:40