can't find dependent library javacv

眉间皱痕 提交于 2019-12-05 18:13:15

Java is trying to find required dlls in ${java.library.path} but it is not defined. So you should:

  1. Set location of opencv_java244.dll in %PATH% ("c:\opencv\build\java\x64\" for example).
  2. Create in your project dir "lib" dir.
  3. Put there:
    • javacpp.jar
    • javacv.jar
    • javacv-windows-x86_64.jar
    • opencv-2.4.4-windows-x86_64.jar
    • opencv-244.jar

If your platform's bitness is 32 then use *x86.jar versions.

And then you may use this modified ant script from opencv/samples/java/ant/ to run your app:

<project name="JavaCv" basedir="." default="rebuild-run">

<property name="src.dir" value="src"/>
<property name="lib.dir" value="lib"/>
<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}">
        <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"/>

Or you may define ${java.library.path} in your ant script like this:

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

Did you try extracting the opencv directory as c:\opencv? That is an easy way to fix this.

Muhammad Bilal

There is a problem of the version of java cv and OpenCV.

If you use the OpenCV 2.4.7 then you should use the java cv 0.6 and if you use OpenCV 2.4.8 then you should use javacv 0.7.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!