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 ?!

Cypher
  • 2,374
  • 4
  • 24
  • 36

2 Answers2

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);
......
lxm
  • 21
  • 3
  • 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 – Daniel Jonker Dec 20 '12 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);
Community
  • 1
  • 1
Daniel Jonker
  • 844
  • 10
  • 21
  • 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 '12 at 05: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 http://javacv.googlecode.com/git-history/d40508ddddb1f4d87ddfb0ac7fccb1dd69b971b1/samples/FaceRecognition.java I recently converted that into a real time face recognizer for android – Daniel Jonker Sep 29 '12 at 02: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 '12 at 06:19
  • If you use git my repo is public which uses the facerecognition.java which might be of some use: https://github.com/danieljonker/PersonFinder.git not sure if you need more than that to check out the project or not. – Daniel Jonker Sep 30 '12 at 22:10