为什么新的 Play-Services FaceDetector 在某些设备上不可用?
Why isn't the new Play-Services FaceDetector available on some devices?
背景
Google 几个月前发布了一个新的 API 来检测位图上的人脸:
- http://android-developers.blogspot.co.il/2015/08/face-detection-in-google-play-services.html
- https://developers.google.com/vision/introduction#apis
- https://developers.google.com/vision/face-detection-concepts#face_orientation
- https://search-codelabs.appspot.com/codelabs/face-detection#1
- https://github.com/googlesamples/android-vision
它应该比 built-in FaceDetector class 更快更好,而且它没有 restrictions/limitations 与之相比(比如输入位图需要配置 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) 上,它仅从示例的第二个 运行 开始工作。
我发现了什么
我发现了一些线索:
在Github(here),其他人也发现了这个问题。
示例 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 上试过)。
问题
有没有办法强制下载库,然后开始使用API?这个操作有监听器吗?
使用 "isOperational" 会触发此下载吗?
为什么它在某些 Nexus 设备上不可用?我是否遗漏了一些关于使用该库的知识?
是否真的如我所见,输入中没有 limitations/restrictions?我注意到有人报告了内存问题 (here)。使用 try-catch(OutOfMemoryError)有助于处理 OOM 吗?
关于为什么它在某些设备上不起作用,Google answered it:
There is a known issue with the new version of GMSCore (v9) that was
just released today. From the release notes:
- A service required by Mobile Vision is now disabled due to a serious
bug in that service. This will prevent users who have not already used
face or barcode detection from using those features. We do not
recommend adding new Mobile Vision features to your app until this
issue is fixed.
- For apps that already use Mobile Vision features,
check FaceDetector.isOperational() or BarcodeDetector.isOperational()
to confirm detector readiness before using the face or barcode
detector.
我也遇到了同样的问题。我所做的解决方法是:
- Google Play 服务的卸载更新
- 安装了 8.7.xx 版本的 Google 来自 apkmirror 网站的播放服务
- 清除数据和缓存并重启设备(不确定是否需要)
- 当我启动我的应用程序时,它要求我更新 google 播放服务
- 我点击了更新并砰的一声......
它现在按预期工作。
PS:Google Play Services apk 有多种变体。请确保您选择正确。
背景
Google 几个月前发布了一个新的 API 来检测位图上的人脸:
- http://android-developers.blogspot.co.il/2015/08/face-detection-in-google-play-services.html
- https://developers.google.com/vision/introduction#apis
- https://developers.google.com/vision/face-detection-concepts#face_orientation
- https://search-codelabs.appspot.com/codelabs/face-detection#1
- https://github.com/googlesamples/android-vision
它应该比 built-in FaceDetector class 更快更好,而且它没有 restrictions/limitations 与之相比(比如输入位图需要配置 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) 上,它仅从示例的第二个 运行 开始工作。
我发现了什么
我发现了一些线索:
在Github(here),其他人也发现了这个问题。
示例 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 上试过)。
问题
有没有办法强制下载库,然后开始使用API?这个操作有监听器吗?
使用 "isOperational" 会触发此下载吗?
为什么它在某些 Nexus 设备上不可用?我是否遗漏了一些关于使用该库的知识?
是否真的如我所见,输入中没有 limitations/restrictions?我注意到有人报告了内存问题 (here)。使用 try-catch(OutOfMemoryError)有助于处理 OOM 吗?
关于为什么它在某些设备上不起作用,Google answered it:
There is a known issue with the new version of GMSCore (v9) that was just released today. From the release notes:
- A service required by Mobile Vision is now disabled due to a serious bug in that service. This will prevent users who have not already used face or barcode detection from using those features. We do not recommend adding new Mobile Vision features to your app until this issue is fixed.
- For apps that already use Mobile Vision features, check FaceDetector.isOperational() or BarcodeDetector.isOperational() to confirm detector readiness before using the face or barcode detector.
我也遇到了同样的问题。我所做的解决方法是:
- Google Play 服务的卸载更新
- 安装了 8.7.xx 版本的 Google 来自 apkmirror 网站的播放服务
- 清除数据和缓存并重启设备(不确定是否需要)
- 当我启动我的应用程序时,它要求我更新 google 播放服务
- 我点击了更新并砰的一声......
它现在按预期工作。
PS:Google Play Services apk 有多种变体。请确保您选择正确。