【问题标题】:FaceDetector does not recognize any face taken with the intent ACTION_IMAGE_CAPTUREFaceDetector 无法识别使用意图 ACTION_IMAGE_CAPTURE 拍摄的任何面部
【发布时间】: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。如果你需要帮助,你应该通过解释上面的代码做什么来扩大谁可以帮助你,并链接到你需要的任何文档或解释。 那么你更有可能得到帮助/答案

标签: android face-recognition


【解决方案1】:

经过一番挖掘,我找到了这段代码的问题。有两个要求,一是位图应该使用 RGB_565 解码,并且无论图像的朝向如何,面部都应该向上。这段代码的问题是,首先是的,它使用正确的格式进行解码,但面部是侧向的。一旦图像被旋转,它就不是在 RGB_565 中创建的。所以我必须将旋转后的图像转换为 RGB_565,这可以通过 Bitmap.copy https://developer.android.com/reference/android/graphics/Bitmap.html#copy(android.graphics.Bitmap.Config, boolean 轻松完成

然后运行 ​​FaceDetector 代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-05
    • 2020-02-28
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多