2015-11-03 128 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