views:

675

answers:

2

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?

A: 

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!

ianium
Hey Thanks a million for the reply......though i havnt checked the java.library.path thingy ...i opened the JNI2OpenCV.dll in dependency walker and could understand much would you help me in that? http://img221.imageshack.us/img221/5042/helpf.jpg
Here i added and found the java.library.path' java.library.path=C:\Program Files\Java\jdk1.6.0_18\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\Intel\DMIX;C:\OpenCV2.0\bin;C:\Sun\SDK\jdk\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Sun\SDK\bin '
The dependency walker seems to look good, MSJAVA and MPR commonly have errors, so if everything else that isn't visible is fine,t hen it is ok. System.loadLibrary() looks for the library in the path you have above, and since your dll isn't there, it isn't being loaded. You could either move it or use System.load(), which expects the full path and filename (and extension) for the DLL.
ianium
A: 

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

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

peter karasev