OpenCV到JNI如何让它工作?

问题描述 投票:0回答:3

我想使用opencv和java进行面部检测,并且在那次追求中我找到了这个“JNI 2 OPENCV”文件....但我很困惑如何让它工作,任何人都可以帮助我吗?

http://img519.imageshack.us/img519/4803/askaj.jpg

以下是FaceDetection.java

class JNIOpenCV {
    static {
        System.loadLibrary("JNI2OpenCV");
    }
    public native int[] detectFace(int minFaceWidth, int minFaceHeight, String cascade, String filename);
}

public class FaceDetection {
    private JNIOpenCV myJNIOpenCV;
    private FaceDetection myFaceDetection;

    public FaceDetection() {
        myJNIOpenCV = new JNIOpenCV();
        String filename = "lena.jpg";
        String cascade = "haarcascade_frontalface_alt.xml";

    int[] detectedFaces = myJNIOpenCV.detectFace(40, 40, cascade, filename);
    int numFaces = detectedFaces.length / 4;

        System.out.println("numFaces = " + numFaces);
        for (int i = 0; i < numFaces; i++) {
            System.out.println("Face " + i + ": " + detectedFaces[4 * i + 0] + " " + detectedFaces[4 * i + 1] + " " + detectedFaces[4 * i + 2] + " " + detectedFaces[4 * i + 3]);
        }
    }

    public static void main(String args[]) {
        FaceDetection myFaceDetection = new FaceDetection();   
    }
}

有谁告诉我如何才能在Netbeans上做这个工作?我尝试了谷歌,但对这个特定主题的帮助非常明显。

我在netbeans项目中添加了整个文件夹作为Llibrary,当我尝试运行该文件时,我得到以下错误。

Exception in thread "main" java.lang.UnsatisfiedLinkError: FaceDetection.JNIOpenCV.detectFace(IILjava/lang/String;Ljava/lang/String;)[I at FaceDetection.JNIOpenCV.detectFace(Native Method) at FaceDetection.FaceDetection.<init>(FaceDetection.java:19) at FaceDetection.FaceDetection.main(FaceDetection.java:29) Java Result: 1 BUILD SUCCESSFUL (total time: 2 seconds)

有人告诉我使用它的确切方法吗?喜欢我所要做的一切?

java netbeans opencv face-detection dll
3个回答
0
投票

如果您在Windows上使用JNI,Dependency Walker将成为您的朋友。

但是,在我们开始之前,首先通过向静态构造函数块添加:System.out.println("java.library.path="+System.getProperty("java.library.path"));来验证JRE是否可以找到您的JNIOpenCV.dll。

但是,我认为这里的问题不是找到你的JNIOpenCV.dll文件,而是它所依赖的文件。在依赖walker中打开你的.dll(只需将其拖入那里)并查找任何错误消息(msjava.dll除外 - 忽略它,无所谓)。我的预感很可能是你需要Microsoft Visual C / C ++运行时库,从Visual Studio网站下载它们并将它们放在与你的dll相同的文件夹中。

祝你好运!


0
投票

你应该看看这里,一些例子与JNI联系起来:

http://code.google.com/p/android-opencv/


0
投票

我使用OpenCV 2.3.1和Eclipse而不是Netbeans创建了一个可用的Android示例。

这个小tutorial描述了一个跟随手电筒的机器人。该页面还包含必要的步骤和源代码。

© www.soinside.com 2019 - 2024. All rights reserved.