How to construct the parameters required by FaceRecognizer in Java

asked 2015-08-24 01:58:44 -0500

chinadragon0515 gravatar image

updated 2015-08-25 00:33:17 -0500

I build a JNI to create LBPHFaceRecognizer, and I can get dll created as expected, but I met issue when call it during train,

Here are the code I construct the parameters for train and the exception I got,

    List<Mat> images = new ArrayList<Mat>(imageFiles.length);
    Mat labels = new Mat(imageFiles.length, 1,  CvType.CV_32SC1);
    int counter = 0;
    for (File image : imageFiles) {
        Mat img = Highgui.imread(image.getAbsolutePath());
        int label = Integer.parseInt(image.getName().split("\\-")[0]);
        images.add(counter,img);
        labels.put(counter, 1, label);
        counter++;
    }

OpenCV Error: Bad argument (The images are expected as InputArray::STD_VECTOR_MAT (a std::vector<mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >).) in train, file D:\Project\javacv\opencv\opencv\sources\modules\contrib\src\facerec.cpp, line 913

Exception in thread "main" java.lang.Exception: unknown exception

at org.opencv.contrib.FaceRecognizer.predict_0(Native Method)
at org.opencv.contrib.FaceRecognizer.predict(FaceRecognizer.java:173)
at OpenCV2411FaceRecognizer.main(OpenCV2411FaceRecognizer.java:149)

Can anyone help me on this?

And when I tried to load a trained result, I just get exception with no meaningful message, any tips on how to fix this? The exception is

Exception in thread "main" java.lang.Exception: unknown exception

at org.opencv.contrib.FaceRecognizer.load_0(Native Method)
at org.opencv.contrib.FaceRecognizer.load(FaceRecognizer.java:104)
at OpenCV2411FaceRecognizer.main(OpenCV2411FaceRecognizer.java:131)
edit retag flag offensive close merge delete

Comments

can you add the train line ? and the code for the prediction ?

berak gravatar imageberak ( 2015-08-25 01:34:31 -0500 )edit

Here are the code

FaceRecognizer lbphFaceRecognizer = new LBPHFaceRecognizer(); 
lbphFaceRecognizer.train(images, labels);   
int[] predictedLabel = {-1}; double[] confidence ={0.88}; 
lbphFaceRecognizer.predict(testImage, predictedLabel, confidence);
chinadragon0515 gravatar imagechinadragon0515 ( 2015-08-25 07:48:49 -0500 )edit
1

Any one has any tips or suggestions? And anyone know is there a plan to make default java interface contains FaceRecognizer in opencv 3.0?thanks.

chinadragon0515 gravatar imagechinadragon0515 ( 2015-08-27 19:20:49 -0500 )edit