gpt4 book ai didi

Java 8 opencv 简单示例 UnsatisfiedLinkError

转载 作者:行者123 更新时间:2023-12-02 09:45:16 25 4
gpt4 key购买 nike

我想学习opencv,所以我想运行这个代码示例。

我已经从opencv 3.4.2下载了软件包,严格添加到intellij,java版本8中。版本3.20 mi可以正常工作,但需要更高版本的3.4.2或更高版本。请帮忙,我无能为力。这是我的代码:

public class Main {

public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
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());
}
}
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Work\opencv\opencv\build\java\x64\opencv_java342.dll: Can't find dependent libraries
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2430)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2487)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2684)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2649)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
at java.base/java.lang.System.loadLibrary(System.java:1867)
at Main.main(Main.java:9)

最佳答案

您需要使用以下方式加载.dll或.so库:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

或者

System.load(PATH_TO_NATIVE_LIB);

接下来需要添加对 pom.xml 的依赖:

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

库和依赖项版本必须相同。

关于Java 8 opencv 简单示例 UnsatisfiedLinkError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56710956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com