Error loading OpenCV with Maven

asked 2019-06-14 02:48:12 -0500

Rafutek gravatar image

Hey, I am trying to import OpenCV from Maven repository. The dependency works because I can see OpenCV classes in Eclipse.

This is the dependency in Maven pom.xml:

<dependency> 
<groupId>nu.pattern</groupId> 
<artifactId>opencv</artifactId> 
<version>2.4.9-4</version> 
</dependency>

However, when I launch the program:

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);
    }
}

I get this error when I try to load the library:

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:7)

Also, I have jdk 12.0.1.

If you have any information about what is going on, or how to solve that please let me know !

Thank you in advance

edit retag flag offensive close merge delete

Comments

import OpenCV from Maven repository.

opencv does not maintain any maven repository. (and we probably can't help with 3rd party efforts there)

2.4.9-4

stone age, dead since 6 years. don't use it.

berak gravatar imageberak ( 2019-06-14 02:52:11 -0500 )edit

I changed the version with 3.4.2, last version in Maven repository: https://repo.maven.apache.org/maven2/....

It still doesn't work with nu.pattern.OpenCV.loadShared() method, raises these errors: Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: Failed to get field handle to set library path ... 3 more

But with nu.pattern.OpenCV.loadLocally() it works!

What do you recommend, loading locally the 3.4.2 version as I did, or install all the library (which is really long to be honest) and link it locally with Maven? Or maybe another alternative...

Thank you

Rafutek gravatar imageRafutek ( 2019-06-14 03:18:32 -0500 )edit
1

again, you have to complain with the maintainer of that maven repo, we can't do much about it here

Or maybe another alternative...

the official way is to build from src

berak gravatar imageberak ( 2019-06-14 03:24:11 -0500 )edit