Remember that you can detect faces using the older FaceDetector API . It works from API level 1 and should work on all phones with a camera. It also returns you a frame when a face is detected.
public Rect findFace(Bitmap bmp) { // Ask for 1 face Face faces[] = new FaceDetector.Face[1]; FaceDetector detector = new FaceDetector( bmp.getWidth(), bmp.getHeight(), 1 ); int count = detector.findFaces( bmp, faces ); Face face = null; if( count > 0 ) { face = faces[0]; PointF midEyes = new PointF(); face.getMidPoint( midEyes ); Log.i( TAG, "Found face. Confidence: " + face.confidence() + ". Eye Distance: " + face.eyesDistance() + " Pose: (" + face.pose( FaceDetector.Face.EULER_X ) + "," + face.pose( FaceDetector.Face.EULER_Y ) + "," + face.pose( FaceDetector.Face.EULER_Z ) + "). Eye Midpoint: (" + midEyes.x + "," + midEyes.y + ")" ); float eyedist = face.eyesDistance(); PointF lt = new PointF( midEyes.x - eyedist * 2.0f, midEyes.y - eyedist * 2.5f ); // Create rectangle around face. Create a box based on the eyes and add some padding. // The ratio of head height to width is generally 9/5 but that makes the rect a bit to tall. return new Rect( Math.max( (int) ( lt.x ), 0 ), Math.max( (int) ( lt.y ), 0 ), Math.min( (int) ( lt.x + eyedist * 4.0f ), bmp.getWidth() ), Math.min( (int) ( lt.y + eyedist * 5.5f ), bmp.getHeight() ) ); } return null; }
source share