If what you need is to detect faces in images stored on the device, you can definitely do this without hacking the source code of android!
There is a FaceDetector
API that is available under the package android.media
since API 1, which accepts Bitmap
as input (formatted in 565 format) and give you the position of faces in that picture.
Here are the steps you need:
1- Load the Bitmap
and convert it to 565 format
(assuming you have facesPicture
file under your drawable resources)
Bitmap originalBitmap =
BitmapFactory.decodeResource(getResources(),R.drawable.facesPicture);
Bitmap bitmap = originalBitmap .copy(Bitmap.Config.RGB_565, true);
originalBitmap .recycle(); // allow the GC to collect this object
2- Define Face
array to hold the detected faces information and initialize the FaceDetector
int MAX_FACES = 20; // assuming that the image will have maximum 20 faces
FaceDetector.Face[] faces = new FaceDetector.Face[MAX_FACES];
FaceDetector faceDetector =
new FaceDetector(bitmap.getWidth(), bitmap.getHeight(), MAX_FACES);
3- Search for the faces and process results
int facesCount = faceDetector.findFaces(bitmap, faces);
for(int i=0; i<facesCount; i++) {
FaceDetector.Face face = faces[i];
float detectionConfidence = face.confidence(); // over 0.3 is OK
PointF eyesMidPoint = new PointF();
face.getMidPoint(eyesMidPoint);
float eyesDistance = face.eyesDistance();
float rotationX = face.pose(FaceDetector.Face.EULER_X);
float rotationY = face.pose(FaceDetector.Face.EULER_Y);
float rotationZ = face.pose(FaceDetector.Face.EULER_Z);
// Do something with these values
}
You can download a complete project example here which is explained in this article Face Detection with Android APIs
If you want something more advanced you should consider using OpenCV