Ask Your Question

Revision history [back]

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);}
click to hide/show revision 2
retagged

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

berak gravatar image

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);}