1

按照这个简单的示例,我将人脸检测整合到我的照片应用程序中。

为简单起见,我删除了所有形状绘图的东西,我只是在寻找 API 来计算照片中头像的数量。

使用前置摄像头,我拍摄了一张照片,并且始终如一地并且没有失败,它没有检测到任何面孔。

每次我运行代码时,日志中都会出现一个非常可疑的警告(这似乎与我正在做的事情没有任何关系,但每次都会出现 - 警告是:

W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.

W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.

这是我的代码

照片回调

PictureCallback jpegCallback = new PictureCallback() {
    public void onPictureTaken(byte[] data, Camera camera) {
        try {

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferQualityOverSpeed = true;
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            options.inPurgeable = true;
            options.inInputShareable = true;
            options.inMutable = true;
            Bitmap temp = BitmapFactory.decodeByteArray(data, 0,
                    data.length, options);

            countHeads(temp);               

        } catch (Exception e) {
            Log.d(TAG, "onPictureTaken callback failed : " + e);
        } 
    }
};

总柜台

private void countHeads(Bitmap b){
    Frame frame = new Frame.Builder().setBitmap(b).build();

    FaceDetector faceDetector = new FaceDetector.Builder(getApplicationContext()).setTrackingEnabled(false)
            .build();

    if(!faceDetector.isOperational()){
        BPCAlertDialog.alert(this, "Can't build face detection");
        return;
    }
    SparseArray<Face> faces = faceDetector.detect(frame);
    //this always prints 0
    Log.d(TAG, "I COUNT " + faces.size() + " FACES IN THIS PHOTO"); 
}
4

1 回答 1

2

事实证明,即使 Activity 是为 Landscape 设置的,我还是在侧身拍摄照片(将手机保持为纵向)。我还没有彻底反省具体的限制是什么,但看起来这些面孔需要与预期的方向对齐。当我弄清楚更多时,我会添加到这个答案中。

于 2015-11-03T21:24:09.500 回答