2015-10-07 86 views
0

我正在創建人臉檢測應用程序。當我嘗試啓動人臉檢測,我得到以下錯誤:嘗試啓動人臉檢測時訪問ByteBuffer時出錯

E/NativeFaceDetectorImpl: Native face detection failed 
E/NativeFaceDetectorImpl: java.lang.RuntimeException: Error accessing ByteBuffer. 

這裏是我的代碼部分:

Context context = getApplicationContext(); 
    FaceDetector detector = new FaceDetector.Builder(context) 
      .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS) 
      .setMode(FaceDetector.ACCURATE_MODE) 
      .build(); 

    detector.setProcessor(
      new MultiProcessor.Builder<>(new FaceTrackerFactory()) 
        .build()); 

    if (!detector.isOperational()) { 
     Log.w(TAG, "Face detector dependencies are not yet available."); 
    } 

    mCameraSource = new CameraSource.Builder(context, detector) 
      .setFacing(CameraSource.CAMERA_FACING_BACK) 
      .setRequestedFps(30.0f) 
      .build(); 

顯示錯誤,當我做mCameraSource.start(),即使這樣做時沒有檢測到錯誤,應用程序不會崩潰,它只是在控制檯上反覆顯示該錯誤。

+1

您使用的是Android和Google Play服務的哪個版本?我似乎記得在使用Gingerbread和Google Play Services 7.8時存在這樣的問題。如果這是同一個問題,那麼如果您使用Google Play Services 8.1,則應該修復此問題。 – pm0733464

+0

我正在使用Google Play服務版本8.1並針對Android API 19編譯,所以我想這不是問題:/ –

回答

0

所以我才弄清楚是什麼問題。我試圖使用Google Play服務版本8.1.0中的Mobile Vision API編譯Android API 19。這是我的build.gradle和它沒有工作

dependencies { 
    compile 'com.google.android.gms:play-services-vision:8.1.0' 
} 

android { 
    compileSdkVersion 19 
} 

我switchted到谷歌的7.8版本的播放服務,現在,它工作正常

dependencies { 
    compile 'com.google.android.gms:play-services-vision:7.8.+' 
} 

android { 
    compileSdkVersion 19 
} 

另外請注意,我有另一個類似的項目編制爲Android API 23,用那個版本,谷歌Play服務8.1 工作

dependencies { 
    compile 'com.google.android.gms:play-services-vision:8.1.0' 
} 

android { 
    compileSdkVersion 23 
}