I am trying to get the faces of an image taken using the ACTION_IMAGE_CAPTURE intent. But for some reason the FaceDetector never finds an image. This is my code
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
options.inSampleSize = calculateInSampleSize(options,desiredWidth,desiredHeight);
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(filePath,options);
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
Matrix matrix = new Matrix();
boolean recycle = true;
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.postRotate(90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.postRotate(180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.postRotate(270);
break;
default:
recycle = false;
break;
}
Bitmap finalBM = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
if(recycle)
bitmap.recycle();
FaceDetector.Face[] faces = new FaceDetector.Face[1];
FaceDetector faceDetector = new FaceDetector(bitmap.getWidth(), bitmap.getHeight(),1);
int numFaces = faceDetector.findFaces(bitmap,faces);
return finalBM;
At this point all i am doing is checking the numFaces variable to see if any face was detected. But every single time is 0 even thought the picture is just my own face. Also I am rotating the image if necessary. I tried to detect the faces before the rotation and it did not work.