【问题标题】:Why isn't the new Play-Services FaceDetector available on some devices?为什么新的 Play-Services FaceDetector 在某些设备上不可用?
【发布时间】:2016-09-15 00:21:05
【问题描述】:

背景

Google 几个月前发布了一个新的 API 来检测位图上的人脸:

它应该比built-in FaceDetector class 更快更好,并且与它相比没有任何限制/限制(例如输入位图需要配置为 565 ,位图宽度均匀,并且具有最大面数检测)。

代码也很简单:

清单:

<meta-data
     android:name="com.google.android.gms.vision.DEPENDENCIES"
     android:value="face" />

java:

FaceDetector faceDetector = new
       FaceDetector.Builder(getApplicationContext()).setTrackingEnabled(false)
.build();
if(!faceDetector.isOperational()){
   //show error
  return;
  }
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Face> faces = faceDetector.detect(frame);

问题

该API似乎在某些设备上不可用,调用“isOperational()”时返回“false”。

  • 在 Nexus 4 (Android 4.4.4) 和 Nexus 5 (Android 6.0.1) 上根本无法使用
  • 在 Nexus 5x (Android 6.0.1) 和 Galaxy S4 (Android 5.0) 上运行良好
  • 在 LG G2 (Android 4.2.2) 上,它仅在示例的第二次运行时有效。

我发现了什么

我找到了一些线索:

  1. 在 Github (here) 上,其他人也发现了这个问题。

  2. 示例says(在“photo-demo”中,在“PhotoViewerActivity.java”文件中)该库可能不可用,但如果不可用,它将被下载:

    if (!safeDetector.isOperational()) {
        // Note: The first time that an app using face API is installed on a device, GMS will
        // download a native library to the device in order to do detection.  Usually this
        // completes before the app is run for the first time.  But if that download has not yet
        // completed, then the above call will not detect any faces.
        //
        // isOperational() can be used to check if the required native library is currently
        // available.  The detector will automatically become operational once the library
        // download completes on device.
        Log.w(TAG, "Face detector dependencies are not yet available.");
    
        // Check for low storage.  If there is low storage, the native library will not be
        // downloaded, so detection will not become operational.
        IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
        boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
    
        if (hasLowStorage) {
            Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
            Log.w(TAG, getString(R.string.low_storage_error));
        }
    }
    

我尝试重置播放服务应用程序(这样可能会强制重新下载库),但它似乎不起作用(在 Nexus 5 上尝试过)。

问题

  1. 有没有办法强制下载库,然后开始使用 API?这个操作有监听器吗?

  2. 使用“isOperational”会触发此下载吗?

  3. 为什么它在某些 Nexus 设备上不可用?我是否在这里遗漏了一些关于使用这个库我应该知道的东西?

  4. 真的像我发现的那样对输入没有限制/限制吗?我注意到有人报告了内存问题 (here)。使用 try-catch (of OutOfMemoryError) 会帮助处理 OOM 吗?

【问题讨论】:

  • “它只在第二次运行”——意思是,第二次 isOperational() 调用返回 true?
  • @CommonsWare 更新了问题。从第二轮开始。第一次运行返回 false。第二次运行及以后,它返回 true。

标签: android google-play-services face-detection


【解决方案1】:

关于为什么它在某些设备上不起作用,Google answered it

新版本的 GMSCore (v9) 存在一个已知问题,即 今天刚刚发布。来自发行说明:

  • Mobile Vision 所需的一项服务现在因严重问题而被禁用 该服务中的错误。这将阻止尚未使用的用户 使用这些功能进行人脸或条形码检测。我们不 建议在您的应用中添加新的 Mobile Vision 功能,直到此 问题已解决。
  • 对于已经使用 Mobile Vision 功能的应用, 检查 FaceDetector.isOperational() 或 BarcodeDetector.isOperational() 在使用面部或条形码之前确认检测器准备就绪 检测器。

【讨论】:

【解决方案2】:

我也遇到了同样的问题。我做的解决方法是:

  • Google Play 服务的卸载更新
  • 从 apkmirror 网站安装了 8.7.xx 版本的 Google Play 服务
  • 清除数据和缓存并重新启动设备(不确定是否需要)
  • 当我启动我的应用时,它要求我更新 google play 服务
  • 我点击更新并砰的一声.....

它现在按预期工作。

PS:Google Play Services apk 有多种变体。请确保您选择正确。

【讨论】:

    猜你喜欢
    • 2021-12-22
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 2018-02-20
    • 2016-09-14
    • 1970-01-01
    • 2015-12-21
    相关资源
    最近更新 更多