Background
Google released a few months ago a new API for detecting faces in bitmaps:
It should be faster and better than the built-in FaceDetector class , and it has no limitations / compared to it (for example, the need for the input bitmap to have a configuration of 565, the width of the bitmap, which even has maximum edges for detection).
The code is pretty simple:
manifest:
<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()){
return;
}
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Face> faces = faceDetector.detect(frame);
Problem
The API seems to be unavailable on some devices, returning "false" when calling "isOperational ()".
- In Nexus 4 (Android 4.4.4) and Nexus 5 (Android 6.0.1) it does not work at all
- On Nexus 5x (Android 6.0.1) and Galaxy S4 (Android 5.0) it works great
- In LG G2 (Android 4.2.2), it worked only from the second sample launch.
What i found
I found some tips:
On Github ( here ), other people also discovered this problem.
( "-", "PhotoViewerActivity.java" ) , , :
if (!safeDetector.isOperational()) {
Log.w(TAG, "Face detector dependencies are not yet available.");
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));
}
}
reset ( , , ), , , ( Nexus 5).