Face Detection in Android

Download the source code of this article.

Recently a friend of mine emailed me and asked about how to do face detection in Android. I created a sample application for him, and I think it is better to share it with you all.

Android provides a convenient class FaceDetector for detecting faces in a bitmap object. This class gives you an array of Face objects that represents the faces found in the given bitmap. The Faces class contains the information about each face detected such as distance between the eyes, mid-point between the eyes and the pose (the rotation around X, Y and Z axis) of the face.

First we initialize the FaceDetector class by passing the height and width of the bitmap and maximum faces to detect. Once we created the FaceDetector object, we can use the findFaces method to start face detection. The findFaces method accepts a bitmap and an array of Face objects. The length of the array should be equal to the number we passed to the FaceDetector constructor. Once the system finished detecting faces, the method returns the number of faces detected and fills the array with the information about the faces detected.

On limitation of this class is that it only supports bitmaps in RGB_565 format. So if you have a bitmap in another format you have to convert it to RGB_565 format.

The sample application is a simple one just to show the use of FaceDetector class. It allows you to take a picture using the camera. Once the picture is taken the bitmap is converted to RGB_565 format and pass it to FaceDetector and draws a red rectangle around the detected faces. Hope this is helpful to you.

Happy Face Detection! Smile


4 Responses

  1. rAMIZ April 15, 2012 / 11:43 am

    thanks aot man

  2. lzz June 26, 2012 / 9:40 am

    I can’t check out your source codes.. does it still exists?

  3. Mahendra August 4, 2012 / 8:28 am

    Thanks for this I got a solution for my application……………..

  4. Deepa February 12, 2013 / 12:02 pm

    How to do face Recongtion using sample database in android App using opencv/javacv lib

Leave a Reply

Your email address will not be published. Required fields are marked *