Java 从哪里获得 openCV 的 jar?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18873017/
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
Where to get the jar for openCV?
提问by theAndDev
Where are the Java jar libraries for the openCV core extensions so that I can import it in my java code?
openCV 核心扩展的 Java jar 库在哪里,以便我可以在我的 Java 代码中导入它?
I cannot find a single place where they have taught how to get everything set up properly. I am using Ubuntu 12.04
and I have openCV installed. I want to use it in eclipse IDE, and eclipse needs a jar file so that I can use openCV functions. I saw the following linkwhich has used the import org.opencv.core.Core;
我找不到他们教过如何正确设置一切的地方。我正在使用Ubuntu 12.04
并且安装了 openCV。我想在eclipse IDE中使用它,eclipse需要一个jar文件,以便我可以使用openCV函数。我看到以下链接使用了import org.opencv.core.Core;
How can I get those .jar files?
我怎样才能得到那些 .jar 文件?
采纳答案by TheKojuEffect
You can find jars for openCV
for linux kicking around the internet like at this link. However it won't work unless you have the native libraries openCV needs to do its work.
你可以openCV
在互联网上找到linux 的jars,就像这个链接。然而,除非你有本地库 openCV 需要做它的工作,否则它不会工作。
A sure way to get openCV available in your eclipse java project is to compile your own jar file from source to make it available as described here: https://udallascs.wordpress.com/2014/03/30/adding-opencv-and-configuring-to-work-with-eclipse-and-java/
在 eclipse java 项目中获得 openCV 的一种可靠方法是从源代码编译您自己的 jar 文件以使其可用,如下所述:https: //udallascs.wordpress.com/2014/03/30/adding-opencv-and -configuring-to-work-with-eclipse-and-java/
Here is the jist of instructions for Linux, open a terminal and run these commands:
这是 Linux 的指令集,打开终端并运行以下命令:
cd ~
mkdir Vision
cd Vision
git clone https://github.com/opencv/opencv.git
cd opencv
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=OFF ..
make -j8
If everything succeeded, then your jars will be under the be under the bin directory:
如果一切顺利,那么你的 jars 将在 bin 目录下的 be 下:
./bin/opencv-300.jar
Move that opencv-300.jar into the lib directory in your project and include it as an external jar. Here is the barebones program that uses it.
将 opencv-300.jar 移动到项目的 lib 目录中,并将其作为外部 jar 包含在内。这是使用它的准系统程序。
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to OpenCV " + Core.VERSION);
System.out.println(System.getProperty("java.library.path"));
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
}
Within eclipse, your jar file will need the native libraries you built earlier to be available. So in eclipse, navigate to:
在 eclipse 中,您的 jar 文件需要您之前构建的本机库才能使用。所以在 eclipse 中,导航到:
Project->Properties->Java Build Path->Libraries tab-> Add external jars -> opencv-300.jar
Then double click: "Native library location" and enter in the build/lib where you built it, in my case: /home/el/Vision/opencv/build/lib
然后双击:“本机库位置”并输入您构建它的构建/库,在我的情况下: /home/el/Vision/opencv/build/lib
Run the java program, the program prints:
运行java程序,程序打印:
Welcome to OpenCV 3.0.0-dev
/home/el/Vision/opencv/build/lib
m = [1, 0, 0;
0, 1, 0;
0, 0, 1]
If you want to give this program to someone else and have them be able to run it, they will need to have openCV version 3.0.0 also available on their system, or else the java program will not find the libraries, and immediately exit.
如果你想把这个程序交给其他人并让他们能够运行它,他们需要在他们的系统上也有 openCV 3.0.0 版,否则 java 程序将找不到库,并立即退出。
Why is this so hard, why is this not just a simple jar?
为什么这么难,为什么这不只是一个简单的罐子?
Because openCV is written in C, and the jar file is just a window into that C world. So we have to make a Rube Goldbergmachine to make the methods in OpenCV available to your java application.
因为 openCV 是用 C 编写的,而 jar 文件只是进入 C 世界的一个窗口。所以我们必须制作一个Rube Goldberg机器来让你的 Java 应用程序可以使用 OpenCV 中的方法。