This is an example iPhone application that performs face detection and recognition using the excellent OpenCV framework.
All dependencies are included within the repo, simply download and run it on your device. Obviously, the app needs the camera to function, and will not work on the simulator.
The app was tested on iOS 6 using an iPhone 5. Other iOS versions and devices will probably work, but I can't say for sure.
The first step will be to train the model with some faces. Importing existing images is not supported for various reasons, so you will need to capture face images using the camera. The steps to perform this are as follows:
- Navigate to the "People" tab, and add a new person.
- Once the person shows up in the list, tap on their name.
- Instructions are provided on how to capture images of that person's face for later detection. The app uses the front-facing camera (the one pointing at you when you are using the device).
- When capturing images, try and move the camera slightly to capture different angles of your face.
- Repeat for other people as necessary.
Once the app has at least one person in the database with face images, face recognition can occur.
Navigate to the "Recognize" tab, and the camera will start. If a face is detected, it will be highlighted with a red box. If that face is recognized from the database, it will be highlighted with a green box. The name of that person will appear on top of the image, and a confidence score of the face recognition will be displayed.
The confidence value provided by the face recognition algorithm is basically a difference score between the input image and what the model knows about a given person's face.
Therefore, a lower confidence score means the model is more confident of its suggested match - because there is less of a difference between the input face and the faces of that person in the database.
The CustomFaceRecognizer class can be initialized using one of 3 different face recognition algorithms. By default it uses an Eigenfaces algorithm, but you can change this easily by using a different initWith method. For a discussion of the various algorithms available, see this OpenCV tutorial.
The available algorithms are:
- Eigenfaces (initWithEigenFaceRecognizer)
- Fisherfaces (initWithFisherFaceRecognizer)
- Local Binary Patterns Histogram (initWithLBPHFaceRecognizer)
After you have initialized the recognizer with one of these methods, training and recognition works the same. You can switch algorithms without having to re-train the model.