【发布时间】:2017-05-16 01:00:53
【问题描述】:
我正在尝试获取使用 ACTION_IMAGE_CAPTURE 意图拍摄的图像的面孔。但由于某种原因,FaceDetector 永远找不到图像。这是我的代码
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;
此时我所做的只是检查 numFaces 变量以查看是否检测到任何人脸。但每一次都是0,甚至认为这张照片只是我自己的脸。如有必要,我还会旋转图像。我尝试在旋转之前检测人脸,但没有成功。
【问题讨论】:
-
如果您只想快速简单地检测人脸,可以使用:github.com/blundell/WoodyFaceDetection(或查看此以了解它是如何进行鲮鱼检测的)
-
除此之外 - 查看您的代码,任何人都可以帮助您的唯一方法是,如果他们以前使用与您在这里相同的方式使用完全相同的 API。如果你需要帮助,你应该通过解释上面的代码做什么来扩大谁可以帮助你,并链接到你需要的任何文档或解释。 那么你更有可能得到帮助/答案