在哪里可以获得openCV的jar? [英] Where to get the jar for openCV?

查看:207
本文介绍了在哪里可以获得openCV的jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenCV核心扩展的Java jar库在哪里可以在我的java代码中导入?



我找不到一个地方,他们教过如何正确设置一切。我正在使用 Ubuntu 12.04 ,我已经安装了openCV。我想在eclipse IDE中使用它,eclipse需要一个jar文件,以便我可以使用openCV函数。我看到以下链接使用 import org.opencv.core.Core;



如何获取那些.jar文件? / p>

解决方案

你可以找到$ code> openCV 的jar,在此链接。但是,除非您有本地库openCV需要执行其工作,否则它将无法正常工作。



在eclipse java项目中获取openCV的一个确定方法是编译您的自己的jar文件从源代码使其可用,如下所述: https://udallascs.wordpress.com/2014/03/30/adding-opencv-and-configuring-to-work-with-eclipse-and-java/



以下是Linux的说明书,打开终端并运行以下命令:

  cd〜
mkdir Vision
cd Vision
git clone git://github.com/Itseez/opencv.git
cd opencv
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS = OFF ..
make -j8

如果一切都成功,那么你的罐子将在bin目录下:

  ./ bin /opencv-300.jar 
将该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());
}
}

在eclipse中,您的jar文件将需要本机库你之前建立的可用。所以在eclipse中,导航到:

  Project->属性 - > Java Build Path-> Libraries tab->添加外部罐子 - > opencv-300.jar 

然后双击:本机库位置,然后输入build / lib在我的情况下,你创建了它: / home / el / Vision / opencv / build / lib



运行程序打印:

 欢迎使用OpenCV 3.0.0-dev 
/ home / el / Vision / opencv / build / lib
m = [1,0,0;
0,1,0;
0,0,1]

如果你想把这个程序给别人,让他们能够运行它们,他们将需要openCV版本3.0.0也可以在他们的系统上使用,否则java程序将找不到库,并立即退出。



为什么这么难,为什么这不只是一个简单的jar?



<因为openCV是用C编写的,jar文件只是一个C语言的窗口。因此,我们必须制作一个rube goldberg机器,使OpenCV中的方法可用于您的java应用程序。


Where are the Java jar libraries for the openCV core extensions so that I can import it in my java code?

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 link which has used the import org.opencv.core.Core;

How can I get those .jar files?

解决方案

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.

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/

Here is the jist of instructions for Linux, open a terminal and run these commands:

cd ~
mkdir Vision
cd Vision
git clone git://github.com/Itseez/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:

./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.

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:

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

Run the java program, the program prints:

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.

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 goldberg machine to make the methods in OpenCV available to your java application.

这篇关于在哪里可以获得openCV的jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆