无法找到依赖库javacv

时间:2013-03-09 11:26:51

标签: opencv netbeans javacv

我有这段代码:

package javacv;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import javax.swing.JOptionPane;

/**
 *
 * @author (Mahdi)
 */
public class JavaCv {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try {
              IplImage img = cvLoadImage("mehdi.jpg");  
                cvShowImage("Hellow", img);
                cvSmooth(img, img, CV_GAUSSIAN, 13);
                cvShowImage("Blur", img);
                cvWaitKey();
                cvReleaseImage(img);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }



    }
}

运行后抛出此异常:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\(Mahdi)\AppData\Local\Temp\javacpp66820482987315\jniopencv_core.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825)
    at java.lang.Runtime.load0(Runtime.java:792)
    at java.lang.System.load(System.java:1059)
    at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:566)
    at com.googlecode.javacpp.Loader.load(Loader.java:489)
    at com.googlecode.javacpp.Loader.load(Loader.java:431)
    at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:266)
    at com.googlecode.javacpp.Loader.load(Loader.java:453)
    at com.googlecode.javacv.cpp.opencv_imgproc.<clinit>(opencv_imgproc.java:97)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:266)
    at com.googlecode.javacpp.Loader.load(Loader.java:453)
    at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:85)
    at javacv.JavaCv.main(JavaCv.java:23)
Caused by: java.lang.UnsatisfiedLinkError: no opencv_core244 in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
    at java.lang.Runtime.loadLibrary0(Runtime.java:845)
    at java.lang.System.loadLibrary(System.java:1084)
    at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
    at com.googlecode.javacpp.Loader.load(Loader.java:481)
    ... 11 more
Java Result: 1

任何想法?

3 个答案:

答案 0 :(得分:3)

Java正试图在$ {java.library.path}中找到所需的dll,但它没有定义。 所以你应该:

  1. 在%PATH%中设置opencv_java244.dll的位置(例如“c:\ opencv \ build \ java \ x64 \”)。
  2. 在项目目录“lib”dir。
  3. 中创建
  4. 放在那里:
    • javacpp.jar
    • javacv.jar
    • javacv-windows-x86_64.jar
    • 的OpenCV-2.4.4 - 窗口x86_64.jar
    • 的OpenCV-244.jar
  5. 如果你的平台的位数是32,那么使用* x86.jar版本。

    然后你可以使用opencv / samples / java / ant /这个修改过的ant脚本来运行你的应用程序:

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

    或者您可以在蚂蚁脚本中定义$ {java.library.path},如下所示:

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

答案 1 :(得分:0)

您是否尝试将opencv目录解压缩为c:\ opencv?这是解决这个问题的简单方法。

答案 2 :(得分:0)

java cv和OpenCV的版本存在问题。

如果使用OpenCV 2.4.7,则应使用Java cv 0.6;如果使用OpenCV 2.4.8,则应使用javacv 0.7。