Ask Your Question

hujiawei090807's profile - activity

2013-11-05 08:39:54 -0600 commented question face recognition on android

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.

2013-11-04 10:33:03 -0600 asked a question face recognition on android

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);
model->save(modelpath);
//...}

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();
model->load(modelpath);
return model->predict(sample);}