OpenCV 3.3.0 predict mismatches with all
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.
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 !)
"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)
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?
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 ?)
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.
So sad, But we have implemented in iOS there this works perfectly. And it returns -1 there if there is no match. How?
i'd rather recommend, you cancel the idea completely.
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?
let's cut it short: you don't know, what you're doing, at all here. please reconsider messing with other ppl's security
Okay, Can you suggest any other framework for authentication purpose.