使用eclipse来查找opencv本机库不起作用

时间:2014-02-04 13:38:29

标签: eclipse opencv ant java

我尝试在ubuntu安装上使用opencv并且正在关注this教程。一切似乎都很好,甚至列在已安装的部件中,所以我继续进入this教程。直到您必须将opencv添加为用户库,因为它不在(完全空的)库列表中。我已经浏览了整个opencv文件夹,找不到像图书馆这样的东西,或者我错过了什么?有关如何解决此问题的任何想法?

请注意,它确实设法生成.jar文件但是库仍然缺失。如果重要的话,opencv安装在usr / local / src。

如果为了解决此问题,您需要在评论中随意提出任何额外信息。

这可能与问题有关:

ulap:/usr/local/src/opencv-2.4.8/opencv/build/bin$ ant -DocvJarDir=path/to/dir/containing/opencv-248.jar -DocvLibDir=/usr/local/src/opencv-2.4.8/opencv/build/bin /opencv_java248/native/library
Buildfile: /usr/local/src/opencv-2.4.8/opencv/build/bin/build.xml

BUILD FAILED
Target "/opencv_java248/native/library" does not exist in the project "SimpleSample". 

Total time: 0 seconds
thijs@thijs-ulap:/usr/local/src/opencv-2.4.8/opencv/build/bin$ ant -DocvJarDir=path/to/dir/containing/opencv-248.jar -DocvLibDir=/usr/local/src/opencv-2.4.8/opencv/build/bin /opencv_java248/native/library
Buildfile: /usr/local/src/opencv-2.4.8/opencv/build/bin/build.xml

BUILD FAILED
Target "/opencv_java248/native/library" does not exist in the project "SimpleSample". 

Total time: 0 seconds

这是我的build.xml:

<property name="src.dir"     value="src"/>

<property name="lib.dir"     value="${ocvJarDir}"/>
<path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>

<property name="build.dir"   value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir"     value="${build.dir}/jar"/>

<property name="main-class"  value="${ant.project.name}"/>


<target name="clean">
    <delete dir="${build.dir}"/>
</target>

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>

<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
        <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
        </manifest>
    </jar>
</target>

<target name="run" depends="jar">
    <java fork="true" classname="${main-class}">
        <sysproperty key="java.library.path" path="${ocvLibDir}"/>
        <classpath>
            <path refid="classpath"/>
            <path location="${jar.dir}/${ant.project.name}.jar"/>
        </classpath>
    </java>
</target>

<target name="rebuild" depends="clean,jar"/>

<target name="rebuild-run" depends="clean,run"/>

正在运行

ulap:/usr/local/src/opencv-2.4.8/opencv/samples/java/ant$ ant -DocvJarDir=/usr/local/src/opencv-2.4.8/opencv/build/bin rebuild-run

给了我:

clean:

compile:
    [mkdir] Created dir: /usr/local/src/opencv-2.4.8/opencv/samples/java/ant/build/classes
    [javac] Compiling 1 source file to /usr/local/src/opencv-2.4.8/opencv/samples/java/ant/build/classes

jar:
    [mkdir] Created dir: /usr/local/src/opencv-2.4.8/opencv/samples/java/ant/build/jar
      [jar] Building jar: /usr/local/src/opencv-2.4.8/opencv/samples/java/ant/build/jar/SimpleSample.jar

run:
     [java] Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path
     [java]     at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709)
     [java]     at java.lang.Runtime.loadLibrary0(Runtime.java:844)
     [java]     at java.lang.System.loadLibrary(System.java:1051)
     [java]     at SimpleSample.<clinit>(Unknown Source)
     [java] Could not find the main class: SimpleSample. Program will exit.
     [java] Java Result: 1

rebuild-run:

BUILD SUCCESSFUL
Total time: 1 second

3 个答案:

答案 0 :(得分:1)

根据第一篇教程(如何从源构建OpenCV),结果应该是一个JAR文件和一个.so本机库,位于OpenCV目录的bin/目录中。在UBUNTU&#34;&#34;设置使用OPENCV(JAVA)的ECLIPSE教程中,您必须按照本教程中的步骤创建用户库。该过程涉及浏览文件系统以选择第一个教程生成的OpenCV JAR,然后选择.so文件作为本机库。 Eclipse不会自动发现&#34;你的OpenCV库,你必须配置它来了解它,这是第二个教程正在做的事情。

答案 1 :(得分:1)

我认为你用ant运行了错误的命令。您可以在此处阅读手册:https://ant.apache.org/manual/running.html

以下是运行ant的格式:

ant [options] [target [target2 [target3] ...]]

所以也许你的命令行应该是这样的:

ant -DocvJarDir=/usr/local/src/opencv-2.4.8/opencv/build/bin rebuild-run

鉴于/usr/local/src/opencv-2.4.8/opencv/build/bin包含opencv-248.jar

如您的build.xml文件所示,属性ocvJarDir指向类路径的位置需要构建项目:

<property name="lib.dir" value="${ocvJarDir}"/>
<path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>

您需要在命令行中指定目标“rebuild-run”,因为您的build.xml没有指定默认目标。

答案 2 :(得分:0)

尝试安装2.4.6版本。在VS中安装时遇到类似的问题。旧版本有效。也许它在Eclipse中也是一样的。