Android Face Cropper

Android Face Cropper

Some months ago, while we were developing Dulceida’s app, we realized that most of its photos didn’t show its face after cropping the image to obtain a squared one, so we needed some mechanism to modify that photos and obtain a face-centered image from itself. After some research, iOS team found a library that provided this feature, but there wasn’t anything similar in Android community.

Android Face Cropper

Android Face Cropper

So, now what? Android Face Cropper

We had to build our own library, Android Face Cropper. We started to search tools inside Android SDK to build our approach, and we found two ways to detect faces:

– Using FaceDetector, and FaceDetector.Face. Available since API 1. It detects FaceDetector.Face instances in a bitmap, so it’s a good approach for static images.

– Using Camera.FaceDetectionListener and Camera.Face. Available since API 14. It detects Camera.Face instances asynchronously from the camera stream. It’s a good approach if you need to detect faces in real time from the device’s camera. Moreover, Camera.Face instances obtain more information about the detected face than FaceDetector.Face, but not all the devices are capable to detect all kind of data.

It seems obvious that we needed the first one, so it’s what we used in our library. Then, the most code of our library is a single method that receives a Bitmap and returns an object that contains that Bitmap and the minimum area of the detected faces. It supports multiple faces detection, and recently we added a debug mode to paint red circles over detected faces, and another method to obtain the original image with the cropped area rectangle painted in green.

 

Android Face Cropper

Android Face Cropper

 

Finally, you can find our code and a sample app in Android Face Cropper Github repo. Hope you like and use it, and feel free to fork and contribute!

Check it out at Lafosca Github
1 Comment
  • Arol

    July 31, 2014 at 3:08 pm Reply

    Awesome work, fellow! Only best engineers use themselves as test apes 😀

Post a Comment