face recognition on android [closed]

asked 2013-11-04 10:33:03 -0500

updated 2013-11-04 11:05:24 -0500

berak gravatar image

Hi all! After two days' coding, I successfully make face recognition algorithm of opencv run on Android, and it is awesome! But, I still have some problems which seem to be my bottleneck. Image frames captured by the Java Camera(using OpenCV for Android) is Mat, and, as the same as the samples, I pass the nativeObjAddr(a long value) of the Mat to the native layer, it works well. Since I don't want to train the images every time a image frame comes, so I saved the model to a file in initialize method, and load it when recognizing. But my problem is, is there any better way for me? Like the way dealing with image frames which passes the address of the Mat, can I save the address of the model, and rebuild it when recognizing? Actually, I tried many many times, but all failed. Anyone can help? Any advice will be appreciated.

some codes of current native layer likes this:

JNIEXPORT jint JNICALL Java_edu_thu_xface_libs_XFaceLibrary_nativeInitFacerec(
    JNIEnv * jenv, jclass jclazz, jstring jdatapath, jstring jmodelpath) {
// get images and label by reading file
Ptr < FaceRecognizer > model = createEigenFaceRecognizer();
model->train(images, labels);

JNIEXPORT jint JNICALL Java_edu_thu_xface_libs_XFaceLibrary_nativeFacerec(
    JNIEnv * jenv, jclass jclazz, jstring jmodelpath, jlong addr) {
const char* mpath = jenv->GetStringUTFChars(jmodelpath, NULL);
string modelpath(mpath);
Mat sample = *((Mat*) addr);
//process sample mat first
Ptr < FaceRecognizer > model = createEigenFaceRecognizer();
return model->predict(sample);}
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-14 10:59:52.783050


you could try to extract the pointer from the (trained) Ptr<FaceRecognizer> and save that:

Ptr < FaceRecognizer > model = createEigenFaceRecognizer();



FaceRecognizer * reco = model->get();

return reco;

berak gravatar imageberak ( 2013-11-04 11:09:34 -0500 )edit

Can you give more details? get method needs some parameter for model, do you mean "model.obj", I tried to return the address of "model.obj", but I get wrong address when returned to Java, and can't rebuild the Face Recognizer when I call next time. By the way, there seems to be some problems in JNI when passing jlong, can you help me? Thank you.

hujiawei090807 gravatar imagehujiawei090807 ( 2013-11-05 08:39:54 -0500 )edit

oh sorry, yes, model.obj (got confused with the 3.0 version)

berak gravatar imageberak ( 2013-11-05 08:50:12 -0500 )edit