尝试启动面部检测时访问ByteBuffer时出错

时间:2015-10-07 11:43:28

标签: android android-vision

我正在创建一个人脸检测应用。当我尝试开始面部检测时,出现以下错误:

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 个答案:

答案 0 :(得分:0)

所以我能够弄清楚问题是什么。我正在尝试使用Google Play Services 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
}

我切换到Google Play服务版本7.8,现在正常

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

android {
    compileSdkVersion 19
}

另请注意,我为Android API 23编译了另一个类似的项目,对于该版本,Google Play Services 8.1 正在运行

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

android {
    compileSdkVersion 23
}