2015-11-03 123 views
0

正在关注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"); 
} 

回答

1

原来的问题是,我正在采取侧身照片(持有人像电话),即使该活动建立的景观。我还没有彻底反思具体的局限性,但似乎需要将面孔与预期的方向对齐。我会更多地了解这个答案。

+0

如果您知道方向,您可以在创建相框时进行设置。脸部检测器将考虑到这一点,并将检测脸部,就好像它是在一张直立的照片。请参阅此处了解更多详情:https://developers.google.com/android/reference/com/google/android/gms/vision/Frame.Builder.html#setRotation(int) – pm0733464