28

How can I do facial recognition on the iPhone. Could someone provide me with references/articles to point me in the right direction please? I have done research and realised that I need to do face detection first to extract the image and then do facial recognition by comparing it with other images within a database.

I have realised that I have do the face detection by using OpenCV or by utilising iOS 5.0 and upwards to detect the face. I am unsure on the facial recognition (I plan on storing images on a remote database and then doing the comparison against the remote database).

jscs
  • 63,694
  • 13
  • 151
  • 195
Rory Lester
  • 2,858
  • 11
  • 49
  • 66
  • 1
    possible duplicate of [Face Recognition in OpenCV](http://stackoverflow.com/questions/4856929/face-recognition-in-opencv) – karlphillip Apr 22 '12 at 22:09
  • 1
    also possible duplicate of [How to do Face Recognition using OpenCV?](http://stackoverflow.com/questions/7949494/how-to-do-face-recognition-using-opencv) and many more. – karlphillip Apr 22 '12 at 22:10
  • 1
    possible duplicate of [How can I perform facial recogntion on iOS?](http://stackoverflow.com/questions/8020842/how-can-i-perform-facial-recogntion-on-ios) – Monolo Jul 17 '12 at 05:34

5 Answers5

14

Face detection

I would use the Haarcascades available in open CV to perform quick and accurate face detection.

http://opencv.willowgarage.com/wiki/FaceDetection

Face recognition

I would use a method such as Principal Component Analysis (PCA) a.k.a eigenfaces.

http://www.cognotics.com/opencv/servo_2007_series/part_5/index.html

That link shows a tutorial on how to get that working with OpenCV - I think this is written for C but i'm sure you can get the basic jist of it.

You could also look at implementing it yourself if you feel brave (it's not too bad)...

http://www.face-rec.org/algorithms/PCA/jcn.pdf

http://blog.zabarauskas.com/eigenfaces-tutorial/

Database

I actually did something similar to you albeit on a PC not an iPhone but its still the same concept. I stored all my images in the database as Blob data types then loaded them into my program when necessary.

Edit

The database is a particularly tricky part of the system as this is where the biggest bottleneck is. In my application, I would go through the following steps...

  1. Open application and grab training images from database
  2. Generate training set based on these images
  3. Once 1 and 2 have been completed the system is very quick as it just performs recognition against the training set.

Fortunately for me, my database server was located on a LAN therefore speed wasn't a problem, however I can see why you have an issue due to the fact that on a mobile device you have a limited data connection (speed/bandwidth). You can compress the images however this may lead to a worse recognition rate, due to image quality reduction and also you will have to decode on the device. There is also the issue of how to expose the remote database to the application, however I do believe this is possible using PHP and JSON (and other technologies, see below).

Retrieving data from a remote database

Maybe you could do an initial synchronize with the database so that the images are cached on the phone? One way or another I think you are probably going to have to have the images on the phone at some point regardless.

Figuring out the best way to store the recognition data/images in the database was one of the biggest challenges I faced so I would be interested to hear if you find a good method.

Community
  • 1
  • 1
TomP89
  • 1,420
  • 3
  • 11
  • 29
  • Many thanks for the response. In regards to the database, did the program connect to the database and then download all the images then perform the recognition for each?. That wouldent be of much use to me since it would be a mobile device with limited capabilities. (im probably wrong so please correct me, i'm at the stage where im just trying to figure out algorithms/psudo code on how to approach things for later on). – Rory Lester Apr 25 '12 at 15:53
  • @RoryLester Hi, I have updated the answer to hopefully answer some of your questions. Good Luck! – TomP89 Apr 26 '12 at 20:49
  • @TomP89 Face recognition links are not working anymore...It would be great to update answer, if you know some new links for face recognition. – Dave Jun 25 '15 at 12:14
  • @TomP89, In my iOS app, user will access their data with verifying their face with camera roll. After installing the app, new user will be registered in app. How I can do with ARKit and MLKit in swift ? Right now , I can create .mlmodel with user photos for specific person and add it to my project. But how I can do it for later registered user ? Should process the .mlmodel from macOS machine and send it to app with a API ? Is their any way to simple verify face of user to recognize their name tag identity ? Thanks in advance. – Jamshed Alam Aug 22 '19 at 05:31
12

As you pointed out, the first step (detection of the face) is easy with iOS 5 and CoreImage.framework. Quick example:

CIImage *image = [CIImage imageWithCGImage:image_ref];
NSDictionary *options = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy];
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:options];
NSArray *features = [detector featuresInImage:image];

for (CIFaceFeature *feature in features)
{
  CGRect face_bounds = [feature bounds];
  CGPoint mouth_position = [feature mouthPosition];
  // do something with these values
}

With regards to the second part of your question (i.e. facial recognition), I shall leave that to someone more qualified than myself to answer. :)

Aidan Steele
  • 10,999
  • 6
  • 38
  • 59
  • 10
    This is face **detection**, not **recognition**. – UIAdam Apr 23 '12 at 01:27
  • 1
    @UIAdam: Excellent point, I have edited to clarify that in my answer. The question indicates that the OP understands the two parts to the task and I have modified the answer accordingly. – Aidan Steele Apr 23 '12 at 02:41
9

You probably want to look at the midian project by Pedro Centieiro, which performs Face Recognition on iOS 5 with OpenCV. It's on github at:

It uses parts of my libfacerec, so it supports Eigenfaces, Fisherfaces and Local Binary Patterns Histograms for face recognition.

bytefish
  • 3,697
  • 1
  • 29
  • 35
2

Face recognition can be implemented as a machine learning algorithm. This book has a chapter that describe this task and how to implement it. Worth the reading!

It uses Single value decomposition (SVD), more specifically the Tensor SVD method.

João Daniel
  • 8,696
  • 11
  • 41
  • 65
1

We have following face recognition api :-

1. OpenCV

2. Kairos

3. CraftarAR

4. AAFaceDetection

5. MoodMe

And in my opinion CraftAR is good if you want to use in offline application and in case you want to use online then Kairos is best. While OpenCV is also a famous and reliable option.

And best advantage of OPENCV is that it is open source.

Please search these on google to get more details and also look at github examples to see how these api work.

Shubham Mishra
  • 1,303
  • 13
  • 24