Ask Your Question
0

unstable face recognition using OpenCV

asked 2014-01-06 08:33:56 -0600

dervish79 gravatar image

updated 2014-04-28 01:34:50 -0600

berak gravatar image

I've already asked my question in stackoverflow.

I’m developing an android application for face recognition, using JavaCV which is unofficial wrapper of OpenCV. After importing (com.googlecode.javacv.cpp.opencv_contrib.FaceRecognizer) I apply and test the following known methods:

LBPH using createLBPHFaceRecognizer() method
FisherFace using createFisherFaceRecognizer() method
EigenFace using createEigenFaceRecognizer() method

Before I recognize the detected face, I correct the rotated face and crop the proper zone, inspiring from this method

In general when I pass on camera a face already exist in the database, the recognition is ok. But this is not always correct. Sometimes it recognizes the unknown face (not found in Database of trained samples) with a high probability. When we have in the DB two or more faces of similar features (beard, mustache, glasses...) the recognition may be highly mistaken between those faces!

To predict the result using the test face image, I apply the following code:

public String predict(Mat m) {

    int n[] = new int[1];
    double p[] = new double[1];
    IplImage ipl = MatToIplImage(m,WIDTH, HEIGHT);

    faceRecognizer.predict(ipl, n, p);

    if (n[0]!=-1)
     mProb=(int)p[0];
    else
        mProb=-1;
        if (n[0] != -1)
        return labelsFile.get(n[0]);
    else
        return "Unkown";
}

I can’t control the threshold of the probability p, because:

Small p < 50 could predict a correct result.
High p > 70 could predict a false result.
Middle p could predict a correct or false.

As well, I don’t understand why predict() function gives sometime a probability greater than 100 in case of using LBPH??? and in case of Fisher and Eigen it gives very big values (>2000) ?? Can someone help in finding a solution for these bizarre problems? Is there any suggestion to improve robustness of recognition? especially in case of similarity of two different faces.

The following is the entire class using Facerecognizer:

import com.googlecode.javacv.cpp.opencv_imgproc; import com.googlecode.javacv.cpp.opencv_contrib.FaceRecognizer; import com.googlecode.javacv.cpp.opencv_core.IplImage; import com.googlecode.javacv.cpp.opencv_core.MatVector;

import android.graphics.Bitmap; import android.os.Environment; import android.util.Log; import android.widget.Toast;

public class PersonRecognizer {

public final static int MAXIMG = 100;
FaceRecognizer faceRecognizer;
String mPath;
int count=0;
labels labelsFile;

 static  final int WIDTH= 128;
 static  final int HEIGHT= 128;;
 private int mProb=999;


PersonRecognizer(String path)
{
  faceRecognizer =  com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer(2,8,8,8,200);
 // path=Environment.getExternalStorageDirectory()+"/facerecog/faces/";
 mPath=path;
 labelsFile= new labels(mPath);


}

void changeRecognizer(int nRec)
{
    switch(nRec) {
    case 0: faceRecognizer = com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer(1,8,8,8,100);
            break;
    case 1: faceRecognizer = com.googlecode.javacv.cpp.opencv_contrib.createFisherFaceRecognizer();
            break;
    case 2: faceRecognizer = com.googlecode.javacv.cpp.opencv_contrib.createEigenFaceRecognizer();
            break;
    }
    train();

}

void add(Mat m, String description) {
    Bitmap bmp= Bitmap.createBitmap(m.width(), m.height(), Bitmap.Config.ARGB_8888);

    Utils.matToBitmap(m,bmp);
    bmp= Bitmap.createScaledBitmap(bmp, WIDTH, HEIGHT, false);

    FileOutputStream f;
    try {
        f = new FileOutputStream(mPath+description+"-"+count+".jpg",true);
        count++;
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, f);
        f.close ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2014-05-15 10:53:12 -0600

hello there can you explain methode canpredict(Mat m)

edit flag offensive delete link more

Comments

if you mean canPredict(), it probably checks, if there was training data loaded or not

btw, meherfrioui, this should have gone into a comment. it's not an answer.

berak gravatar imageberak ( 2014-05-15 10:56:56 -0600 )edit

Question Tools

Stats

Asked: 2014-01-06 08:33:56 -0600

Seen: 1,473 times

Last updated: May 15 '14