0

I'm trying to develop a Face Recognition app on Android and I'm using JavaCV+OpenCV 2.4.2 to use Philipp Wagner's Face Recognition Class.

The class has a Train Method which accepts arrays of Mat and Integer as input (in C++) :

vector<Mat> images;
vector<int> labels;

Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
model->train(images, labels);

JavaCV accepts the attributes of 'train' method as train(MatVector arg0, CvArr arg1) AND here is where I'm stuck !

I'm having a little trouble trying to load data into CvArr... I already have the labels as strings of data... but I can't seem to find a way to insert these labels as an array to CvArr... let's call it a lack of OpenCV knowledge... can anybody help me with this issue ?!

P.S : BTW I know that iplImage can be used instead of CvArr in this method but the problem still remains : HOW can I insert an Array of <int> into iplImage ?!

2 Answers 2

2
MatVector images = new MatVector(numberOfImages);
CvMat labels= cvCreateMat(1,numberOfImages,CV_32SC1);

images.put(0, cvLoadImage("D:/att_faces/test/p1/1.pgm"));
labels.put(0,0);

images.put(1, cvLoadImage("D:/att_faces/test/p1/2.pgm"));
labels.put(1,0);

images.put(2, cvLoadImage("D:/att_faces/test/p2/1.pgm"));
labels.put(2,1);

images.put(3, cvLoadImage("D:/att_faces/test/p2/2.pgm"));
labels.put(3,1);

......
FaceRecognizerPtr model = createEigenFaceRecognizer(0,1000);
model.get().train(images, labels);
......
1
  • Does that work? It looks so simple yet I could never figure it out. Just curious since it hasn't been ticked as correct answer Dec 20, 2012 at 22:43
0

From what I just read here you need to use pointers so like this should work:

//Total number of faces in database
final int numberOfImages = 20;

Integer[] labels = new Integer[numberOfImages];
//add integers to array
...

IntPointer iPoint = new IntPointer();

for (Integer i : labels) {
     i.put(i)
}

CVArr labelsCV = new CvArr(i);
4
  • one question though... where exactly did you use 'iPoint' in your code ?! shouldn't it be 'iPoint.put(i)' instead of 'i.put(i)' ?! and shouldn't the last line be more like 'CvArr labelsCV = new CvArr (iPoint)' ?!
    – Cypher
    Sep 21, 2012 at 5:51
  • Yeah it probably should, my bad. Was writing this in a hurry. However I tried this recently and couldn't make it work. Do you need the fisherface algorithm? would eigenface do? if so you could look at javacv.googlecode.com/git-history/… I recently converted that into a real time face recognizer for android Sep 29, 2012 at 2:16
  • Both will do ! I'll take a look at it (in spare time) and check if I can run it too or not...
    – Cypher
    Sep 30, 2012 at 6:19
  • If you use git my repo is public which uses the facerecognition.java which might be of some use: github.com/danieljonker/PersonFinder.git not sure if you need more than that to check out the project or not. Sep 30, 2012 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.