OpenCV to JNI how to make it work?

怎甘沉沦 提交于 2019-12-18 09:53:30

问题


I am tring to use opencv and java for face detection, and in that pursit i found this "JNI2OPENCV" file....but i am confused on how to make it work, can anyone help me?

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

and the following is the 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();   
    }
}

CAn anyone tell me how can i make this work on Netbeans?? I tried Google but help on this particular topic is very meger.

I have added the whole folder as Llibrary in netbeans project and whe i try to run the file i get the followig wrroes.

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)

CAn anyone tell me the exact way to work with this? like what all i have to do?


回答1:


If you are using JNI on Windows, Dependency Walker is going to be your friend.

But, before we get to that first verify that the JRE can find your JNIOpenCV.dll by adding: System.out.println("java.library.path="+System.getProperty("java.library.path")); to the static constructor block.

However, I think the issue here isn't finding your JNIOpenCV.dll file, but a file that it depends on. Open your .dll in dependency walker (just drag it in there) and look out for any error messages (except msjava.dll - ignore that, it doesn't matter). Most likely my hunch is that you need the Microsoft Visual C/C++ runtime libraries, download them from the Visual Studio website and put them in the same folder as your dll.

Best of luck!




回答2:


You should take a look here, a few of the examples are hooked up with JNI:

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




回答3:


I have created a working Android example using OpenCV 2.3.1 and Eclipse instead of Netbeans.

This small tutorial describes a robot following torchlight. The page contains the necessary steps and the source code as well.



来源:https://stackoverflow.com/questions/2441198/opencv-to-jni-how-to-make-it-work

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