Connecting OpenCV to a Java project

When executing code from the tutorial:

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

    public static void main(String[] args) {
        System.out.println("Welcome to OpenCV " + Core.VERSION);
        Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
        System.out.println("OpenCV Mat: " + m);
        Mat mr1 = m.row(1);
        mr1.setTo(new Scalar(1));
        Mat mc5 = m.col(5);
        mc5.setTo(new Scalar(5));
        System.out.println("OpenCV Mat data:\n" + m.dump());
    }

When running this code, I get the error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java410 in java.library.path:

Among other things, I installed OpenCV of the latest version for Windovs, in the system environment variable Path I wrote the path to this folder according to the manual of one of the articles on habr:

C:\Java_Projects\opencv\build\x64\vc15\bin

I scrolled through the answers(1, 2) on this error, but did not find a solution.

Question two:

1) Why is it trying to find the version of the file 410, if I have OpenCV, in which the version of this file is 411. (It may be due to a dependency in the pom, but the latest one is registered there)

2) Is it necessary to specify the path to the file with version 411 in the path variable (or somewhere else), since it lies in the folder: C:\Java_Projects\opencv\build\java\x64 ?

P.S. For the second question, I understand what is necessary, but I want to hear the correct answer to the question where.

pom.xml:

<dependency>
  <groupId>org.bytedeco</groupId>
  <artifactId>javacv-platform</artifactId>
  <version>1.5.1</version>
</dependency>

UPD:

Core.NATIVE_LIBRARY_NAME

Returns just opencv_java410, but then it's not quite clear what to do. Download the system library named *411, or install an older version of OpenCV that has version 410?

1 answers

The solution that worked, but I am not completely sure that it is correct, is to specify the path to 411 of the library in the startup parameters:

-Djava.library.path="C:\Java_Projects\opencv\build\java\x64"

In this folder, rename the 411 library to the 410 it is looking for. Then the code runs and works, but I don't think this is the right option. I would like to know the correct answer.

 0
Author: Мишаков Александр, 2019-08-25 12:02:47