Android Face Cropper: qué es y cómo lo hicimos
Lo sentimos, este post sólo está disponible en inglés.
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.
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 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.
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