在eclipse中将openCV添加到java buildpath

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16316381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:17:15  来源:igfitidea点击:

adding openCV to java buildpath in eclipse

javawindowseclipseopencv

提问by kiltek

I have problems adding openCV to the buildpath of my eclipse-project. I have followed the instructions in the tutorial on this site: http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.html#create-a-simple-java-project-in-eclipse

我在将 openCV 添加到我的 eclipse 项目的构建路径时遇到问题。我已按照本网站教程中的说明进行操作:http: //docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.html#create-a-simple-java-project-日食

But executing the code fragment gives this console output:

但是执行代码片段会给出这个控制台输出:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv-java2.4.4 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at camStatisticsTests.RawTests.main(RawTests.java:20)

What do I have to do in order to get openCV working with java and eclipse. i want to use it as a normal java library.

我该怎么做才能让 openCV 与 java 和 eclipse 一起工作。我想将它用作普通的 Java 库。

采纳答案by kiltek

I have found the solution. The tutorial skips the step, where one has to add a dll to the "native build path". The dll is located in "opencv/build/java/x86" for 32-bit java i guess. although i dont know why this is the case. Would be nice, if someone could explain that.

我找到了解决办法。本教程跳过了必须向“本机构建路径”添加 dll 的步骤。我猜对于 32 位 java,dll 位于“opencv/build/java/x86”中。虽然我不知道为什么会这样。会很好,如果有人能解释一下。

回答by StreakyCobra

The OpenCV java library is correctly linked to your Eclipse project.

OpenCV java 库正确链接到您的 Eclipse 项目。

The problem is the OpenCV native library which is not in the java.library.path. The exception is thrown by the line

问题是 OpenCV 本机库不在java.library.path. 异常由该行抛出

static{ System.loadLibrary("opencv_java244"); }

which link the java library to the native one.

将 java 库链接到本机库。

When you install OpenCV on your computer, it will also install a native dlllibrary somewhere on your system, and when you call the System.loadLibrary, you tell java to search and load this library.

当你在你的计算机上安装 OpenCV 时,它也会dll在你系统的某个地方安装一个本地库,当你调用 时System.loadLibrary,你告诉 java 搜索并加载这个库。

Your current problem is Java can not find this library in your System, either because the library is not in one of the java.library.pathfolders, or because you have not OpenCV installed (also take a look at the version, maybe you have not the 2.4.4 because the last is 2.4.5, in which case you will have to adapt the String).

您当前的问题是 Java 在您的系统中找不到这个库,要么是因为该库不在其中一个java.library.path文件夹中,要么是因为您没有安装 OpenCV(也看看版本,也许您没有 2.4.4因为最后一个是 2.4.5,在这种情况下,您必须调整字符串)。

I just noticed that your exception is about "opencv-java2.4.4". Be sure to have the right spelling of the form "opencv_java244", in your System.loadLibrarycall.

我刚刚注意到你的例外是关于“opencv-java2.4.4”。请确保在您的System.loadLibrary通话中使用正确的“opencv_java244”形式拼写。

I also redirect you to one of my answer, which is related to JavaCV, but that explain in more details what is going under.

我还将您重定向到我的一个答案,它与 JavaCV 相关,但它更详细地解释了正在发生的事情。

回答by user3033420

I found a solution. The actual dll is located in the openCV\opencv\build\java\x64\folder. In my case, its name is opencv_java247.dll, so I have changed System.loadLibrary("opencv_java244")to System.loadLibrary("opencv_java247")in my java code. I also put the native library location as E:/Sagar_tools/tools/openCV/opencv/build/java/x64(which is my full path to the dll).

我找到了解决方案。实际的 dll 位于该openCV\opencv\build\java\x64\文件夹中。就我而言,它的名称是opencv_java247.dll,所以我在我的 Java 代码中更改System.loadLibrary("opencv_java244")System.loadLibrary("opencv_java247")。我还将本机库位置作为E:/Sagar_tools/tools/openCV/opencv/build/java/x64(这是我到 dll 的完整路径)。

回答by Avisho

I had the same problem.

我有同样的问题。

It happened because I had a mistake with the 'Native library location' configuration:

发生这种情况是因为我对“本机库位置”配置有误:

Goto Eclipse -> Window -> Preferences:

转到 Eclipse -> 窗口 -> 首选项:

Goto Eclipse ->Window ->Preferences

转到 Eclipse ->窗口 ->首选项

Goto User Libraries:

转到用户库:

enter image description here

在此处输入图片说明

Make sure that your native library location path is (change c:/opencv-2.4.9 to your own opencv folder):

确保您的本机库位置路径为(将 c:/opencv-2.4.9 更改为您自己的 opencv 文件夹):

C:/opencv-2.4.9/build/java/x64

and not:

并不是:

C:/opencv-2.4.9/build/x64

(I missed the /javafolder...)

(我错过了/java文件夹...)

回答by gihantharanga

Change the code to System.loadLibrary("opencv_java244")hope you would set the native path to correct folder and opencv jar has set in build path

更改代码以System.loadLibrary("opencv_java244")希望您将本机路径设置为正确的文件夹,并且 opencv jar 已在构建路径中设置

回答by Zodzie

For me, Eclipse > external jar > native library config = opencv/build/lib worked

对我来说,Eclipse > external jar > native library config = opencv/build/lib 工作