2015-10-07 71 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 
}