【问题标题】:Face detection not working人脸检测不工作
【发布时间】:2016-02-04 04:50:15
【问题描述】:

this simple example 之后,我将人脸检测功能整合到我的照片应用中。

为了简单起见,我删除了所有形状绘制的东西,我只是在寻找 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"); 
}

【问题讨论】:

    标签: android face-detection google-vision


    【解决方案1】:

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

    【讨论】:

    猜你喜欢
    • 2012-09-26
    • 2019-11-18
    • 2019-02-27
    • 2013-09-24
    • 2013-12-04
    • 2014-08-09
    • 1970-01-01
    • 2022-01-13
    • 2017-05-05
    相关资源
    最近更新 更多