Categories
discuss

Android face detection – Vision API or Camera API

I need a simple way of detecting faces in my Camera app. All I care about is a callback saying that a face was detected in certain place or with coordinates where it was detected on the preview. I’ve …

I need a simple way of detecting faces in my Camera app. All I care about is a callback saying that a face was detected in certain place or with coordinates where it was detected on the preview. I’ve noticed that there seem to be several face detection APIs – in Google Play services and in both legacy and camera2 APIs. Which one should I use for the simple requirement described above?

Answer

The legacy version is older, and has much lower accuracy than the new Google Play services API.

The camera2 API depends upon face detection capabilities built into the camera hardware, so it isn’t necessarily available on all devices. I have not done an exhaustive comparison, but I think that the accuracy is also lower than that of the new Google Play services API.

See this tutorial for using the Google Play services API for tracking faces in the camera preview:

https://developers.google.com/vision/face-tracker-tutorial

The callback that you’d define would be a subclass of Tracker, similar to the GraphicFaceTracker in the tutorial.

If you don’t need to track faces or you have other code that manages the camera, you can call the face detector directly like this:

Frame frame = Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Face> faces = faceDetector.detect(frame);

See for information here:

https://developers.google.com/android/reference/com/google/android/gms/vision/package-summary

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..