Ask Your Question

OpenCV on Android - Facial recognition to generate id code?

asked 2013-09-06 13:56:16 -0500

jandresakis gravatar image


Im extremely confident in my android development having used native code in c and c++ before but Ive come across a project that Im undertaking and I would like to use openCV on android to generate a score or code that I can use rather than try to match a picture against a picture. Are there any resources in the sdk samples that show how to do something similar? Any links to examples or blogs with other opencv tutorials on android would be much appreciated as well.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-09-06 14:43:16 -0500

berak gravatar image

there's the FaceRecognizer api in c++, and it's even already wrapped into java(sorry, can't find the docs now) but a small problem will stop you from using it in java as of now - the code's all there, but the creation functions for any of the FaceRecognizer classes did not make it there.

so, actually nice, if you're good at c++ / jni

but the general usage pattern would be like this:

  • use the face-detection to locate the face, crop img to that region.

  • take your train-images, grayscale, resize(to say 90x90) & flatten them to a row, then assemble a N(numImages) x M(numpixels_per_image) (float) Mat from that. you also need a N x 1 Mat with the person ids ( one per picture in the trainmat ), the labels

  • now you can call reco.train(trainmat,labels) on that, and later save the trained state to a xml/yml file, that you can reload later instead of repeating the training over and over.

  • after that, for each prediction, process the image in the same way ( grayscale, resize, flatten ), and call reco.predict(), which will return to you the label/person_id of the best match, and the distance between the test img and the match.

and please, look around on this site for more info, bytefish(who wrote that stuff) put a lot of work into explaining it.

edit flag offensive delete link more


When you say creation functions do you mean the java to native calls to initialize everything? Because that would seem to be an easy fix :)

jandresakis gravatar imagejandresakis ( 2013-09-06 14:52:14 -0500 )edit

probably. it's actually those 3 . the java wrapper can't handle Ptr types atm, so unfortunately the wrapper generation skips those.

and yes, doing your own jni wrapper for those should be fairly easy, just don't forget to put an addref on it ;)

berak gravatar imageberak ( 2013-09-06 15:09:47 -0500 )edit

Cool thanks for the link :) hopefully I should have this up and running in not to long

jandresakis gravatar imagejandresakis ( 2013-09-06 15:15:19 -0500 )edit

Have the wrappers been updated to provide this yet? I don't see the needed operations, though I may not be looking in the right place.

Will Stewart gravatar imageWill Stewart ( 2014-03-26 13:46:08 -0500 )edit

@Will, unfortunately, no .

berak gravatar imageberak ( 2014-03-26 14:27:18 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-09-06 13:56:16 -0500

Seen: 324 times

Last updated: Sep 06 '13