OpenCV 3.3.0 predict mismatches with all

asked 2017-09-19 05:33:47 -0600

gunas.idesign gravatar image

updated 2017-09-19 06:40:18 -0600

We called predict in Java class like this.

int[] label = new int[1];
double[] d = new double[1];
label[0] = -1;
d[0] = 0.0;
predict(mGrey.getNativeObjAddr(), label, confidence);
Log.v(TAG, "Prediction completed, label[0]: " + label[0] + ", d[0]: " + d[0]);

And in JNI predict method defined like this.

JNIEXPORT void JNICALL Java_com_opencv.test_FaceRecognizer_predict
        (JNIEnv *env, jobject thisObj, jlong image1, jintArray label, jdoubleArray confidence) {
    Mat &mGr = *(Mat *) image1;
    jint *labelBody = (*env).GetIntArrayElements(label, 0);
    jdouble *confidenceBody = (*env).GetDoubleArrayElements(confidence, 0);
    int &myLabel = labelBody[0];
    double &myConfidence = confidenceBody[0];
    LOGD("Prediction started in JNI");
    model->predict(mGr, myLabel, myConfidence);
    LOGD("Prediction ended in JNI");
    (*env).ReleaseIntArrayElements(label, labelBody, 0);
    (*env).ReleaseDoubleArrayElements(confidence, confidenceBody, 0);
}

Here model is declared like this,

Ptr<LBPHFaceRecognizer> model;

And this model has been accessible by all methods in this JNI class.

And initiated like this.

model = LBPHFaceRecognizer::create();

I got logcat output as

Prediction completed, label[0]: 1, d[0]: 38.56067116659108

Don't know how it returns 38 % confidence level for some other person. Is there anything wrong in my code?

Previously I trained opencv with 10 images of one person, those images are 250X250 sizes.

This predict method predicts all members with same level of confidence. Don't know how?

Any help will be highly appreciated.

edit retag flag offensive close merge delete

Comments

1

the confidence is actually the chi-sqr distance between your test image and the closest from the db (smaller==better). it's NOT a similarity in percent ! (more the opposite !)

berak gravatar imageberak ( 2017-09-19 05:39:52 -0600 )edit
1

"I trained opencv with 10 images of one person" -- unfortunately, that does not make any sense at all.

are you trying to build an "authentifaction" system (for a single person) with this ? it won't ever work.

you probably misunderstood, how it works, and what it should be used for (identification, find closest from db)

berak gravatar imageberak ( 2017-09-19 05:41:29 -0600 )edit

Yes, I am trying to build an "authentication" system for a single person. I don't want to authenticate other persons. This predict method always returned label as 1, and same confidence value for all person, May I know how to find the difference between trained person and some other person?

gunas.idesign gravatar imagegunas.idesign ( 2017-09-19 05:47:39 -0600 )edit

so, forget about using opencv's face recognition classes entirely, then, they were not made for your purpose.

(and maybe, if you're lacking any computer-vision knowledge, -- you should not do this at all ?)

berak gravatar imageberak ( 2017-09-19 06:19:41 -0600 )edit

Hi, Now I trained with 2 persons, This predicts perfectly both. But this predicts other persons also says either one within these 2 person. My question is why it didn't return -1(I am passing this as value), why it return trained person label.

gunas.idesign gravatar imagegunas.idesign ( 2017-09-19 06:22:57 -0600 )edit

So sad, But we have implemented in iOS there this works perfectly. And it returns -1 there if there is no match. How?

gunas.idesign gravatar imagegunas.idesign ( 2017-09-19 06:24:09 -0600 )edit

i'd rather recommend, you cancel the idea completely.

berak gravatar imageberak ( 2017-09-19 06:33:49 -0600 )edit

So sorry, in iOS it returns confidence as very large like above 70 for one label. So we matched with that value. Same as I am expecting larger value in android too. If less then 40 means we said this is that person, Why it returns less than 40 in android only?

gunas.idesign gravatar imagegunas.idesign ( 2017-09-19 06:37:14 -0600 )edit

let's cut it short: you don't know, what you're doing, at all here. please reconsider messing with other ppl's security

berak gravatar imageberak ( 2017-09-19 13:18:54 -0600 )edit

Okay, Can you suggest any other framework for authentication purpose.

gunas.idesign gravatar imagegunas.idesign ( 2017-09-20 00:28:16 -0600 )edit